Skip to content

Commit e47102f

Browse files
committed
Add wasm32v1-none target (compiler-team/#791)
1 parent 798fb83 commit e47102f

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ supported_targets! {
18031803

18041804
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
18051805
("wasm32-unknown-unknown", wasm32_unknown_unknown),
1806+
("wasm32v1-none", wasm32v1_none),
18061807
("wasm32-wasi", wasm32_wasi),
18071808
("wasm32-wasip1", wasm32_wasip1),
18081809
("wasm32-wasip2", wasm32_wasip2),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//! A "bare wasm" target representing a WebAssembly output that makes zero
2+
//! assumptions about its environment, similar to wasm32-unknown-unknown, but
3+
//! that also specifies an _upper_ bound on the set of wasm proposals that are
4+
//! supported.
5+
//!
6+
//! It is implemented as a variant on LLVM's wasm32-unknown-unknown target, with
7+
//! the additional flags `-Ctarget-cpu=mvp` and `-Ctarget-feature=+mutable-globals`.
8+
//!
9+
//! This target exists to resolve a tension in Rustc's choice of WebAssembly
10+
//! proposals to support. Since most WebAssembly users are in fact _on the web_
11+
//! and web browsers are frequently updated with support for the latest
12+
//! features, it is reasonable for Rustc to generate wasm code that exploits new
13+
//! WebAssembly proposals as they gain browser support. At least by default. And
14+
//! this is what the wasm32-unknown-unknown target does, which means that the
15+
//! _exact_ WebAssembly features that Rustc generates will change over time.
16+
//!
17+
//! But a different set of users -- smaller but nonetheless worth supporting --
18+
//! are using WebAssembly in implementations that either don't get updated very
19+
//! often, or need to prioritize stability, implementation simplicity or
20+
//! security over feature support. This target is for them, and it promises that
21+
//! the wasm code it generates will not go beyond the proposals/features of the
22+
//! W3C WebAssembly core 1.0 spec, which (as far as I can tell) is approximately
23+
//! "the wasm MVP plus mutable globals". Mutable globals was proposed in 2018
24+
//! and made it in.
25+
//!
26+
//! See https://www.w3.org/TR/wasm-core-1/
27+
//!
28+
//! Notably this feature-set _excludes_:
29+
//!
30+
//! - sign-extension operators
31+
//! - non-trapping / saturating float-to-int conversions
32+
//! - multi-value
33+
//! - reference types
34+
//! - bulk memory operations
35+
//! - SIMD
36+
//!
37+
//! These are all listed as additions in the core 2.0 spec. Also they were all
38+
//! proposed after 2020, and core 1.0 shipped in 2019. It also excludes even
39+
//! later proposals such as:
40+
//!
41+
//! - exception handling
42+
//! - tail calls
43+
//! - extended consts
44+
//! - function references
45+
//! - multi-memory
46+
//! - component model
47+
//! - gc
48+
//! - threads
49+
//! - relaxed SIMD
50+
//! - custom annotations
51+
//! - branch hinting
52+
//!
53+
54+
use crate::spec::{Cc, LinkerFlavor, Target, base};
55+
56+
pub(crate) fn target() -> Target {
57+
let mut options = base::wasm::options();
58+
options.os = "none".into();
59+
60+
options.cpu = "mvp".into();
61+
options.features = "+mutable-globals".into();
62+
63+
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::No), &[
64+
// For now this target just never has an entry symbol no matter the output
65+
// type, so unconditionally pass this.
66+
"--no-entry",
67+
]);
68+
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &[
69+
// Make sure clang uses LLD as its linker and is configured appropriately
70+
// otherwise
71+
"--target=wasm32-unknown-unknown",
72+
"-Wl,--no-entry",
73+
]);
74+
75+
Target {
76+
llvm_target: "wasm32-unknown-unknown".into(),
77+
metadata: crate::spec::TargetMetadata {
78+
description: Some("WebAssembly".into()),
79+
tier: Some(2),
80+
host_tools: Some(false),
81+
std: Some(false),
82+
},
83+
pointer_width: 32,
84+
data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(),
85+
arch: "wasm32".into(),
86+
options,
87+
}
88+
}

tests/assembly/targets/targets-elf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@
522522
//@ revisions: wasm32_unknown_unknown
523523
//@ [wasm32_unknown_unknown] compile-flags: --target wasm32-unknown-unknown
524524
//@ [wasm32_unknown_unknown] needs-llvm-components: webassembly
525+
//@ revisions: wasm32v1_none
526+
//@ [wasm32v1_none] compile-flags: --target wasm32v1-none
527+
//@ [wasm32v1_none] needs-llvm-components: webassembly
525528
//@ revisions: wasm32_wasi
526529
//@ [wasm32_wasi] compile-flags: --target wasm32-wasi
527530
//@ [wasm32_wasi] needs-llvm-components: webassembly

0 commit comments

Comments
 (0)