diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs index 95a82601702..e802ef8d265 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs @@ -47,14 +47,25 @@ fn main() -> anyhow::Result<()> { None => bail!("must have a file to test as first argument"), }; - // Assume a cargo-like directory layout and generate output at - // `target/wasm32-unknown-unknown/wbg-tmp/...` - let tmpdir = wasm_file_to_test - .parent() // chop off file name - .and_then(|p| p.parent()) // chop off `deps` - .and_then(|p| p.parent()) // chop off `debug` - .map(|p| p.join("wbg-tmp")) - .ok_or_else(|| anyhow!("file to test doesn't follow the expected Cargo conventions"))?; + // wasm_file_to_test may be + // - a cargo-like directory layout and generate output at + // `target/wasm32-unknown-unknown/...` + // - a tmp directory, generated by rustdoc + // we would like a directory we have write access to. if we assume cargo-like directories, + // we end up with the path `/wbg-out` + let tmpdir = if wasm_file_to_test + .to_string_lossy() + .starts_with("/tmp/rustdoc") + { + wasm_file_to_test.parent() // chop off the file name and give us the /tmp/rustdoc directory + } else { + wasm_file_to_test + .parent() // chop off file name + .and_then(|p| dbg!(p.parent())) // chop off `deps` + .and_then(|p| dbg!(p.parent())) // chop off `debug` + } + .map(|p| p.join("wbg-tmp")) + .ok_or_else(|| anyhow!("file to test doesn't follow the expected Cargo conventions"))?; // Make sure there's no stale state from before drop(fs::remove_dir_all(&tmpdir));