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