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