rustc_target/spec/targets/
wasm32_wasip1_threads.rs

1//! The `wasm32-wasip1-threads` target is an extension of the `wasm32-wasip1`
2//! target where threads are enabled by default for all crates. This target
3//! should be considered "in flux" as WASI itself has moved on from "p1" to "p2"
4//! now and threads in "p2" are still under heavy design.
5//!
6//! This target inherits most of the other aspects of `wasm32-wasip1`.
7//!
8//! Historically this target was known as `wasm32-wasi-preview1-threads`.
9
10use crate::spec::{
11    Cc, LinkSelfContainedDefault, LinkerFlavor, Target, TargetMetadata, base, crt_objects,
12};
13
14pub(crate) fn target() -> Target {
15    let mut options = base::wasm::options();
16
17    options.os = "wasi".into();
18    options.env = "p1".into();
19
20    options.add_pre_link_args(
21        LinkerFlavor::WasmLld(Cc::No),
22        &["--import-memory", "--export-memory", "--shared-memory"],
23    );
24    options.add_pre_link_args(
25        LinkerFlavor::WasmLld(Cc::Yes),
26        &[
27            "--target=wasm32-wasip1-threads",
28            "-Wl,--import-memory",
29            "-Wl,--export-memory,",
30            "-Wl,--shared-memory",
31        ],
32    );
33
34    options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
35    options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
36
37    // FIXME: Figure out cases in which WASM needs to link with a native toolchain.
38    options.link_self_contained = LinkSelfContainedDefault::True;
39
40    // Right now this is a bit of a workaround but we're currently saying that
41    // the target by default has a static crt which we're taking as a signal
42    // for "use the bundled crt". If that's turned off then the system's crt
43    // will be used, but this means that default usage of this target doesn't
44    // need an external compiler but it's still interoperable with an external
45    // compiler if configured correctly.
46    options.crt_static_default = true;
47    options.crt_static_respected = true;
48
49    // Allow `+crt-static` to create a "cdylib" output which is just a wasm file
50    // without a main function.
51    options.crt_static_allows_dylibs = true;
52
53    // WASI's `sys::args::init` function ignores its arguments; instead,
54    // `args::args()` makes the WASI API calls itself.
55    options.main_needs_argc_argv = false;
56
57    // And, WASI mangles the name of "main" to distinguish between different
58    // signatures.
59    options.entry_name = "__main_void".into();
60
61    options.singlethread = false;
62    options.features = "+atomics,+bulk-memory,+mutable-globals".into();
63
64    Target {
65        llvm_target: "wasm32-wasi".into(),
66        metadata: TargetMetadata {
67            description: None,
68            tier: Some(2),
69            host_tools: Some(false),
70            std: Some(true),
71        },
72        pointer_width: 32,
73        data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20".into(),
74        arch: "wasm32".into(),
75        options,
76    }
77}