Skip to content

Support compile gix-config-value to wasm32-wasi #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 24, 2024

Conversation

ChanTsune
Copy link
Contributor

Hi! I tried to compile gix-value-config to wasm32-wasi but encountered an error during compilation with this error:

   Compiling gix-config-value v0.14.8 (/gitoxide/gix-config-value)
error[E0433]: failed to resolve: could not find `unix` in `os`
  --> gix-config-value/src/path.rs:66:30
   |
66 |                 use std::os::unix::ffi::OsStrExt;
   |                              ^^^^ could not find `unix` in `os`
   |
note: found an item that was configured out
  --> /.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/os/mod.rs:26:9
   |
26 | pub mod unix {}
   |         ^^^^
note: found an item that was configured out
  --> /.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/os/mod.rs:64:9
   |
64 | pub mod unix;
   |         ^^^^

error[E0425]: cannot find function `getpwnam` in crate `libc`
  --> gix-config-value/src/path.rs:62:38
   |
62 |             let pwd = unsafe { libc::getpwnam(cname.as_ptr()) };
   |                                      ^^^^^^^^ not found in `libc`

error[E0599]: no function or associated item named `from_bytes` found for struct `OsStr` in the current scope
  --> gix-config-value/src/path.rs:71:39
   |
71 |                 Some(std::ffi::OsStr::from_bytes(cstr.to_bytes()).into())
   |                                       ^^^^^^^^^^ function or associated item not found in `OsStr`
   |
   = help: items from traits can only be used if the trait is in scope
help: there is a method `as_bytes` with a similar name, but with different arguments
  --> /.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/os/wasi/../unix/ffi/os_str.rs:57:5
   |
57 |     fn as_bytes(&self) -> &[u8];
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: trait `OsStrExt` which provides `from_bytes` is implemented but not in scope; perhaps you want to import it
   |
10 +     use std::os::wasi::ffi::OsStrExt;
   |

Some errors have detailed explanations: E0425, E0433, E0599.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `gix-config-value` (lib) due to 3 previous errors

So I added a cfg directive all(target_family = "wasm", not(target_os = "emscripten”)), because currently libc does not provide getpwnam for wasm32-wasi.

Now that gix-value-config can be compiled to wasm32-wasi, some crates that depend on gix-value-config can also be compiled to wasm32-wasi.

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your help with this!
I am also happy about the additions to the CI configuration so it can keep working on WASM.

@Byron Byron merged commit 7df1d03 into GitoxideLabs:main Aug 24, 2024
18 checks passed
@ChanTsune ChanTsune deleted the gix-config-value-for-wasi branch August 24, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants