rustc_target/spec/targets/
wasm32v1_none.rs

1//! A "bare wasm" target representing a WebAssembly output that does not import
2//! anything from its environment and also specifies an _upper_ bound on the set
3//! of WebAssembly proposals that are supported.
4//!
5//! It's equivalent to the `wasm32-unknown-unknown` target with the additional
6//! flags `-Ctarget-cpu=mvp` and `-Ctarget-feature=+mutable-globals`. This
7//! enables just the features specified in <https://www.w3.org/TR/wasm-core-1/>
8//!
9//! This is a _separate target_ because using `wasm32-unknown-unknown` with
10//! those target flags doesn't automatically rebuild libcore / liballoc with
11//! them, and in order to get those libraries rebuilt you need to use the
12//! nightly Rust feature `-Zbuild-std`. This target is for people who want to
13//! use stable Rust, and target a stable set pf WebAssembly features.
14
15use crate::spec::{Cc, LinkerFlavor, Target, base};
16
17pub(crate) fn target() -> Target {
18    let mut options = base::wasm::options();
19    options.os = "none".into();
20
21    // WebAssembly 1.0 shipped in 2019 and included exactly one proposal
22    // after the initial "MVP" feature set: "mutable-globals".
23    options.cpu = "mvp".into();
24    options.features = "+mutable-globals".into();
25
26    options.add_pre_link_args(
27        LinkerFlavor::WasmLld(Cc::No),
28        &[
29            // For now this target just never has an entry symbol no matter the output
30            // type, so unconditionally pass this.
31            "--no-entry",
32        ],
33    );
34    options.add_pre_link_args(
35        LinkerFlavor::WasmLld(Cc::Yes),
36        &[
37            // Make sure clang uses LLD as its linker and is configured appropriately
38            // otherwise
39            "--target=wasm32-unknown-unknown",
40            "-Wl,--no-entry",
41        ],
42    );
43
44    Target {
45        llvm_target: "wasm32-unknown-unknown".into(),
46        metadata: crate::spec::TargetMetadata {
47            description: Some("WebAssembly".into()),
48            tier: Some(2),
49            host_tools: Some(false),
50            std: Some(false),
51        },
52        pointer_width: 32,
53        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(),
54        arch: "wasm32".into(),
55        options,
56    }
57}