-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
Testing the wasm32-unknown-emscripten
target fails due to a filename mismatch in the compilation output:
$ cross test --verbose --target wasm32-unknown-emscripten
+ "rustup" "target" "list"
+ "cargo" "fetch" "--manifest-path" "/home/adam/dev/ldcore/Cargo.toml"
+ "rustc" "--print" "sysroot"
+ "docker" "run" "--userns" "host" "--rm" "--user" "1000:1000" "-e" "CARGO_HOME=/cargo" "-e" "CARGO_TARGET_DIR=/target" "-e" "USER=adam" "-e" "XARGO_HOME=/xargo" "-v" "/home/adam/.xargo:/xargo" "-v" "/home/adam/.cargo:/cargo" "-v" "/home/adam/dev/ldcore:/project:ro" "-v" "/home/adam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/rust:ro" "-v" "/home/adam/dev/ldcore/target:/target" "-w" "/project" "-it" "japaric/wasm32-unknown-emscripten:v0.1.14" "sh" "-c" "PATH=$PATH:/rust/bin \"cargo\" \"test\" \"--verbose\" \"--target\" \"wasm32-unknown-emscripten\""
Compiling ldcore v0.1.0 (/project)
Running `rustc --edition=2018 --crate-name ldcore src/lib.rs --color always --emit=dep-info,link -C debuginfo=2 --test -C metadata=ecd9c7299ab7d7c3 -C extra-filename=-ecd9c7299ab7d7c3 --out-dir /target/wasm32-unknown-emscripten/debug/deps --target wasm32-unknown-emscripten -C incremental=/target/wasm32-unknown-emscripten/debug/incremental -L dependency=/target/wasm32-unknown-emscripten/debug/deps -L dependency=/target/debug/deps`
Finished dev [unoptimized + debuginfo] target(s) in 5.63s
Running `node-wasm /target/wasm32-unknown-emscripten/debug/deps/ldcore-ecd9c7299ab7d7c3.js`
running 1 test
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Running `node-wasm /target/wasm32-unknown-emscripten/debug/deps/ldcore_ecd9c7299ab7d7c3.wasm`
module.js:487
throw err;
^
Error: Cannot find module '/target/wasm32-unknown-emscripten/debug/deps/ldcore_ecd9c7299ab7d7c3.wasm'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
error: test failed, to rerun pass '--lib'
I checked the output directory and confirmed the file does not exist, but one named ldcore-ecd9c7299ab7d7c3.wasm
does (note the hyphen instead of the underscore):
$ ls target/wasm32-unknown-emscripten/debug/deps/
ldcore-0c4924d1705b39bd.d ldcore-ecd9c7299ab7d7c3.wasm libldcore-0c4924d1705b39bd.rlib
ldcore-ecd9c7299ab7d7c3.d ldcore-ecd9c7299ab7d7c3.wasm.map libldcore-0c4924d1705b39bd.rmeta
ldcore-ecd9c7299ab7d7c3.js ldcore-ecd9c7299ab7d7c3.wast
I've confirmed that building the project outside of the cross
environment produces the same file with a hyphen, not an underscore:
$ cargo clean && cargo build --tests --target wasm32-unknown-emscripten
Compiling ldcore v0.1.0 (/home/adam/dev/ldcore)
Finished dev [unoptimized + debuginfo] target(s) in 7.04s
$ ls target/wasm32-unknown-emscripten/debug/deps/
ldcore-a3bffe884c1348b1.d ldcore-a3bffe884c1348b1.wasm ldcore-a3bffe884c1348b1.wast
ldcore-a3bffe884c1348b1.js ldcore-a3bffe884c1348b1.wasm.map
Steps (Linux)
- Install and activate the Emscripten SDK (latest).
- Install cross:
cargo install cross
(make sure you also have Docker installed and available)
- I had to modify the container image that cross uses to run WASM so it would have a newer version of emsdk. This is needed for it to work properly, but it is not fixed upstream yet.
- Create a library project from the template:
cargo new --lib foo && cd foo
- Build the tests using cross or cargo (either one will reproduce the error):
cargo build --tests --target wasm32-unknown-emscripten
- Attempt to run the the tests:
cross test --target wasm32-unknown-emscripten
Possible Solution(s)
I did some digging, and to my surprise, this is probably caused by a specific case implemented just for WASM: the should_replace_hyphens
field. Some more research needs to be done to figure out exactly why this was added and if it is still required by some supported configurations. There may have been some update to the Emscripten SDK that made it start emitting hyphens - in that case, I'm not entirely sure how we will detect and fix that.
Notes
- Output of
cargo version
:cargo 1.38.0-nightly (e853aa976 2019-08-09)
(having trouble updating to latest nightly, but will edit this when I've reproduced it.
- Emscripten SDK version: 1.38.31 (latest as of the time of posting)