From 715e5d8035659bfa91ddc4805748d05744bf6553 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 3 Oct 2019 16:42:23 -0700 Subject: [PATCH] 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. --- src/cargo/core/compiler/build_context/target_info.rs | 9 ++++++++- src/cargo/core/compiler/context/mod.rs | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 926a1ca9664..61bbb365dfc 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -42,6 +42,8 @@ pub struct TargetInfo { pub enum FileFlavor { /// Not a special file type. Normal, + /// Like `Normal`, but not directly executable + Auxiliary, /// Something you can link against (e.g., a library). Linkable { rmeta: bool }, /// Piece of external debug information (e.g., `.dSYM`/`.pdb` file). @@ -253,10 +255,15 @@ impl TargetInfo { // See rust-lang/cargo#4535. if target_triple.starts_with("wasm32-") && crate_type == "bin" && suffix == ".js" { + let flavor = if target_triple.contains("emscripten") { + FileFlavor::Auxiliary + } else { + FileFlavor::Normal + }; ret.push(FileType { suffix: ".wasm".to_string(), prefix: prefix.clone(), - flavor: FileFlavor::Normal, + flavor, should_replace_hyphens: true, }) } diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index db5ea9eca17..55f2a4fb354 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -167,7 +167,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> { for unit in units.iter() { for output in self.outputs(unit)?.iter() { - if output.flavor == FileFlavor::DebugInfo { + if output.flavor == FileFlavor::DebugInfo || + output.flavor == FileFlavor::Auxiliary { continue; }