4

I'm trying to learn Rust and WebAssembly by building a demo app to manipulate some archive files.

After I added the "zip" crate, I was able to run cargo build successfully but not wasm-pack build (nor cargo build --target wasm32-unknown-unknown).

I am getting cargo:warning=#error Unsupported architecture when trying to build my file and clang seems somehow not happy with it.

At first I was getting some stdio.h not found, so I ran

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

to install them.

I am now having the following error:

   Compiling bzip2-sys v0.1.7
error: failed to run custom build command for `bzip2-sys v0.1.7`
process didn't exit successfully: `/Users/projects/rust/hello-wasm/target/release/build/bzip2-sys-b7b1e1aeb1e6f42f/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("s")
HOST = Some("x86_64-apple-darwin")
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" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.6" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/Users/projects/rust/hello-wasm/target/wasm32-unknown-unknown/release/build/bzip2-sys-3be942e6fa7d3879/out/lib/bzip2-1.0.6/blocksort.o" "-c" "bzip2-1.0.6/blocksort.c"
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:62:
cargo:warning=/usr/include/sys/cdefs.h:784:2: error: Unsupported architecture
cargo:warning=#error Unsupported architecture
cargo:warning= ^
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:64:
cargo:warning=In file included from /usr/include/_types.h:27:
cargo:warning=In file included from /usr/include/sys/_types.h:33:
cargo:warning=/usr/include/machine/_types.h:34:2: error: architecture not supported
cargo:warning=#error architecture not supported
cargo:warning= ^
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:64:
cargo:warning=In file included from /usr/include/_types.h:27:
cargo:warning=/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'; did you mean '__int128_t'?
cargo:warning=typedef __int64_t       __darwin_blkcnt_t;      /* total blocks */
cargo:warning=        ^
cargo:warning=note: '__int128_t' declared here
[...]
Internal error occurred: Command "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.6" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/Users/projects/rust/hello-wasm/target/wasm32-unknown-unknown/release/build/bzip2-sys-3be942e6fa7d3879/out/lib/bzip2-1.0.6/blocksort.o" "-c" "bzip2-1.0.6/blocksort.c" with args "clang" did not execute successfully (status code exit code: 1).

I then ran:

rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly

to install target wasm32-unknown-unknown but I am still getting the error.

What am I missing to compile the "zip" crate for wasm ?

Environment

macOS 10.14.4

gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
rustc --version                                             
rustc 1.36.0-nightly (31a75a172 2019-04-21)
rustup show                                                                
Default host: x86_64-apple-darwin

installed toolchains
--------------------

stable-x86_64-apple-darwin
nightly-2019-04-16-x86_64-apple-darwin
nightly-x86_64-apple-darwin (default)

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-apple-darwin

active toolchain
----------------

nightly-x86_64-apple-darwin (default)
rustc 1.36.0-nightly (31a75a172 2019-04-21)
2
  • #error Unsupported architecture is a C compiler error (you can see the .c files in the surrounding lines). You have chosen a crate that actually compiles a C library to do all of the heavy work of compressing, but that C library cannot be compiled to WASM (at least with your configuration). The easiest thing is to find a pure Rust implementation. Commented Apr 22, 2019 at 12:28
  • Thanks a lot. I ended up disabling bzip support from this crate, since the author left the possibility to do so through features flags using the following configuration in my Cargo.toml: zip = { version = "0.5.2", default-features = false, features = ["deflate"] } Commented Apr 22, 2019 at 13:56

1 Answer 1

1

choose one of

  • replace wasm32-unknown-unknown with wasm32-unknown-emscripten
  • remove #include <stdio.h>, printf and other standard-library calls from the C sources
  • implement the needed functions (printf?) for wasm32-unknown-unknown, or extract-and-copy emscripten's implementation
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.