Skip to content
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

unable to compile to wasm32-wasi target #22

Open
storybehind opened this issue Apr 22, 2024 · 5 comments
Open

unable to compile to wasm32-wasi target #22

storybehind opened this issue Apr 22, 2024 · 5 comments

Comments

@storybehind
Copy link

When compiling my project that uses this library as a dependency using command cargo wasi build --release, the below error occurs:

libheif-rs-wasi-compile-err

When looking at the source code in src/utils.rs, it can compile only to unix and windows target platform. I'm new to rust and my question is why can't the function just return CString::new(path.as_os_str().as_bytes()).unwrap_or_default(). Can you alter this function to make it work in other target platforms?

@Cykooz
Copy link
Owner

Cykooz commented Apr 22, 2024

why can't the function just return CString::new(path.as_os_str().as_bytes()).unwrap_or_default()

Because the structure OsStr returned by method as_os_str() does not implement method as_bytes(). This method is described in the trait OsStrExt. Declaration and implementation of this trait depends on the particular OS.

@Cykooz
Copy link
Owner

Cykooz commented Apr 22, 2024

I have added this code into path_to_cstring function:

    #[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
    {
        use std::os::wasi::ffi::OsStrExt;
        CString::new(path.as_os_str().as_bytes()).unwrap_or_default()
    }

You can try to compile libheif-rs from the dev branch of this git-repo.

@storybehind
Copy link
Author

When building dev branch by command cargo wasi build --release, many errors occur like below. Any idea?

libheif-rs-dev-wasi-build-err

@Cykooz
Copy link
Owner

Cykooz commented Apr 23, 2024

I don't know. Could you look at bindings.rs file somewhere inside target/wasm32-wasi/release/build/libheif-sys-*/out/ directory?
This file generates by bindgen crate from headers-file of original libheif library. May be it contains these function with another name.

@Cykooz
Copy link
Owner

Cykooz commented Apr 23, 2024

Have you already found a solution how to build the original libheif library (https://github.com/strukturag/libheif) for wasm32-wasi and statically link them to the rust project?
I think this is the most painful task in your case.

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

No branches or pull requests

2 participants