I'm trying to compile this example code from rust to wasm. It's a rust crate that lets you create/write excel files. I've successfully managed to run it using cargo run.
Unfortunately, when I try to compile it to web assembly I'm experiencing an error which states that the library <stdlib.h>, a common C library, cannot be found while compiling bzip2-sys, a rust crate.
When I first tried to compile it, it prompted me to install clang which I did from here (pre-built binary for Windows (64-bit and 32-bit)) and I've included C:\Program Files\LLVM\bin to the system Path environment variable. I also have MinGW-w64 installed, as well as Visual Studio 2017 with Visual C++ build tools.
You can see the whole error generated in Visual Studio Code below.
PS C:\Users\User\Desktop\excel-test> wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling libc v0.2.71
Compiling pkg-config v0.3.17
Compiling cc v1.0.54
Compiling crc32fast v1.2.0
Compiling cfg-if v0.1.10
Compiling adler32 v1.0.4
Compiling podio v0.1.7
Compiling miniz_oxide v0.3.6
Compiling time v0.1.43
Compiling flate2 v1.0.14
Compiling bzip2-sys v0.1.9+1.0.8
error: failed to run custom build command for `bzip2-sys v0.1.9+1.0.8`
Caused by:
process didnt exit successfully: `C:\Users\User\Desktop\excel-test\target\release\build\bzip2-sys-aa88969feaab6a44\build-script-build` (exit code: 1)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\\Users\\User\\Desktop\\excel-test\\target\\wasm32-unknown-unknown\\release\\build\\bzip2-sys-03c492d40657ce9f\\out\\lib\\bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c"
cargo:warning=In file included from bzip2-1.0.8/blocksort.c:22:
cargo:warning=bzip2-1.0.8/bzlib_private.h:25:10: fatal error: 'stdlib.h' file not found
cargo:warning=#include <stdlib.h>
cargo:warning= ^~~~~~~~~~
cargo:warning=1 error generated.
exit code: 1
--- stderr
error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\\Users\\User\\Desktop\\excel-test\\target\\wasm32-unknown-unknown\\release\\build\\bzip2-sys-03c492d40657ce9f\\out\\lib\\bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args "clang" did not execute successfully (status code exit code: 1).
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
PS C:\Users\User\Desktop\excel-test>