Skip to content

Commit 715e5d8

Browse files
committed
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.
1 parent b6c6f68 commit 715e5d8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct TargetInfo {
4242
pub enum FileFlavor {
4343
/// Not a special file type.
4444
Normal,
45+
/// Like `Normal`, but not directly executable
46+
Auxiliary,
4547
/// Something you can link against (e.g., a library).
4648
Linkable { rmeta: bool },
4749
/// Piece of external debug information (e.g., `.dSYM`/`.pdb` file).
@@ -253,10 +255,15 @@ impl TargetInfo {
253255

254256
// See rust-lang/cargo#4535.
255257
if target_triple.starts_with("wasm32-") && crate_type == "bin" && suffix == ".js" {
258+
let flavor = if target_triple.contains("emscripten") {
259+
FileFlavor::Auxiliary
260+
} else {
261+
FileFlavor::Normal
262+
};
256263
ret.push(FileType {
257264
suffix: ".wasm".to_string(),
258265
prefix: prefix.clone(),
259-
flavor: FileFlavor::Normal,
266+
flavor,
260267
should_replace_hyphens: true,
261268
})
262269
}

src/cargo/core/compiler/context/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
167167

168168
for unit in units.iter() {
169169
for output in self.outputs(unit)?.iter() {
170-
if output.flavor == FileFlavor::DebugInfo {
170+
if output.flavor == FileFlavor::DebugInfo ||
171+
output.flavor == FileFlavor::Auxiliary {
171172
continue;
172173
}
173174

0 commit comments

Comments
 (0)