Skip to main content

rustc_target/spec/targets/
wasm32_unknown_emscripten.rs

1use crate::spec::{
2    Arch, LinkArgs, LinkerFlavor, Os, PanicStrategy, RelocModel, Target, TargetMetadata,
3    TargetOptions, base, cvs,
4};
5
6pub(crate) fn target() -> Target {
7    // Reset flags for non-Em flavors back to empty to satisfy sanity checking tests.
8    let pre_link_args = LinkArgs::new();
9    let post_link_args =
10        TargetOptions::link_args(LinkerFlavor::EmCc, &["-sABORTING_MALLOC=0", "-sWASM_BIGINT"]);
11
12    let opts = TargetOptions {
13        os: Os::Emscripten,
14        linker_flavor: LinkerFlavor::EmCc,
15        // emcc emits two files - a .js file to instantiate the wasm and supply platform
16        // functionality, and a .wasm file.
17        exe_suffix: ".js".into(),
18        linker: None,
19        pre_link_args,
20        post_link_args,
21        relocation_model: RelocModel::Pic,
22        // crt_static should always be true for an executable and always false
23        // for a shared library. There is no easy way to indicate this and it
24        // doesn't seem to matter much so we set crt_static_allows_dylibs to
25        // true and leave crt_static as true when linking dynamic libraries.
26        // wasi also sets crt_static_allows_dylibs: true so this is at least
27        // aligned between wasm targets.
28        crt_static_respected: true,
29        crt_static_default: true,
30        crt_static_allows_dylibs: true,
31        panic_strategy: PanicStrategy::Unwind,
32        no_default_libraries: false,
33        families: cvs!["unix", "wasm"],
34        ..base::wasm::options()
35    };
36    Target {
37        llvm_target: "wasm32-unknown-emscripten".into(),
38        metadata: TargetMetadata {
39            description: Some("WebAssembly via Emscripten".into()),
40            tier: Some(2),
41            host_tools: Some(false),
42            std: Some(true),
43        },
44        pointer_width: 32,
45        data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
46            .into(),
47        arch: Arch::Wasm32,
48        options: opts,
49    }
50}