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

cargo test tries to execute .wasm files #7471

Closed
tlively opened this issue Oct 3, 2019 · 3 comments · Fixed by #7476
Closed

cargo test tries to execute .wasm files #7471

tlively opened this issue Oct 3, 2019 · 3 comments · Fixed by #7476
Labels
C-bug Category: bug

Comments

@tlively
Copy link
Contributor

tlively commented Oct 3, 2019

Problem
When using target wasm32-unknown-emscripten, cargo test correctly uses node to execute the .js test files, but also attempts to execute the output .wasm files with node. This was observed during the development of rust-lang/rust#63649, for example when running ./x.py test src/libcore.

Steps

$ cargo new mytest
$ cd mytest
$ CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node cargo test --target wasm32-unknown-emscripten
   Compiling rust_test v0.1.0 (/usr/local/google/home/tlively/code/rust_test)
    Finished test [unoptimized + debuginfo] target(s) in 4.10s
     Running target/wasm32-unknown-emscripten/debug/deps/rust_test-89db5c32db7329f0.js

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/wasm32-unknown-emscripten/debug/deps/rust_test_89db5c32db7329f0.wasm
internal/modules/cjs/loader.js:775
    throw err;
    ^

Error: Cannot find module '/usr/local/google/home/tlively/code/rust_test/target/wasm32-unknown-emscripten/debug/deps/rust_test_89db5c32db7329f0.wasm'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
error: test failed, to rerun pass '--lib'

I've put some effort into fixing this myself, but I can't figure out where the best place to filter out the .wasm files would be. It would be simple to filter them out in cargo_test.rs, but it seems like it would be more elegant to filter them out or mark them as not executable somewhere in the compilation machinery. Pointers and suggestions would be much appreciated!

@tlively tlively added the C-bug Category: bug label Oct 3, 2019
@ehuss
Copy link
Contributor

ehuss commented Oct 3, 2019

Is this maybe a duplicate of #7255?

@tlively
Copy link
Contributor Author

tlively commented Oct 3, 2019

Yes it is, although the top post of that issue focuses on the file name when the larger issue is that the wasm is being executed at all. I'd be fine rolling this issue into the other or vice versa.

@alexcrichton
Copy link
Member

The wasm file is added around here and I think the fix may be to tweak the FileFlavor to indicate that it's not-normal? We could probably reuse DebugInfo but rename it to something like "aux file"

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants