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", "--max-memory=1073741824"],
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 "-Wl,--max-memory=1073741824",
32 ],
33 );
34
35 options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
36 options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
37
38 // FIXME: Figure out cases in which WASM needs to link with a native toolchain.
39 options.link_self_contained = LinkSelfContainedDefault::True;
40
41 // Right now this is a bit of a workaround but we're currently saying that
42 // the target by default has a static crt which we're taking as a signal
43 // for "use the bundled crt". If that's turned off then the system's crt
44 // will be used, but this means that default usage of this target doesn't
45 // need an external compiler but it's still interoperable with an external
46 // compiler if configured correctly.
47 options.crt_static_default = true;
48 options.crt_static_respected = true;
49
50 // Allow `+crt-static` to create a "cdylib" output which is just a wasm file
51 // without a main function.
52 options.crt_static_allows_dylibs = true;
53
54 // WASI's `sys::args::init` function ignores its arguments; instead,
55 // `args::args()` makes the WASI API calls itself.
56 options.main_needs_argc_argv = false;
57
58 // And, WASI mangles the name of "main" to distinguish between different
59 // signatures.
60 options.entry_name = "__main_void".into();
61
62 options.singlethread = false;
63 options.features = "+atomics,+bulk-memory,+mutable-globals".into();
64
65 Target {
66 llvm_target: "wasm32-wasi".into(),
67 metadata: TargetMetadata {
68 description: None,
69 tier: Some(2),
70 host_tools: Some(false),
71 std: Some(true),
72 },
73 pointer_width: 32,
74 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(),
75 arch: "wasm32".into(),
76 options,
77 }
78}