Skip to content

Commit 2a3e22b

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 9dcaa7f commit 2a3e22b

File tree

9 files changed

+291
-3
lines changed

9 files changed

+291
-3
lines changed

Diff for: Cargo.lock

+154-3
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ dependencies = [
16711671
"compiler_builtins",
16721672
"rustc-std-workspace-alloc",
16731673
"rustc-std-workspace-core",
1674+
"serde",
16741675
]
16751676

16761677
[[package]]
@@ -1880,6 +1881,12 @@ dependencies = [
18801881
"syn 2.0.67",
18811882
]
18821883

1884+
[[package]]
1885+
name = "id-arena"
1886+
version = "2.2.1"
1887+
source = "registry+https://github.com/rust-lang/crates.io-index"
1888+
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
1889+
18831890
[[package]]
18841891
name = "ident_case"
18851892
version = "1.0.1"
@@ -2109,6 +2116,12 @@ version = "1.0.5"
21092116
source = "registry+https://github.com/rust-lang/crates.io-index"
21102117
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21112118

2119+
[[package]]
2120+
name = "lexopt"
2121+
version = "0.3.0"
2122+
source = "registry+https://github.com/rust-lang/crates.io-index"
2123+
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
2124+
21122125
[[package]]
21132126
name = "libc"
21142127
version = "0.2.155"
@@ -2623,7 +2636,7 @@ dependencies = [
26232636
"indexmap",
26242637
"memchr",
26252638
"ruzstd 0.5.0",
2626-
"wasmparser",
2639+
"wasmparser 0.118.2",
26272640
]
26282641

26292642
[[package]]
@@ -3424,7 +3437,7 @@ dependencies = [
34243437
"object 0.34.0",
34253438
"regex",
34263439
"similar",
3427-
"wasmparser",
3440+
"wasmparser 0.118.2",
34283441
]
34293442

34303443
[[package]]
@@ -3805,7 +3818,7 @@ dependencies = [
38053818
"thin-vec",
38063819
"thorin-dwp",
38073820
"tracing",
3808-
"wasm-encoder",
3821+
"wasm-encoder 0.200.0",
38093822
"windows",
38103823
]
38113824

@@ -5248,6 +5261,15 @@ dependencies = [
52485261
"color-eyre",
52495262
]
52505263

5264+
[[package]]
5265+
name = "spdx"
5266+
version = "0.10.6"
5267+
source = "registry+https://github.com/rust-lang/crates.io-index"
5268+
checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc"
5269+
dependencies = [
5270+
"smallvec",
5271+
]
5272+
52515273
[[package]]
52525274
name = "spdx-expression"
52535275
version = "0.5.2"
@@ -6296,6 +6318,28 @@ version = "0.2.92"
62966318
source = "registry+https://github.com/rust-lang/crates.io-index"
62976319
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
62986320

6321+
[[package]]
6322+
name = "wasm-component-ld"
6323+
version = "0.5.4"
6324+
source = "registry+https://github.com/rust-lang/crates.io-index"
6325+
checksum = "314d932d5e84c9678751b85498b1482b2f32f185744e449d3ce0b1d400376dad"
6326+
dependencies = [
6327+
"anyhow",
6328+
"clap",
6329+
"lexopt",
6330+
"tempfile",
6331+
"wasmparser 0.210.0",
6332+
"wat",
6333+
"wit-component",
6334+
]
6335+
6336+
[[package]]
6337+
name = "wasm-component-ld-wrapper"
6338+
version = "0.1.0"
6339+
dependencies = [
6340+
"wasm-component-ld",
6341+
]
6342+
62996343
[[package]]
63006344
name = "wasm-encoder"
63016345
version = "0.200.0"
@@ -6305,6 +6349,40 @@ dependencies = [
63056349
"leb128",
63066350
]
63076351

6352+
[[package]]
6353+
name = "wasm-encoder"
6354+
version = "0.210.0"
6355+
source = "registry+https://github.com/rust-lang/crates.io-index"
6356+
checksum = "e7e3764d9d6edabd8c9e16195e177be0d20f6ab942ad18af52860f12f82bc59a"
6357+
dependencies = [
6358+
"leb128",
6359+
]
6360+
6361+
[[package]]
6362+
name = "wasm-encoder"
6363+
version = "0.211.1"
6364+
source = "registry+https://github.com/rust-lang/crates.io-index"
6365+
checksum = "5e7d931a1120ef357f32b74547646b6fa68ea25e377772b72874b131a9ed70d4"
6366+
dependencies = [
6367+
"leb128",
6368+
]
6369+
6370+
[[package]]
6371+
name = "wasm-metadata"
6372+
version = "0.210.0"
6373+
source = "registry+https://github.com/rust-lang/crates.io-index"
6374+
checksum = "012729d1294907fcb0866f08460ab95426a6d0b176a599619b84cac7653452b4"
6375+
dependencies = [
6376+
"anyhow",
6377+
"indexmap",
6378+
"serde",
6379+
"serde_derive",
6380+
"serde_json",
6381+
"spdx",
6382+
"wasm-encoder 0.210.0",
6383+
"wasmparser 0.210.0",
6384+
]
6385+
63086386
[[package]]
63096387
name = "wasmparser"
63106388
version = "0.118.2"
@@ -6315,6 +6393,42 @@ dependencies = [
63156393
"semver",
63166394
]
63176395

6396+
[[package]]
6397+
name = "wasmparser"
6398+
version = "0.210.0"
6399+
source = "registry+https://github.com/rust-lang/crates.io-index"
6400+
checksum = "a7bbcd21e7581619d9f6ca00f8c4f08f1cacfe58bf63f83af57cd0476f1026f5"
6401+
dependencies = [
6402+
"ahash",
6403+
"bitflags 2.5.0",
6404+
"hashbrown",
6405+
"indexmap",
6406+
"semver",
6407+
"serde",
6408+
]
6409+
6410+
[[package]]
6411+
name = "wast"
6412+
version = "211.0.1"
6413+
source = "registry+https://github.com/rust-lang/crates.io-index"
6414+
checksum = "b25506dd82d00da6b14a87436b3d52b1d264083fa79cdb72a0d1b04a8595ccaa"
6415+
dependencies = [
6416+
"bumpalo",
6417+
"leb128",
6418+
"memchr",
6419+
"unicode-width",
6420+
"wasm-encoder 0.211.1",
6421+
]
6422+
6423+
[[package]]
6424+
name = "wat"
6425+
version = "1.211.1"
6426+
source = "registry+https://github.com/rust-lang/crates.io-index"
6427+
checksum = "eb716ca6c86eecac2d82541ffc39860118fc0af9309c4f2670637bea2e1bdd7d"
6428+
dependencies = [
6429+
"wast",
6430+
]
6431+
63186432
[[package]]
63196433
name = "winapi"
63206434
version = "0.3.9"
@@ -6542,6 +6656,43 @@ dependencies = [
65426656
"memchr",
65436657
]
65446658

6659+
[[package]]
6660+
name = "wit-component"
6661+
version = "0.210.0"
6662+
source = "registry+https://github.com/rust-lang/crates.io-index"
6663+
checksum = "a450bdb5d032acf1fa0865451fa0c6f50e62f2d31eaa8dba967c2e2d068694a4"
6664+
dependencies = [
6665+
"anyhow",
6666+
"bitflags 2.5.0",
6667+
"indexmap",
6668+
"log",
6669+
"serde",
6670+
"serde_derive",
6671+
"serde_json",
6672+
"wasm-encoder 0.210.0",
6673+
"wasm-metadata",
6674+
"wasmparser 0.210.0",
6675+
"wit-parser",
6676+
]
6677+
6678+
[[package]]
6679+
name = "wit-parser"
6680+
version = "0.210.0"
6681+
source = "registry+https://github.com/rust-lang/crates.io-index"
6682+
checksum = "60a965cbd439af19a4b44a54a97ab8957d86f02d01320efc9e31c1d3605c6710"
6683+
dependencies = [
6684+
"anyhow",
6685+
"id-arena",
6686+
"indexmap",
6687+
"log",
6688+
"semver",
6689+
"serde",
6690+
"serde_derive",
6691+
"serde_json",
6692+
"unicode-xid",
6693+
"wasmparser 0.210.0",
6694+
]
6695+
65456696
[[package]]
65466697
name = "writeable"
65476698
version = "0.5.5"

Diff for: Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ members = [
4545
"src/tools/opt-dist",
4646
"src/tools/coverage-dump",
4747
"src/tools/rustc-perf-wrapper",
48+
"src/tools/wasm-component-ld",
4849
]
4950

5051
exclude = [
@@ -104,6 +105,9 @@ rustc-demangle.debug = 0
104105
[profile.release.package.lld-wrapper]
105106
debug = 0
106107
strip = true
108+
[profile.release.package.wasm-component-ld-wrapper]
109+
debug = 0
110+
strip = true
107111

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

Diff for: src/bootstrap/src/core/build_steps/compile.rs

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

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

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+28
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,34 @@ impl Step for LldWrapper {
701701
}
702702
}
703703

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

Diff for: 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

Diff for: 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

Diff for: src/tools/wasm-component-ld/Cargo.toml

+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)