Skip to content

cargo test tries to execute .wasm files #7471

Closed
@tlively

Description

@tlively

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions