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        main_needs_argc_argv: true,
32        panic_strategy: PanicStrategy::Unwind,
33        no_default_libraries: false,
34        families: cvs!["unix", "wasm"],
35        // Explicitly override the `base::wasm`'s `llvm_args` back to empty. The
36        // base is to force using the most standard exception-handling
37        // instructions, when enabled, but this target is intended to follow
38        // Emscripten, which is whatever LLVM defaults to.
39        llvm_args: cvs![],
40        ..base::wasm::options()
41    };
42    Target {
43        llvm_target: "wasm32-unknown-emscripten".into(),
44        metadata: TargetMetadata {
45            description: Some("WebAssembly via Emscripten".into()),
46            tier: Some(2),
47            host_tools: Some(false),
48            std: Some(true),
49        },
50        pointer_width: 32,
51        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"
52            .into(),
53        arch: Arch::Wasm32,
54        options: opts,
55    }
56}