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 // Use the wasm C-ABI entry name from the tool-conventions BasicCABI
33 // spec rather than a raw `main`, as referenced by emscripten's crt/libc.
34 // Required for entry paths like `-sPROXY_TO_PTHREAD`, whose
35 // `crt1_proxy_main` links against `__main_argc_argv`.
36 entry_name: "__main_argc_argv".into(),
37 panic_strategy: PanicStrategy::Unwind,
38 no_default_libraries: false,
39 families: cvs!["unix", "wasm"],
40 // Explicitly override the `base::wasm`'s `llvm_args` back to empty. The
41 // base is to force using the most standard exception-handling
42 // instructions, when enabled, but this target is intended to follow
43 // Emscripten, which is whatever LLVM defaults to.
44 llvm_args: cvs![],
45 ..base::wasm::options()
46 };
47 Target {
48 llvm_target: "wasm32-unknown-emscripten".into(),
49 metadata: TargetMetadata {
50 description: Some("WebAssembly via Emscripten".into()),
51 tier: Some(2),
52 host_tools: Some(false),
53 std: Some(true),
54 },
55 pointer_width: 32,
56 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"
57 .into(),
58 arch: Arch::Wasm32,
59 options: opts,
60 }
61}