Repository: Kimahriman/hdfs-native (language: python)

Issue:
Compiling on windows fails
The `users` crate seems to only work for unix. Now that lbgssapi isn't used we might as well make windows compilation work


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/python-release.yml b/.github/workflows/python-release.yml
index 9df5ffb..68e0f95 100644
--- a/.github/workflows/python-release.yml
+++ b/.github/workflows/python-release.yml
@@ -34,6 +34,7 @@ jobs:
           target: ${{ matrix.target }}
           args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
           sccache: 'true'
+          manylinux: auto
       - name: Upload wheels
         uses: actions/upload-artifact@v4
         with:
diff --git a/Cargo.lock b/Cargo.lock
index bdaa39e..da6f05c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -720,9 +720,9 @@ dependencies = [
  "thiserror",
  "tokio",
  "url",
- "users",
  "uuid",
  "which",
+ "whoami",
 ]
 
 [[package]]
@@ -1064,7 +1064,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
 dependencies = [
  "cfg-if",
  "libc",
- "redox_syscall",
+ "redox_syscall 0.5.1",
  "smallvec",
  "windows-targets 0.52.5",
 ]
@@ -1346,6 +1346,15 @@ dependencies = [
  "crossbeam-utils",
 ]
 
+[[package]]
+name = "redox_syscall"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
+dependencies = [
+ "bitflags 1.3.2",
+]
+
 [[package]]
 name = "redox_syscall"
 version = "0.5.1"
@@ -1698,15 +1707,6 @@ dependencies = [
  "percent-encoding",
 ]
 
-[[package]]
-name = "users"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
-dependencies = [
- "libc",
-]
-
 [[package]]
 name = "uuid"
 version = "1.8.0"
@@ -1738,6 +1738,12 @@ version = "0.11.0+wasi-snapshot-preview1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
 
+[[package]]
+name = "wasite"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
+
 [[package]]
 name = "wasm-bindgen"
 version = "0.2.92"
@@ -1814,6 +1820,17 @@ dependencies = [
  "rustix",
 ]
 
+[[package]]
+name = "whoami"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9"
+dependencies = [
+ "redox_syscall 0.4.1",
+ "wasite",
+ "web-sys",
+]
+
 [[package]]
 name = "winapi-util"
 version = "0.1.8"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index eb116c1..bc5093c 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -21,8 +21,6 @@ cipher = "0.4"
 crc = "3.2"
 ctr = "0.9"
 des = "0.8"
-# Just used for benchmarks
-fs-hdfs3 = { version = "0.1.12", optional = true }
 futures = "0.3"
 g2p = "1"
 hex = "0.4"
@@ -42,9 +40,13 @@ socket2 = "0.5"
 thiserror = { workspace = true }
 tokio = { workspace = true, features = ["rt", "rt-multi-thread", "net", "io-util", "macros", "sync", "time"] }
 url = "2"
-users = { version = "0.11", default-features = false }
 uuid = { version = "1", features = ["v4"] }
 which = { version = "4", optional = true }
+whoami = "1"
+
+[target.'cfg(unix)'.dependencies]
+# Just used for benchmarks
+fs-hdfs3 = { version = "0.1.12", optional = true }
 
 [build-dependencies]
 prost-build = { version = "0.12", optional = true }
diff --git a/rust/benches/io.rs b/rust/benches/io.rs
index 761ac55..e53b218 100644
--- a/rust/benches/io.rs
+++ b/rust/benches/io.rs
@@ -1,8 +1,8 @@
 use std::collections::HashSet;
 
+#[allow(unused_imports)]
 use bytes::{Buf, BufMut, BytesMut};
 use criterion::*;
-use hdfs::hdfs::get_hdfs;
 use hdfs_native::{
     minidfs::{DfsFeatures, MiniDfs},
     Client, WriteOptions,
@@ -49,8 +49,9 @@ fn bench(c: &mut Criterion) {
         })
     });
     group.sample_size(50);
+    #[cfg(unix)]
     group.bench_function("read-libhdfs", |b| {
-        let fs = get_hdfs().unwrap();
+        let fs = hdfs::hdfs::get_hdfs().unwrap();
         b.iter(|| {
             let mut buf = BytesMut::zeroed(ints_to_write * 4);
             let mut bytes_read = 0;
@@ -79,8 +80,9 @@ fn bench(c: &mut Criterion) {
             .iter(|| async { reader.read_range(0, reader.file_length()).await.unwrap() })
     });
     group.sample_size(50);
+    #[cfg(unix)]
     group.bench_function("read-libhdfs", |b| {
-        let fs = get_hdfs().unwrap();
+        let fs = hdfs::hdfs::get_hdfs().unwrap();
         b.iter(|| {
             let mut buf = BytesMut::zeroed(ints_to_write * 4);
             let mut bytes_read = 0;
@@ -120,8 +122,9 @@ fn bench(c: &mut Criterion) {
         })
     });
     group.sample_size(10);
+    #[cfg(unix)]
     group.bench_function("write-libhdfs", |b| {
-        let fs = get_hdfs().unwrap();
+        let fs = hdfs::hdfs::get_hdfs().unwrap();
         b.iter(|| {
             let mut buf = buf.clone();
             let writer = fs.create_with_overwrite("/bench-write", true).unwrap();
@@ -154,8 +157,9 @@ fn bench(c: &mut Criterion) {
         })
     });
     group.sample_size(10);
+    #[cfg(unix)]
     group.bench_function("write-libhdfs", |b| {
-        let fs = get_hdfs().unwrap();
+        let fs = hdfs::hdfs::get_hdfs().unwrap();
         b.iter(|| {
             let mut buf = buf.clone();
             let writer = fs
diff --git a/rust/benches/rpc.rs b/rust/benches/rpc.rs
index 0b7cd29..8dabc85 100644
--- a/rust/benches/rpc.rs
+++ b/rust/benches/rpc.rs
@@ -1,7 +1,6 @@
 use std::collections::HashSet;
 
 use criterion::*;
-use hdfs::hdfs::get_hdfs;
 use hdfs_native::{minidfs::MiniDfs, Client, WriteOptions};
 
 fn bench(c: &mut Criterion) {
@@ -25,14 +24,14 @@ fn bench(c: &mut Criterion) {
             .unwrap();
     });
 
-    let fs = get_hdfs().unwrap();
-
     let mut group = c.benchmark_group("rpc");
     group.bench_function("getFileInfo-native", |b| {
         b.to_async(&rt)
             .iter(|| async { client.get_file_info("/bench").await.unwrap() })
     });
+    #[cfg(unix)]
     group.bench_function("getFileInfo-libhdfs", |b| {
+        let fs = hdfs::hdfs::get_hdfs().unwrap();
         b.iter(|| fs.get_file_status("/bench").unwrap())
     });
 }
diff --git a/rust/src/security/user.rs b/rust/src/security/user.rs
index ea1e08d..901405c 100644
--- a/rust/src/security/user.rs
+++ b/rust/src/security/user.rs
@@ -6,7 +6,7 @@ use std::fs;
 use std::io;
 use std::path::PathBuf;
 
-use users::get_current_username;
+use whoami::username;
 
 use crate::proto::common::CredentialsProto;
 use crate::proto::common::TokenProto;
@@ -333,13 +333,7 @@ impl User {
     }
 
     pub(crate) fn get_simpler_user() -> UserInfo {
-        let effective_user = env::var(HADOOP_USER_NAME).ok().unwrap_or_else(|| {
-            get_current_username()
-                .unwrap()
-                .to_str()
-                .unwrap()
-                .to_string()
-        });
+        let effective_user = env::var(HADOOP_USER_NAME).ok().unwrap_or_else(username);
         UserInfo {
             real_user: None,
             effective_user: Some(effective_user),


Test patch:
diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml
index 9241232..d83500d 100644
--- a/.github/workflows/python-test.yml
+++ b/.github/workflows/python-test.yml
@@ -73,6 +73,7 @@ jobs:
         with:
           args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
           sccache: 'true'
+          manylinux: auto
 
       - name: Upload wheels
         if: github.ref == 'refs/heads/master'
diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml
index 84bb957..626568f 100644
--- a/.github/workflows/rust-test.yml
+++ b/.github/workflows/rust-test.yml
@@ -27,8 +27,8 @@ jobs:
       matrix:
         os:
           - ubuntu-latest
-          # - macos-11
-          # - windows-latest
+          - macos-latest
+          - windows-latest
     runs-on: ${{ matrix.os }}
 
     steps:
@@ -58,7 +58,7 @@ jobs:
       matrix:
         os:
           - ubuntu-latest
-          # - macos-11
+          # - macos-latest
           # - windows-latest
     runs-on: ${{ matrix.os }}
     env: