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

Error running tests in wasm32-unknown-emscripten environment. #7255

Closed
agausmann opened this issue Aug 16, 2019 · 1 comment · Fixed by #7476
Closed

Error running tests in wasm32-unknown-emscripten environment. #7255

agausmann opened this issue Aug 16, 2019 · 1 comment · Fixed by #7476
Labels
C-bug Category: bug Command-test O-wasm OS: WASM target released issues

Comments

@agausmann
Copy link

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)

  1. Install and activate the Emscripten SDK (latest).
  2. 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.
  1. Create a library project from the template: cargo new --lib foo && cd foo
  2. Build the tests using cross or cargo (either one will reproduce the error): cargo build --tests --target wasm32-unknown-emscripten
  3. 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)
@agausmann agausmann added the C-bug Category: bug label Aug 16, 2019
@agausmann
Copy link
Author

After thinking about it further, I'm skeptical that Cargo should even be trying to run the WASM file. It already runs the JS file which appears to be a wrapper around the WASM.

@ehuss ehuss added Command-test O-wasm OS: WASM target released issues labels Sep 21, 2019
bors added a commit that referenced this issue Oct 4, 2019
Mark Emscripten's .wasm files auxiliary

This fixes #7471 and fixes #7255 by preventing the .wasm file from
being treated as an executable binary, so `cargo test` and `cargo run`
will no longer try to execute it directly. This change is only made
for Emscripten, which outputs a .js file as the primary executable
entry point, as opposed to other WebAssembly targets for which the
.wasm file is the only output.
@bors bors closed this as completed in 715e5d8 Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-test O-wasm OS: WASM target released issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants