Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build Rust dependency with C dependency #621

Closed
tmfink opened this issue Apr 9, 2019 · 9 comments
Closed

Unable to build Rust dependency with C dependency #621

tmfink opened this issue Apr 9, 2019 · 9 comments

Comments

@tmfink
Copy link

tmfink commented Apr 9, 2019

I'm not sure if wasm-pack is the correct project to open an issue. My goal is to create a web-interface for https://github.com/capstone-rust/capstone-rs (Rust bindings around a C library) that runs completely client-side in webassembly. However, I had issues with a proof-of-concept that tried to link transitively to a C library.

🐛 Bug description

wasm-pack fails to build Rust code that has C dependency for target wasm32-unknown-unknown.

Project available here: https://github.com/tmfink/simple-wasm/tree/master

🤔 Expected Behavior

wasm-pack build should succeed.

  1. C dependency built with emcc
  2. Rust *-sys library built library with wasm binary.
  3. Rust -rs code links *-sys library.

👟 Steps to reproduce

  1. Create wasm-pack project based on tutorial at https://rustwasm.github.io/docs/book/game-of-life/hello-world.html
    • See link above
  2. Add additional Rust dependency with C language dependency
  3. Try to build with wasm-pack build.

~/.cargo/config:

$ cat ~/.cargo/config
[target.wasm32-unknown-unknown]
linker = "emcc"

Do no set CC:

$ wasm-pack build --dev -- -v
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
       Fresh unicode-xid v0.1.0
       Fresh bumpalo v2.3.0
       Fresh lazy_static v1.3.0
       Fresh cc v1.0.35
   Compiling cfg-if v0.1.7
       Fresh log v0.4.6
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=161e81c1e1ea1ab6 -C extra-filename=-161e81c1e1ea1ab6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling wasm-bindgen v0.2.40
       Fresh proc-macro2 v0.4.27
       Fresh wasm-bindgen-shared v0.2.40
   Compiling double-sys v0.1.0 (/home/user/simple-wasm/double-sys)
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6/build-script-build`
       Fresh quote v0.6.11
       Fresh syn v0.15.30
       Fresh wasm-bindgen-backend v0.2.40
       Fresh wasm-bindgen-macro-support v0.2.40
       Fresh wasm-bindgen-macro v0.2.40
     Running `rustc --crate-name wasm_bindgen /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=805eef06f23662b6 -C extra-filename=-805eef06f23662b6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern wasm_bindgen_macro=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro-e8b6c52194013b1f.so --cap-lints allow`
error: failed to run custom build command for `double-sys v0.1.0 (/home/user/simple-wasm/double-sys)`
process didn't exit successfully: `/home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-unknown-linux-gnu")
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("true")
running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out/double/double.o" "-c" "double/double.c"
cargo:warning=error: unable to create target: 'No available targets are compatible with this triple.'
cargo:warning=1 error generated.
exit code: 1

--- stderr
thread 'main' panicked at '

Internal error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out/double/double.o" "-c" "double/double.c" with args "clang" did not execute successfully (status code exit code: 1).

', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.35/src/lib.rs:2398:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101

Set CC=emcc

$ CC=emcc wasm-pack build --dev -- -v
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
       Fresh unicode-xid v0.1.0
       Fresh lazy_static v1.3.0
       Fresh bumpalo v2.3.0
       Fresh cc v1.0.35
   Compiling cfg-if v0.1.7
       Fresh log v0.4.6
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=161e81c1e1ea1ab6 -C extra-filename=-161e81c1e1ea1ab6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling wasm-bindgen v0.2.40
       Fresh proc-macro2 v0.4.27
       Fresh wasm-bindgen-shared v0.2.40
   Compiling double-sys v0.1.0 (/home/user/simple-wasm/double-sys)
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6/build-script-build`
       Fresh quote v0.6.11
       Fresh syn v0.15.30
       Fresh wasm-bindgen-backend v0.2.40
       Fresh wasm-bindgen-macro-support v0.2.40
       Fresh wasm-bindgen-macro v0.2.40
     Running `rustc --crate-name wasm_bindgen /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=805eef06f23662b6 -C extra-filename=-805eef06f23662b6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern wasm_bindgen_macro=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro-e8b6c52194013b1f.so --cap-lints allow`
     Running `rustc --edition=2018 --crate-name double_sys double-sys/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=127908e4a28ab64e -C extra-filename=-127908e4a28ab64e --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out -l static=double`
   Compiling double v0.1.0 (/home/user/simple-wasm/double-rs)
     Running `rustc --edition=2018 --crate-name double double-rs/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f7bdb95ab507d2d9 -C extra-filename=-f7bdb95ab507d2d9 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern double_sys=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble_sys-127908e4a28ab64e.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
   Compiling console_error_panic_hook v0.1.6
     Running `rustc --crate-name console_error_panic_hook /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/console_error_panic_hook-0.1.6/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=2891ebcc06a522d7 -C extra-filename=-2891ebcc06a522d7 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern cfg_if=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libcfg_if-161e81c1e1ea1ab6.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib --cap-lints allow`
   Compiling simple-wasm v0.1.0 (/home/user/simple-wasm)
     Running `rustc --edition=2018 --crate-name simple_wasm src/lib.rs --color always --crate-type cdylib --crate-type rlib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=4bb0d303c287c5df --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern console_error_panic_hook=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-2891ebcc06a522d7.rlib --extern double=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble-f7bdb95ab507d2d9.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
warning: unused import: `wasm_bindgen::prelude::*`
 --> src/lib.rs:6:5
  |
6 | use wasm_bindgen::prelude::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: function is never used: `set_panic_hook`
 --> src/utils.rs:1:1
  |
1 | pub fn set_panic_hook() {
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

thread 'rustc' panicked at 'src/librustc_codegen_ssa/back/linker.rs:815: building dynamic library is unsupported on Emscripten', src/librustc/util/bug.rs:37:26
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.33.0 (2aa4c46cf 2019-02-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C linker=emcc -C incremental --crate-type cdylib --crate-type rlib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `simple-wasm`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name simple_wasm src/lib.rs --color always --crate-type cdylib --crate-type rlib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=4bb0d303c287c5df --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C linker=emcc -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern console_error_panic_hook=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-2891ebcc06a522d7.rlib --extern double=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble-f7bdb95ab507d2d9.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out` (exit code: 101)
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: wasm-pack 0.8.1
rustc version: 1.33.0 (2aa4c46cf 2019-02-28)
emcc version: 1.38.12 (commit 0d8576c0e8f5ee09a36120b9d44184b5da2f2e7a)

@ashleygwilliams
Copy link
Member

i think this is the right place! i'll need to try to reproduce this- what C dependency were you using? or if you can just push up an example repo, that'd be helpful. thanks for filing!

@tmfink
Copy link
Author

tmfink commented Apr 9, 2019

@ashleygwilliams glad to hear! The example repo for this simplified example is here:

https://github.com/tmfink/simple-wasm/tree/master

The README gives an overview of where/what the dependencies are.

@alexcrichton
Copy link
Contributor

I commented on rust-lang/cc-rs#392 as well, but I think the issue here is that emcc is simply incompatible with wasm32-unknown-unknown, the compiler does not have support to link with it and the toolchain is different enough that I don't think it'd work at this time. Perhaps in the future though the two will work together!

@tmfink
Copy link
Author

tmfink commented Apr 11, 2019

@alexcrichton thanks for the info! I'm not as familiar with this web programming.
I suppose we would use clang to compile C for wasm32-unknown-unknown?

@tmfink
Copy link
Author

tmfink commented Apr 11, 2019

After clearing the wasm32-unknown-unknown, from ~/.cargo/config, I get the same error as above:

cargo:warning=error: unable to create target: 'No available targets are compatible with this triple.'

I'm running Ubuntu 18.04, which comes with clang 6.0.0.

However, after installing clang-8 from https://apt.llvm.org/, I am able to build:

$ CC=clang-8 wasm-pack build --dev -- -v
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling proc-macro2 v0.4.27
   Compiling unicode-xid v0.1.0
   Compiling syn v0.15.30
   Compiling wasm-bindgen-shared v0.2.40
   Compiling cfg-if v0.1.7
   Compiling bumpalo v2.3.0
   Compiling lazy_static v1.3.0
   Compiling cc v1.0.35
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.27/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=e6babb0cd74a978e -C extra-filename=-e6babb0cd74a978e --out-dir /home/user/simple-wasm/target/debug/build/proc-macro2-e6babb0cd74a978e -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name unicode_xid /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-xid-0.1.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' -C metadata=61996a4420d40ddf -C extra-filename=-61996a4420d40ddf --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-0.15.30/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' --cfg 'feature="quote"' --cfg 'feature="visit"' -C metadata=2c36a70878d630bb -C extra-filename=-2c36a70878d630bb --out-dir /home/user/simple-wasm/target/debug/build/syn-2c36a70878d630bb -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-shared-0.2.40/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=d9b3c3462518ac53 -C extra-filename=-d9b3c3462518ac53 --out-dir /home/user/simple-wasm/target/debug/build/wasm-bindgen-shared-d9b3c3462518ac53 -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=1e34a1283119a981 -C extra-filename=-1e34a1283119a981 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --edition=2018 --crate-name bumpalo /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bumpalo-2.3.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="collections"' --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=fc4bbb5b440fe8c4 -C extra-filename=-fc4bbb5b440fe8c4 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name lazy_static /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.3.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=afc97fc38871e70e -C extra-filename=-afc97fc38871e70e --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cc /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.35/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=5804909ed03c2692 -C extra-filename=-5804909ed03c2692 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling wasm-bindgen v0.2.40
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=4623a14ba246abb4 -C extra-filename=-4623a14ba246abb4 --out-dir /home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4 -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=161e81c1e1ea1ab6 -C extra-filename=-161e81c1e1ea1ab6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling log v0.4.6
     Running `rustc --crate-name log /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=178363436eabfb4e -C extra-filename=-178363436eabfb4e --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern cfg_if=/home/user/simple-wasm/target/debug/deps/libcfg_if-1e34a1283119a981.rlib --cap-lints allow`
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/syn-2c36a70878d630bb/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/proc-macro2-e6babb0cd74a978e/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-shared-d9b3c3462518ac53/build-script-build`
     Running `rustc --crate-name wasm_bindgen_shared /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-shared-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d8152148aebf6d5d -C extra-filename=-d8152148aebf6d5d --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name proc_macro2 /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.27/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=d3456f7f985b30f5 -C extra-filename=-d3456f7f985b30f5 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern unicode_xid=/home/user/simple-wasm/target/debug/deps/libunicode_xid-61996a4420d40ddf.rlib --cap-lints allow --cfg u128 --cfg use_proc_macro --cfg wrap_proc_macro`
   Compiling double-sys v0.1.0 (/home/user/simple-wasm/double-sys)
     Running `rustc --edition=2018 --crate-name build_script_build double-sys/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=4ec575918a7679c6 -C extra-filename=-4ec575918a7679c6 --out-dir /home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6 -C incremental=/home/user/simple-wasm/target/debug/incremental -L dependency=/home/user/simple-wasm/target/debug/deps --extern cc=/home/user/simple-wasm/target/debug/deps/libcc-5804909ed03c2692.rlib`
   Compiling quote v0.6.11
     Running `rustc --crate-name quote /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.11/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' -C metadata=23dd3ea856cdd569 -C extra-filename=-23dd3ea856cdd569 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --cap-lints allow`
     Running `/home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6/build-script-build`
     Running `rustc --edition=2018 --crate-name double_sys double-sys/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=127908e4a28ab64e -C extra-filename=-127908e4a28ab64e --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out -l static=double`
     Running `rustc --crate-name syn /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-0.15.30/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' --cfg 'feature="quote"' --cfg 'feature="visit"' -C metadata=12c8c9fe7f83c356 -C extra-filename=-12c8c9fe7f83c356 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern unicode_xid=/home/user/simple-wasm/target/debug/deps/libunicode_xid-61996a4420d40ddf.rlib --cap-lints allow --cfg syn_can_use_thread_id --cfg syn_can_call_macro_by_path --cfg syn_disable_nightly_tests`
   Compiling double v0.1.0 (/home/user/simple-wasm/double-rs)
     Running `rustc --edition=2018 --crate-name double double-rs/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f7bdb95ab507d2d9 -C extra-filename=-f7bdb95ab507d2d9 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern double_sys=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble_sys-127908e4a28ab64e.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
   Compiling wasm-bindgen-backend v0.2.40
     Running `rustc --crate-name wasm_bindgen_backend /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-backend-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="spans"' -C metadata=aa5460080790b84c -C extra-filename=-aa5460080790b84c --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern bumpalo=/home/user/simple-wasm/target/debug/deps/libbumpalo-fc4bbb5b440fe8c4.rlib --extern lazy_static=/home/user/simple-wasm/target/debug/deps/liblazy_static-afc97fc38871e70e.rlib --extern log=/home/user/simple-wasm/target/debug/deps/liblog-178363436eabfb4e.rlib --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern syn=/home/user/simple-wasm/target/debug/deps/libsyn-12c8c9fe7f83c356.rlib --extern wasm_bindgen_shared=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_shared-d8152148aebf6d5d.rlib --cap-lints allow`
   Compiling wasm-bindgen-macro-support v0.2.40
     Running `rustc --edition=2018 --crate-name wasm_bindgen_macro_support /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-support-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="spans"' --cfg 'feature="wasm-bindgen-backend"' -C metadata=ab96c1aa98ff2337 -C extra-filename=-ab96c1aa98ff2337 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern syn=/home/user/simple-wasm/target/debug/deps/libsyn-12c8c9fe7f83c356.rlib --extern wasm_bindgen_backend=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_backend-aa5460080790b84c.rlib --extern wasm_bindgen_shared=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_shared-d8152148aebf6d5d.rlib --cap-lints allow`
   Compiling wasm-bindgen-macro v0.2.40
     Running `rustc --crate-name wasm_bindgen_macro /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.40/src/lib.rs --color always --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --cfg 'feature="spans"' --cfg 'feature="wasm-bindgen-macro-support"' -C metadata=e8b6c52194013b1f -C extra-filename=-e8b6c52194013b1f --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern wasm_bindgen_macro_support=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro_support-ab96c1aa98ff2337.rlib --cap-lints allow`
     Running `rustc --crate-name wasm_bindgen /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=805eef06f23662b6 -C extra-filename=-805eef06f23662b6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern wasm_bindgen_macro=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro-e8b6c52194013b1f.so --cap-lints allow`
   Compiling console_error_panic_hook v0.1.6
     Running `rustc --crate-name console_error_panic_hook /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/console_error_panic_hook-0.1.6/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=2891ebcc06a522d7 -C extra-filename=-2891ebcc06a522d7 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern cfg_if=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libcfg_if-161e81c1e1ea1ab6.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib --cap-lints allow`
   Compiling simple-wasm v0.1.0 (/home/user/simple-wasm)
     Running `rustc --edition=2018 --crate-name simple_wasm src/lib.rs --color always --crate-type cdylib --crate-type rlib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=4bb0d303c287c5df --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern console_error_panic_hook=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-2891ebcc06a522d7.rlib --extern double=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble-f7bdb95ab507d2d9.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
warning: unused import: `wasm_bindgen::prelude::*`
 --> src/lib.rs:6:5
  |
6 | use wasm_bindgen::prelude::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: function is never used: `set_panic_hook`
 --> src/utils.rs:1:1
  |
1 | pub fn set_panic_hook() {
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 17.58s
:-) [WARN]: origin crate has no README
[INFO]: Installing wasm-bindgen...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 17.69s
[INFO]: :-) Your wasm pkg is ready to publish at ./pkg.
user@backfist:~/workspace/wasm-tutorial/simple-wasm/simple-wasm-original(master ✗)$ CC=clang-8 wasm-pack build --dev -- -v^C
user@backfist:~/workspace/wasm-tutorial/simple-wasm/simple-wasm-original(master ✗)$ CC=clang-8 wasm-pack build --dev -- -v
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
       Fresh unicode-xid v0.1.0
       Fresh lazy_static v1.3.0
       Fresh bumpalo v2.3.0
       Fresh cc v1.0.35
       Fresh cfg-if v0.1.7
       Fresh log v0.4.6
       Fresh proc-macro2 v0.4.27
       Fresh wasm-bindgen-shared v0.2.40
       Fresh quote v0.6.11
       Fresh double-sys v0.1.0 (/home/user/simple-wasm/double-sys)
       Fresh syn v0.15.30
       Fresh double v0.1.0 (/home/user/simple-wasm/double-rs)
       Fresh wasm-bindgen-backend v0.2.40
       Fresh wasm-bindgen-macro-support v0.2.40
       Fresh wasm-bindgen-macro v0.2.40
       Fresh wasm-bindgen v0.2.40
       Fresh console_error_panic_hook v0.1.6
       Fresh simple-wasm v0.1.0 (/home/user/simple-wasm)
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
:-) [WARN]: origin crate has no README
[INFO]: Installing wasm-bindgen...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 0.12s
[INFO]: :-) Your wasm pkg is ready to publish at ./pkg.

However, I don't know how to test my change since, when I run npm run start in www/, get the popup Hello, hello-wasm-pack! from the hello-wasm-pack tutorial.
It looks like I'm not importing the wasm code that was built in pkg/.

@tmfink
Copy link
Author

tmfink commented Apr 11, 2019

I replaced "hello-wasm-pack" with "simple-wasm" as described in the "Using your library" tutorial page:
tmfink/simple-wasm@a68d738

However, when building with:

#!/bin/sh

set -eux

cd "$(dirname "$0")"

CC=clang-8 wasm-pack build --dev -- -v
( cd pkg && npm link )
(
    cd www
    npm link simple-wasm
    npm install
    npm run start
)

I get an error during npm run start:

ERROR in ../pkg/simple_wasm_bg.wasm
Module not found: Error: Can't resolve 'env' in '/home/user/simple-wasm/pkg'
 @ ../pkg/simple_wasm_bg.wasm
 @ ../pkg/simple_wasm.js
 @ ./index.js
 @ ./bootstrap.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./bootstrap.js
ℹ 「wdm」: Failed to compile.

Full log:

+ dirname ./build.sh
+ cd .
+ CC=clang-8 wasm-pack build --dev -- -v
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling proc-macro2 v0.4.27
   Compiling unicode-xid v0.1.0
   Compiling wasm-bindgen-shared v0.2.40
   Compiling syn v0.15.30
   Compiling cfg-if v0.1.7
   Compiling bumpalo v2.3.0
   Compiling lazy_static v1.3.0
   Compiling cc v1.0.35
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.27/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=e6babb0cd74a978e -C extra-filename=-e6babb0cd74a978e --out-dir /home/user/simple-wasm/target/debug/build/proc-macro2-e6babb0cd74a978e -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name unicode_xid /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-xid-0.1.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' -C metadata=61996a4420d40ddf -C extra-filename=-61996a4420d40ddf --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-shared-0.2.40/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=d9b3c3462518ac53 -C extra-filename=-d9b3c3462518ac53 --out-dir /home/user/simple-wasm/target/debug/build/wasm-bindgen-shared-d9b3c3462518ac53 -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-0.15.30/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' --cfg 'feature="quote"' --cfg 'feature="visit"' -C metadata=2c36a70878d630bb -C extra-filename=-2c36a70878d630bb --out-dir /home/user/simple-wasm/target/debug/build/syn-2c36a70878d630bb -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=1e34a1283119a981 -C extra-filename=-1e34a1283119a981 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --edition=2018 --crate-name bumpalo /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bumpalo-2.3.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="collections"' --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=fc4bbb5b440fe8c4 -C extra-filename=-fc4bbb5b440fe8c4 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name lazy_static /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.3.0/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=afc97fc38871e70e -C extra-filename=-afc97fc38871e70e --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cc /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.35/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=5804909ed03c2692 -C extra-filename=-5804909ed03c2692 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling wasm-bindgen v0.2.40
     Running `rustc --crate-name build_script_build /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=4623a14ba246abb4 -C extra-filename=-4623a14ba246abb4 --out-dir /home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4 -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cfg_if /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.7/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=161e81c1e1ea1ab6 -C extra-filename=-161e81c1e1ea1ab6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
   Compiling log v0.4.6
     Running `rustc --crate-name log /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=178363436eabfb4e -C extra-filename=-178363436eabfb4e --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern cfg_if=/home/user/simple-wasm/target/debug/deps/libcfg_if-1e34a1283119a981.rlib --cap-lints allow`
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-4623a14ba246abb4/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/wasm-bindgen-shared-d9b3c3462518ac53/build-script-build`
     Running `rustc --crate-name wasm_bindgen_shared /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-shared-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d8152148aebf6d5d -C extra-filename=-d8152148aebf6d5d --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --cap-lints allow`
     Running `/home/user/simple-wasm/target/debug/build/syn-2c36a70878d630bb/build-script-build`
     Running `/home/user/simple-wasm/target/debug/build/proc-macro2-e6babb0cd74a978e/build-script-build`
     Running `rustc --crate-name proc_macro2 /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.27/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=d3456f7f985b30f5 -C extra-filename=-d3456f7f985b30f5 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern unicode_xid=/home/user/simple-wasm/target/debug/deps/libunicode_xid-61996a4420d40ddf.rlib --cap-lints allow --cfg u128 --cfg use_proc_macro --cfg wrap_proc_macro`
   Compiling double-sys v0.1.0 (/home/user/simple-wasm/double-sys)
     Running `rustc --edition=2018 --crate-name build_script_build double-sys/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=4ec575918a7679c6 -C extra-filename=-4ec575918a7679c6 --out-dir /home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6 -C incremental=/home/user/simple-wasm/target/debug/incremental -L dependency=/home/user/simple-wasm/target/debug/deps --extern cc=/home/user/simple-wasm/target/debug/deps/libcc-5804909ed03c2692.rlib`
   Compiling quote v0.6.11
     Running `rustc --crate-name quote /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-0.6.11/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' -C metadata=23dd3ea856cdd569 -C extra-filename=-23dd3ea856cdd569 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --cap-lints allow`
     Running `/home/user/simple-wasm/target/debug/build/double-sys-4ec575918a7679c6/build-script-build`
     Running `rustc --edition=2018 --crate-name double_sys double-sys/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=127908e4a28ab64e -C extra-filename=-127908e4a28ab64e --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out -l static=double`
   Compiling double v0.1.0 (/home/user/simple-wasm/double-rs)
     Running `rustc --edition=2018 --crate-name double double-rs/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f7bdb95ab507d2d9 -C extra-filename=-f7bdb95ab507d2d9 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern double_sys=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble_sys-127908e4a28ab64e.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
     Running `rustc --crate-name syn /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-0.15.30/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="proc-macro2"' --cfg 'feature="quote"' --cfg 'feature="visit"' -C metadata=12c8c9fe7f83c356 -C extra-filename=-12c8c9fe7f83c356 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern unicode_xid=/home/user/simple-wasm/target/debug/deps/libunicode_xid-61996a4420d40ddf.rlib --cap-lints allow --cfg syn_can_use_thread_id --cfg syn_can_call_macro_by_path --cfg syn_disable_nightly_tests`
   Compiling wasm-bindgen-backend v0.2.40
     Running `rustc --crate-name wasm_bindgen_backend /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-backend-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="spans"' -C metadata=aa5460080790b84c -C extra-filename=-aa5460080790b84c --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern bumpalo=/home/user/simple-wasm/target/debug/deps/libbumpalo-fc4bbb5b440fe8c4.rlib --extern lazy_static=/home/user/simple-wasm/target/debug/deps/liblazy_static-afc97fc38871e70e.rlib --extern log=/home/user/simple-wasm/target/debug/deps/liblog-178363436eabfb4e.rlib --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern syn=/home/user/simple-wasm/target/debug/deps/libsyn-12c8c9fe7f83c356.rlib --extern wasm_bindgen_shared=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_shared-d8152148aebf6d5d.rlib --cap-lints allow`
   Compiling wasm-bindgen-macro-support v0.2.40
     Running `rustc --edition=2018 --crate-name wasm_bindgen_macro_support /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-support-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="spans"' --cfg 'feature="wasm-bindgen-backend"' -C metadata=ab96c1aa98ff2337 -C extra-filename=-ab96c1aa98ff2337 --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern proc_macro2=/home/user/simple-wasm/target/debug/deps/libproc_macro2-d3456f7f985b30f5.rlib --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern syn=/home/user/simple-wasm/target/debug/deps/libsyn-12c8c9fe7f83c356.rlib --extern wasm_bindgen_backend=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_backend-aa5460080790b84c.rlib --extern wasm_bindgen_shared=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_shared-d8152148aebf6d5d.rlib --cap-lints allow`
   Compiling wasm-bindgen-macro v0.2.40
     Running `rustc --crate-name wasm_bindgen_macro /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.40/src/lib.rs --color always --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --cfg 'feature="spans"' --cfg 'feature="wasm-bindgen-macro-support"' -C metadata=e8b6c52194013b1f -C extra-filename=-e8b6c52194013b1f --out-dir /home/user/simple-wasm/target/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern quote=/home/user/simple-wasm/target/debug/deps/libquote-23dd3ea856cdd569.rlib --extern wasm_bindgen_macro_support=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro_support-ab96c1aa98ff2337.rlib --cap-lints allow`
     Running `rustc --crate-name wasm_bindgen /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.40/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="spans"' --cfg 'feature="std"' --cfg 'feature="wasm-bindgen-macro"' -C metadata=805eef06f23662b6 -C extra-filename=-805eef06f23662b6 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern wasm_bindgen_macro=/home/user/simple-wasm/target/debug/deps/libwasm_bindgen_macro-e8b6c52194013b1f.so --cap-lints allow`
   Compiling console_error_panic_hook v0.1.6
     Running `rustc --crate-name console_error_panic_hook /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/console_error_panic_hook-0.1.6/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=2891ebcc06a522d7 -C extra-filename=-2891ebcc06a522d7 --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern cfg_if=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libcfg_if-161e81c1e1ea1ab6.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib --cap-lints allow`
   Compiling simple-wasm v0.1.0 (/home/user/simple-wasm)
     Running `rustc --edition=2018 --crate-name simple_wasm src/lib.rs --color always --crate-type cdylib --crate-type rlib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=4bb0d303c287c5df --out-dir /home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/user/simple-wasm/target/debug/deps --extern console_error_panic_hook=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-2891ebcc06a522d7.rlib --extern double=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libdouble-f7bdb95ab507d2d9.rlib --extern wasm_bindgen=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-805eef06f23662b6.rlib -L native=/home/user/simple-wasm/target/wasm32-unknown-unknown/debug/build/double-sys-b3cdd135281094ab/out`
warning: unused import: `wasm_bindgen::prelude::*`
 --> src/lib.rs:6:5
  |
6 | use wasm_bindgen::prelude::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: function is never used: `set_panic_hook`
 --> src/utils.rs:1:1
  |
1 | pub fn set_panic_hook() {
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 17.38s
[INFO]: Installing wasm-bindgen...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 17.47s
[INFO]: :-) Your wasm pkg is ready to publish at ./pkg.
+ cd pkg
+ npm link
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

up to date in 0.605s
found 0 vulnerabilities

/opt/node-v10.15.3-linux-x64/lib/node_modules/simple-wasm -> /home/user/simple-wasm/pkg
+ cd www
+ npm link simple-wasm
/home/user/simple-wasm/www/node_modules/simple-wasm -> /opt/node-v10.15.3-linux-x64/lib/node_modules/simple-wasm -> /home/user/simple-wasm/pkg
+ npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

audited 7155 packages in 2.88s
found 0 vulnerabilities

+ npm run start

> [email protected] start /home/user/simple-wasm/www
> webpack-dev-server

ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
✖ 「wdm」: Hash: cef95608bf92005ac1d6
Version: webpack 4.29.6
Time: 527ms
Built at: 04/10/2019 9:14:55 PM
                           Asset          Size  Chunks             Chunk Names
                  0.bootstrap.js      3.87 KiB       0  [emitted]  
00bb30c087b2bd4bb381.module.wasm  unknown size       0  [emitted]  
                    bootstrap.js       355 KiB    main  [emitted]  main
                      index.html     175 bytes          [emitted]  
Entrypoint main = bootstrap.js
[0] multi (webpack)-dev-server/client?http://localhost:8080 ./bootstrap.js 40 bytes {main} [built]
[../pkg/simple_wasm.js] 1.21 KiB {0} [built]
[./bootstrap.js] 279 bytes {main} [built]
[./index.js] 52 bytes {0} [built]
[./node_modules/ansi-html/index.js] 4.16 KiB {main} [built]
[./node_modules/events/events.js] 13.3 KiB {main} [built]
[./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built]
[./node_modules/querystring-es3/index.js] 127 bytes {main} [built]
[./node_modules/url/url.js] 22.8 KiB {main} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:8080] (webpack)-dev-server/client?http://localhost:8080 8.1 KiB {main} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.59 KiB {main} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
[./node_modules/webpack-dev-server/node_modules/strip-ansi/index.js] (webpack)-dev-server/node_modules/strip-ansi/index.js 161 bytes {main} [built]
[./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 75 bytes {main} [built]
    + 14 hidden modules

ERROR in ../pkg/simple_wasm_bg.wasm
Module not found: Error: Can't resolve 'env' in '/home/user/simple-wasm/pkg'
 @ ../pkg/simple_wasm_bg.wasm
 @ ../pkg/simple_wasm.js
 @ ./index.js
 @ ./bootstrap.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./bootstrap.js
ℹ 「wdm」: Failed to compile.

@ashleygwilliams Am I not running npm/web-pack correctly, or is this an bug?

@ashleygwilliams
Copy link
Member

i'm not sure but it does seem to be a npm/web-pack sitch. i'll need to carve out some time to look at this more closely. i'm not sure what this error causing "env" bit means!

@ashleygwilliams ashleygwilliams self-assigned this Apr 12, 2019
@ct-porco
Copy link

I am also trying to compile the Capstone engine to WebAssembly and getting the same results. Using CC=clang-8 wasm-pack build --dev -- -v satisfies wasm-pack and allows it to finish compiling. However, when I try to host my web app using npm run start, I get the same Module not found: Error: Can't resolve 'env' in '/path/to/file.wasm' error. Using wasm2wat I was able to see that my wasm module is trying to import functions when it is loaded. The general wat syntax for this import is import "namespace" "function_name" (func $function_name (type <number>))). (This article has a some information on how imports work: https://medium.com/wasmer/executing-webassembly-in-your-rust-application-d5cd32e8ce46) I also noticed that all of the functions that my wasm module is trying to import from env are in the C standard library. Capstone is designed to pull some functions from it's environment when its called, so this isn't surprising (http://www.capstone-engine.org/embed.html).

@ashleygwilliams Could there be a way to direct wasm-pack to compile functions found in the C standard library to wasm when the rest of the package is built? That way there won't be an imports to be missing, and a more static library will be produced.

@tmfink
Copy link
Author

tmfink commented Jun 9, 2019

This basic example seems to work now, perhaps from a Rust or clang update?

$ cargo -vV
cargo 1.34.0 (6789d8a0a 2019-04-01)
release: 1.34.0
commit-hash: 6789d8a0a54a96d95365c4e1fb01d47a5eed9937
commit-date: 2019-04-01
$ clang-8 --version
clang version 8.0.1-svn360950-1~exp1~20190517004233.70 (branches/release_80)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@ct-porco any success on your end? My proof-of-concept C code here is simple, just:

double-sys/double/double.c:

unsigned int double_it(unsigned int x) {
    return x * 2;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants