Skip to content

Commit

Permalink
Mark Emscripten's .wasm files auxiliary
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tlively committed Oct 3, 2019
1 parent b6c6f68 commit 715e5d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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,
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 715e5d8

Please sign in to comment.