Open storybehind opened 4 months ago
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.
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.
When building dev branch by command cargo wasi build --release
, many errors occur like below. Any idea?
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.
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.
When compiling my project that uses this library as a dependency using command
cargo wasi build --release
, the below error occurs: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 returnCString::new(path.as_os_str().as_bytes()).unwrap_or_default()
. Can you alter this function to make it work in other target platforms?