gyscos / zstd-rs

A rust binding for the zstd compression library.
MIT License
501 stars 104 forks source link

Need web-assembly support . #48

Open naskarsubhajit opened 5 years ago

naskarsubhajit commented 5 years ago

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.

gyscos commented 5 years ago

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.

gyscos commented 3 years ago

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
gyscos commented 2 years ago

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.

yjhmelody commented 2 years ago

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?
jokemanfire commented 2 days ago

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?

hello, I don't know if you have been resolved , but it looks like you didn't install the clang ..