]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs
Merge commit '98e2b9f25b6db4b2680a3d388456d9f95cb28344' into clippyup
[rust.git] / compiler / rustc_target / src / spec / wasm32_unknown_emscripten.rs
1 use super::wasm_base;
2 use super::{LinkArgs, LinkerFlavor, PanicStrategy, Target, TargetOptions};
3
4 pub fn target() -> Target {
5     let mut options = wasm_base::options();
6
7     let clang_args = options.pre_link_args.entry(LinkerFlavor::Gcc).or_default();
8
9     // Rust really needs a way for users to specify exports and imports in
10     // the source code. --export-dynamic isn't the right tool for this job,
11     // however it does have the side effect of automatically exporting a lot
12     // of symbols, which approximates what people want when compiling for
13     // wasm32-unknown-unknown expect, so use it for now.
14     clang_args.push("--export-dynamic".to_string());
15
16     let mut post_link_args = LinkArgs::new();
17     post_link_args.insert(
18         LinkerFlavor::Em,
19         vec![
20             "-s".to_string(),
21             "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string(),
22             "-s".to_string(),
23             "ASSERTIONS=1".to_string(),
24             "-s".to_string(),
25             "ABORTING_MALLOC=0".to_string(),
26             "-Wl,--fatal-warnings".to_string(),
27         ],
28     );
29
30     let opts = TargetOptions {
31         os: "emscripten".to_string(),
32         linker_flavor: LinkerFlavor::Em,
33         // emcc emits two files - a .js file to instantiate the wasm and supply platform
34         // functionality, and a .wasm file.
35         exe_suffix: ".js".to_string(),
36         linker: None,
37         linker_is_gnu: true,
38         is_like_emscripten: true,
39         panic_strategy: PanicStrategy::Unwind,
40         post_link_args,
41         os_family: Some("unix".to_string()),
42         ..options
43     };
44     Target {
45         llvm_target: "wasm32-unknown-emscripten".to_string(),
46         pointer_width: 32,
47         data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(),
48         arch: "wasm32".to_string(),
49         options: opts,
50     }
51 }