zstd-rs
zstd-rs copied to clipboard
Need web-assembly support .
Hi, It will be great help if you can guide to create a webassembly out of this library so as we can use it from browser.
Hi!
Supporting wasm targets would be great indeed!
Right now it seems libc
is the problem: we use libc
types rather than std::os::raw
so that zstd-sys can work with #[no_std]
, but libc doesn't seem to work well with wasm just yet...
I suppose one option might be to use feature flags to switch between libc and std, letting users choose between wasm and embedded.
Edit: the current master branch should now compile for the wasm32-unknown-unknown target. Haven't tested it yet.
Hi again! Like mentioned in https://github.com/gyscos/zstd-rs/issues/93, the current way to build C libraries for ASM is to use the emscripten backend:
# Make sure you have emscripten installed (such that `emcc` and `emar` are in the $PATH)
rustup target add wasm32-unknown-emscripten
cargo build --target wasm32-unknown-emscripten
Since then, https://github.com/gyscos/zstd-rs/pull/139 has brought support for wasm32-unknown-unknown. Right now dictionary-building and legacy support are not supported, so you'd need to disable the default features, but it should otherwise compile fine.
Hi @gyscos Still have such problems when I read the doc https://github.com/gyscos/zstd-rs/wiki/Compile-for-WASM :
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = Some("/usr/local/opt/llvm/bin/clang")
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
running: "/usr/local/opt/llvm/bin/clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "wasm-shim/" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-fvisibility=hidden" "-DXXH_STATIC_ASSERT=0" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-o" "/Users/yjhmelody/code/github/zstd-rs/zstd-safe/zstd-sys/target/wasm32-unknown-unknown/debug/build/zstd-sys-ff6d63836dba9265/out/zstd/lib/compress/zstd_fast.o" "-c" "zstd/lib/compress/zstd_fast.c"
--- stderr
error occurred: Failed to find tool. Is `clang` installed?