Skip to content

Commit 674267e

Browse files
committed
Promote the wasm32-wasip2 target to Tier 2
This commit promotes the `wasm32-wasip2` Rust target to tier 2 as proposed in rust-lang/compiler-team#760. There are two major changes in this PR: 1. The `dist-various-2` container, which already produces the other WASI targets, now has an extra target added for `wasm32-wasip2`. 2. A new `wasm-component-ld` binary is added to all host toolchains when LLD is enabled. This is the linker used for the `wasm32-wasip2` target. This new linker is added for all host toolchains to ensure that all host toolchains can produce the `wasm32-wasip2` target. This is similar to how `rust-lld` was originally included for all host toolchains to be able to produce WebAssembly output when the targets were first added. The new linker is developed [here][wasm-component-ld] and is pulled in via a crates.io-based dependency to the tree here. [wasm-component-ld]: https://github.com/bytecodealliance/wasm-component-ld
1 parent 5a3e2a4 commit 674267e

File tree

9 files changed

+291
-3
lines changed

9 files changed

+291
-3
lines changed

Cargo.lock

+154-3
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ dependencies = [
16651665
"compiler_builtins",
16661666
"rustc-std-workspace-alloc",
16671667
"rustc-std-workspace-core",
1668+
"serde",
16681669
]
16691670

16701671
[[package]]
@@ -1874,6 +1875,12 @@ dependencies = [
18741875
"syn 2.0.67",
18751876
]
18761877

1878+
[[package]]
1879+
name = "id-arena"
1880+
version = "2.2.1"
1881+
source = "registry+https://github.com/rust-lang/crates.io-index"
1882+
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
1883+
18771884
[[package]]
18781885
name = "ident_case"
18791886
version = "1.0.1"
@@ -2103,6 +2110,12 @@ version = "1.0.5"
21032110
source = "registry+https://github.com/rust-lang/crates.io-index"
21042111
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21052112

2113+
[[package]]
2114+
name = "lexopt"
2115+
version = "0.3.0"
2116+
source = "registry+https://github.com/rust-lang/crates.io-index"
2117+
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
2118+
21062119
[[package]]
21072120
name = "libc"
21082121
version = "0.2.155"
@@ -2617,7 +2630,7 @@ dependencies = [
26172630
"indexmap",
26182631
"memchr",
26192632
"ruzstd 0.5.0",
2620-
"wasmparser",
2633+
"wasmparser 0.118.2",
26212634
]
26222635

26232636
[[package]]
@@ -3398,7 +3411,7 @@ dependencies = [
33983411
"object 0.34.0",
33993412
"regex",
34003413
"similar",
3401-
"wasmparser",
3414+
"wasmparser 0.118.2",
34023415
]
34033416

34043417
[[package]]
@@ -3772,7 +3785,7 @@ dependencies = [
37723785
"thin-vec",
37733786
"thorin-dwp",
37743787
"tracing",
3775-
"wasm-encoder",
3788+
"wasm-encoder 0.200.0",
37763789
"windows",
37773790
]
37783791

@@ -5214,6 +5227,15 @@ dependencies = [
52145227
"color-eyre",
52155228
]
52165229

5230+
[[package]]
5231+
name = "spdx"
5232+
version = "0.10.6"
5233+
source = "registry+https://github.com/rust-lang/crates.io-index"
5234+
checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc"
5235+
dependencies = [
5236+
"smallvec",
5237+
]
5238+
52175239
[[package]]
52185240
name = "spdx-expression"
52195241
version = "0.5.2"
@@ -6261,6 +6283,28 @@ version = "0.2.92"
62616283
source = "registry+https://github.com/rust-lang/crates.io-index"
62626284
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
62636285

6286+
[[package]]
6287+
name = "wasm-component-ld"
6288+
version = "0.5.4"
6289+
source = "registry+https://github.com/rust-lang/crates.io-index"
6290+
checksum = "314d932d5e84c9678751b85498b1482b2f32f185744e449d3ce0b1d400376dad"
6291+
dependencies = [
6292+
"anyhow",
6293+
"clap",
6294+
"lexopt",
6295+
"tempfile",
6296+
"wasmparser 0.210.0",
6297+
"wat",
6298+
"wit-component",
6299+
]
6300+
6301+
[[package]]
6302+
name = "wasm-component-ld-wrapper"
6303+
version = "0.1.0"
6304+
dependencies = [
6305+
"wasm-component-ld",
6306+
]
6307+
62646308
[[package]]
62656309
name = "wasm-encoder"
62666310
version = "0.200.0"
@@ -6270,6 +6314,40 @@ dependencies = [
62706314
"leb128",
62716315
]
62726316

6317+
[[package]]
6318+
name = "wasm-encoder"
6319+
version = "0.210.0"
6320+
source = "registry+https://github.com/rust-lang/crates.io-index"
6321+
checksum = "e7e3764d9d6edabd8c9e16195e177be0d20f6ab942ad18af52860f12f82bc59a"
6322+
dependencies = [
6323+
"leb128",
6324+
]
6325+
6326+
[[package]]
6327+
name = "wasm-encoder"
6328+
version = "0.211.1"
6329+
source = "registry+https://github.com/rust-lang/crates.io-index"
6330+
checksum = "5e7d931a1120ef357f32b74547646b6fa68ea25e377772b72874b131a9ed70d4"
6331+
dependencies = [
6332+
"leb128",
6333+
]
6334+
6335+
[[package]]
6336+
name = "wasm-metadata"
6337+
version = "0.210.0"
6338+
source = "registry+https://github.com/rust-lang/crates.io-index"
6339+
checksum = "012729d1294907fcb0866f08460ab95426a6d0b176a599619b84cac7653452b4"
6340+
dependencies = [
6341+
"anyhow",
6342+
"indexmap",
6343+
"serde",
6344+
"serde_derive",
6345+
"serde_json",
6346+
"spdx",
6347+
"wasm-encoder 0.210.0",
6348+
"wasmparser 0.210.0",
6349+
]
6350+
62736351
[[package]]
62746352
name = "wasmparser"
62756353
version = "0.118.2"
@@ -6280,6 +6358,42 @@ dependencies = [
62806358
"semver",
62816359
]
62826360

6361+
[[package]]
6362+
name = "wasmparser"
6363+
version = "0.210.0"
6364+
source = "registry+https://github.com/rust-lang/crates.io-index"
6365+
checksum = "a7bbcd21e7581619d9f6ca00f8c4f08f1cacfe58bf63f83af57cd0476f1026f5"
6366+
dependencies = [
6367+
"ahash",
6368+
"bitflags 2.5.0",
6369+
"hashbrown",
6370+
"indexmap",
6371+
"semver",
6372+
"serde",
6373+
]
6374+
6375+
[[package]]
6376+
name = "wast"
6377+
version = "211.0.1"
6378+
source = "registry+https://github.com/rust-lang/crates.io-index"
6379+
checksum = "b25506dd82d00da6b14a87436b3d52b1d264083fa79cdb72a0d1b04a8595ccaa"
6380+
dependencies = [
6381+
"bumpalo",
6382+
"leb128",
6383+
"memchr",
6384+
"unicode-width",
6385+
"wasm-encoder 0.211.1",
6386+
]
6387+
6388+
[[package]]
6389+
name = "wat"
6390+
version = "1.211.1"
6391+
source = "registry+https://github.com/rust-lang/crates.io-index"
6392+
checksum = "eb716ca6c86eecac2d82541ffc39860118fc0af9309c4f2670637bea2e1bdd7d"
6393+
dependencies = [
6394+
"wast",
6395+
]
6396+
62836397
[[package]]
62846398
name = "winapi"
62856399
version = "0.3.9"
@@ -6507,6 +6621,43 @@ dependencies = [
65076621
"memchr",
65086622
]
65096623

6624+
[[package]]
6625+
name = "wit-component"
6626+
version = "0.210.0"
6627+
source = "registry+https://github.com/rust-lang/crates.io-index"
6628+
checksum = "a450bdb5d032acf1fa0865451fa0c6f50e62f2d31eaa8dba967c2e2d068694a4"
6629+
dependencies = [
6630+
"anyhow",
6631+
"bitflags 2.5.0",
6632+
"indexmap",
6633+
"log",
6634+
"serde",
6635+
"serde_derive",
6636+
"serde_json",
6637+
"wasm-encoder 0.210.0",
6638+
"wasm-metadata",
6639+
"wasmparser 0.210.0",
6640+
"wit-parser",
6641+
]
6642+
6643+
[[package]]
6644+
name = "wit-parser"
6645+
version = "0.210.0"
6646+
source = "registry+https://github.com/rust-lang/crates.io-index"
6647+
checksum = "60a965cbd439af19a4b44a54a97ab8957d86f02d01320efc9e31c1d3605c6710"
6648+
dependencies = [
6649+
"anyhow",
6650+
"id-arena",
6651+
"indexmap",
6652+
"log",
6653+
"semver",
6654+
"serde",
6655+
"serde_derive",
6656+
"serde_json",
6657+
"unicode-xid",
6658+
"wasmparser 0.210.0",
6659+
]
6660+
65106661
[[package]]
65116662
name = "writeable"
65126663
version = "0.5.5"

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ members = [
4444
"src/tools/rustdoc-gui-test",
4545
"src/tools/opt-dist",
4646
"src/tools/coverage-dump",
47+
"src/tools/wasm-component-ld",
4748
]
4849

4950
exclude = [
@@ -103,6 +104,9 @@ rustc-demangle.debug = 0
103104
[profile.release.package.lld-wrapper]
104105
debug = 0
105106
strip = true
107+
[profile.release.package.wasm-component-ld-wrapper]
108+
debug = 0
109+
strip = true
106110

107111
[patch.crates-io]
108112
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on

src/bootstrap/src/core/build_steps/compile.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,21 @@ impl Step for Assemble {
18261826
&self_contained_lld_dir.join(exe(name, target_compiler.host)),
18271827
);
18281828
}
1829+
1830+
// In addition to `rust-lld` also install `wasm-component-ld` when
1831+
// LLD is enabled. This is a relatively small binary that primarily
1832+
// delegates to the `rust-lld` binary for linking and then runs
1833+
// logic to create the final binary. This is used by the
1834+
// `wasm32-wasip2` target of Rust.
1835+
let wasm_component_ld_exe =
1836+
builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
1837+
compiler: build_compiler,
1838+
target: target_compiler.host,
1839+
});
1840+
builder.copy_link(
1841+
&wasm_component_ld_exe,
1842+
&libdir_bin.join(wasm_component_ld_exe.file_name().unwrap()),
1843+
);
18291844
}
18301845

18311846
if builder.config.llvm_enabled(target_compiler.host) {

src/bootstrap/src/core/build_steps/tool.rs

+28
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,34 @@ impl Step for LldWrapper {
696696
}
697697
}
698698

699+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
700+
pub struct WasmComponentLd {
701+
pub compiler: Compiler,
702+
pub target: TargetSelection,
703+
}
704+
705+
impl Step for WasmComponentLd {
706+
type Output = PathBuf;
707+
708+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
709+
run.never()
710+
}
711+
712+
fn run(self, builder: &Builder<'_>) -> PathBuf {
713+
builder.ensure(ToolBuild {
714+
compiler: self.compiler,
715+
target: self.target,
716+
tool: "wasm-component-ld",
717+
mode: Mode::ToolStd,
718+
path: "src/tools/wasm-component-ld",
719+
source_type: SourceType::InTree,
720+
extra_features: Vec::new(),
721+
allow_features: "",
722+
cargo_args: Vec::new(),
723+
})
724+
}
725+
}
726+
699727
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
700728
pub struct RustAnalyzer {
701729
pub compiler: Compiler,

src/ci/docker/host-x86_64/dist-various-2/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ ENV TARGETS=$TARGETS,wasm32-unknown-unknown
112112
ENV TARGETS=$TARGETS,wasm32-wasi
113113
ENV TARGETS=$TARGETS,wasm32-wasip1
114114
ENV TARGETS=$TARGETS,wasm32-wasip1-threads
115+
ENV TARGETS=$TARGETS,wasm32-wasip2
115116
ENV TARGETS=$TARGETS,sparcv9-sun-solaris
116117
ENV TARGETS=$TARGETS,x86_64-pc-solaris
117118
ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32

src/tools/tidy/src/deps.rs

+5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ const EXCEPTIONS: ExceptionList = &[
9595
("self_cell", "Apache-2.0"), // rustc (fluent translations)
9696
("snap", "BSD-3-Clause"), // rustc
9797
("wasm-encoder", "Apache-2.0 WITH LLVM-exception"), // rustc
98+
("wasm-metadata", "Apache-2.0 WITH LLVM-exception"), // rustc
9899
("wasmparser", "Apache-2.0 WITH LLVM-exception"), // rustc
100+
("wast", "Apache-2.0 WITH LLVM-exception"), // rustc
101+
("wat", "Apache-2.0 WITH LLVM-exception"), // rustc
102+
("wit-component", "Apache-2.0 WITH LLVM-exception"), // rustc
103+
("wit-parser", "Apache-2.0 WITH LLVM-exception"), // rustc
99104
// tidy-alphabetical-end
100105
];
101106

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See the `README.md` in this directory for what this tool is.
2+
3+
[package]
4+
name = "wasm-component-ld-wrapper"
5+
version = "0.1.0"
6+
edition = "2021"
7+
8+
[[bin]]
9+
name = "wasm-component-ld"
10+
path = "src/main.rs"
11+
12+
[dependencies]
13+
wasm-component-ld = "0.5.4"

0 commit comments

Comments
 (0)