Skip to content

Commit 4f2f477

Browse files
committed
Auto merge of rust-lang#132070 - fmease:rollup-4i4k587, r=fmease
Rollup of 5 pull requests Successful merges: - rust-lang#131043 (Refactor change detection for rustdoc and download-rustc) - rust-lang#131181 (Compiletest: Custom differ) - rust-lang#131487 (Add wasm32v1-none target (compiler-team/rust-lang#791)) - rust-lang#132054 (do not remove `.cargo` directory) - rust-lang#132058 (CI: rfl: use rust-next temporary commit) r? `@ghost` `@rustbot` modify labels: rollup
2 parents be01dab + 5f0626c commit 4f2f477

File tree

20 files changed

+290
-115
lines changed

20 files changed

+290
-115
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,51 @@
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+
15+
use crate::spec::{Cc, LinkerFlavor, Target, base};
16+
17+
pub(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(LinkerFlavor::WasmLld(Cc::No), &[
27+
// For now this target just never has an entry symbol no matter the output
28+
// type, so unconditionally pass this.
29+
"--no-entry",
30+
]);
31+
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &[
32+
// Make sure clang uses LLD as its linker and is configured appropriately
33+
// otherwise
34+
"--target=wasm32-unknown-unknown",
35+
"-Wl,--no-entry",
36+
]);
37+
38+
Target {
39+
llvm_target: "wasm32-unknown-unknown".into(),
40+
metadata: crate::spec::TargetMetadata {
41+
description: Some("WebAssembly".into()),
42+
tier: Some(2),
43+
host_tools: Some(false),
44+
std: Some(false),
45+
},
46+
pointer_width: 32,
47+
data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(),
48+
arch: "wasm32".into(),
49+
options,
50+
}
51+
}

compiler/rustc_target/src/spec/tests/tests_impl.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ impl Target {
121121
// Check dynamic linking stuff
122122
// BPF: when targeting user space vms (like rbpf), those can load dynamic libraries.
123123
// hexagon: when targeting QuRT, that OS can load dynamic libraries.
124-
if self.os == "none" && (self.arch != "bpf" && self.arch != "hexagon") {
124+
// wasm{32,64}: dynamic linking is inherent in the definition of the VM.
125+
if self.os == "none"
126+
&& (self.arch != "bpf"
127+
&& self.arch != "hexagon"
128+
&& self.arch != "wasm32"
129+
&& self.arch != "wasm64")
130+
{
125131
assert!(!self.dynamic_linking);
126132
}
127133
if self.only_cdylib

config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@
419419
# passed to cargo invocations.
420420
#jobs = 0
421421

422+
# What custom diff tool to use for displaying compiletest tests.
423+
#compiletest-diff-tool = <none>
424+
422425
# =============================================================================
423426
# General install configuration options
424427
# =============================================================================

src/bootstrap/bootstrap.py

-3
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,6 @@ def check_vendored_status(self):
10921092
if not os.path.exists(cargo_dir):
10931093
eprint('ERROR: vendoring required, but .cargo/config does not exist.')
10941094
raise Exception("{} not found".format(cargo_dir))
1095-
else:
1096-
if os.path.exists(cargo_dir):
1097-
shutil.rmtree(cargo_dir)
10981095

10991096
def parse_args(args):
11001097
"""Parse the command line arguments that the python script needs."""

src/bootstrap/src/core/build_steps/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18361836
if builder.config.cmd.only_modified() {
18371837
cmd.arg("--only-modified");
18381838
}
1839+
if let Some(compiletest_diff_tool) = &builder.config.compiletest_diff_tool {
1840+
cmd.arg("--compiletest-diff-tool").arg(compiletest_diff_tool);
1841+
}
18391842

18401843
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
18411844
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));

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

+6-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use std::path::PathBuf;
22
use std::{env, fs};
33

4-
use build_helper::git::get_closest_merge_commit;
5-
64
use crate::core::build_steps::compile;
75
use crate::core::build_steps::toolstate::ToolState;
86
use crate::core::builder;
97
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
108
use crate::core::config::TargetSelection;
119
use crate::utils::channel::GitInfo;
1210
use crate::utils::exec::{BootstrapCommand, command};
13-
use crate::utils::helpers::{add_dylib_path, exe, git, t};
11+
use crate::utils::helpers::{add_dylib_path, exe, t};
1412
use crate::{Compiler, Kind, Mode, gha};
1513

1614
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -596,28 +594,11 @@ impl Step for Rustdoc {
596594
&& target_compiler.stage > 0
597595
&& builder.rust_info().is_managed_git_subrepository()
598596
{
599-
let commit = get_closest_merge_commit(
600-
Some(&builder.config.src),
601-
&builder.config.git_config(),
602-
&[],
603-
)
604-
.unwrap();
605-
606-
let librustdoc_src = builder.config.src.join("src/librustdoc");
607-
let rustdoc_src = builder.config.src.join("src/tools/rustdoc");
608-
609-
// FIXME: The change detection logic here is quite similar to `Config::download_ci_rustc_commit`.
610-
// It would be better to unify them.
611-
let has_changes = !git(Some(&builder.config.src))
612-
.allow_failure()
613-
.run_always()
614-
.args(["diff-index", "--quiet", &commit])
615-
.arg("--")
616-
.arg(librustdoc_src)
617-
.arg(rustdoc_src)
618-
.run(builder);
619-
620-
if !has_changes {
597+
let files_to_track = &["src/librustdoc", "src/tools/rustdoc"];
598+
599+
// Check if unchanged
600+
if builder.config.last_modified_commit(files_to_track, "download-rustc", true).is_some()
601+
{
621602
let precompiled_rustdoc = builder
622603
.config
623604
.ci_rustc_dir()

src/bootstrap/src/core/config/config.rs

+23-41
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ pub struct Config {
368368
/// The paths to work with. For example: with `./x check foo bar` we get
369369
/// `paths=["foo", "bar"]`.
370370
pub paths: Vec<PathBuf>,
371+
372+
/// Command for visual diff display, e.g. `diff-tool --color=always`.
373+
pub compiletest_diff_tool: Option<String>,
371374
}
372375

373376
#[derive(Clone, Debug, Default)]
@@ -892,6 +895,7 @@ define_config! {
892895
android_ndk: Option<PathBuf> = "android-ndk",
893896
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
894897
jobs: Option<u32> = "jobs",
898+
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
895899
}
896900
}
897901

@@ -1512,6 +1516,7 @@ impl Config {
15121516
android_ndk,
15131517
optimized_compiler_builtins,
15141518
jobs,
1519+
compiletest_diff_tool,
15151520
} = toml.build.unwrap_or_default();
15161521

15171522
config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0))));
@@ -2158,6 +2163,7 @@ impl Config {
21582163
config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(DebuginfoLevel::None);
21592164
config.optimized_compiler_builtins =
21602165
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
2166+
config.compiletest_diff_tool = compiletest_diff_tool;
21612167

21622168
let download_rustc = config.download_rustc_commit.is_some();
21632169
// See https://github.com/rust-lang/compiler-team/issues/326
@@ -2754,25 +2760,25 @@ impl Config {
27542760
}
27552761
};
27562762

2757-
let files_to_track = &[
2758-
self.src.join("compiler"),
2759-
self.src.join("library"),
2760-
self.src.join("src/version"),
2761-
self.src.join("src/stage0"),
2762-
self.src.join("src/ci/channel"),
2763-
];
2763+
let files_to_track =
2764+
&["compiler", "library", "src/version", "src/stage0", "src/ci/channel"];
27642765

27652766
// Look for a version to compare to based on the current commit.
27662767
// Only commits merged by bors will have CI artifacts.
2767-
let commit =
2768-
get_closest_merge_commit(Some(&self.src), &self.git_config(), files_to_track).unwrap();
2769-
if commit.is_empty() {
2770-
println!("ERROR: could not find commit hash for downloading rustc");
2771-
println!("HELP: maybe your repository history is too shallow?");
2772-
println!("HELP: consider disabling `download-rustc`");
2773-
println!("HELP: or fetch enough history to include one upstream commit");
2774-
crate::exit!(1);
2775-
}
2768+
let commit = match self.last_modified_commit(files_to_track, "download-rustc", if_unchanged)
2769+
{
2770+
Some(commit) => commit,
2771+
None => {
2772+
if if_unchanged {
2773+
return None;
2774+
}
2775+
println!("ERROR: could not find commit hash for downloading rustc");
2776+
println!("HELP: maybe your repository history is too shallow?");
2777+
println!("HELP: consider disabling `download-rustc`");
2778+
println!("HELP: or fetch enough history to include one upstream commit");
2779+
crate::exit!(1);
2780+
}
2781+
};
27762782

27772783
if CiEnv::is_ci() && {
27782784
let head_sha =
@@ -2787,31 +2793,7 @@ impl Config {
27872793
return None;
27882794
}
27892795

2790-
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2791-
let has_changes = !t!(helpers::git(Some(&self.src))
2792-
.args(["diff-index", "--quiet", &commit])
2793-
.arg("--")
2794-
.args(files_to_track)
2795-
.as_command_mut()
2796-
.status())
2797-
.success();
2798-
if has_changes {
2799-
if if_unchanged {
2800-
if self.is_verbose() {
2801-
println!(
2802-
"WARNING: saw changes to compiler/ or library/ since {commit}; \
2803-
ignoring `download-rustc`"
2804-
);
2805-
}
2806-
return None;
2807-
}
2808-
println!(
2809-
"WARNING: `download-rustc` is enabled, but there are changes to \
2810-
compiler/ or library/"
2811-
);
2812-
}
2813-
2814-
Some(commit.to_string())
2796+
Some(commit)
28152797
}
28162798

28172799
fn parse_download_ci_llvm(

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
280280
severity: ChangeSeverity::Info,
281281
summary: "Allow setting `--jobs` in config.toml with `build.jobs`.",
282282
},
283+
ChangeInfo {
284+
change_id: 131181,
285+
severity: ChangeSeverity::Info,
286+
summary: "New option `build.compiletest-diff-tool` that adds support for a custom differ for compiletest",
287+
},
283288
];

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

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ ENV TARGETS=$TARGETS,wasm32-wasi
118118
ENV TARGETS=$TARGETS,wasm32-wasip1
119119
ENV TARGETS=$TARGETS,wasm32-wasip1-threads
120120
ENV TARGETS=$TARGETS,wasm32-wasip2
121+
ENV TARGETS=$TARGETS,wasm32v1-none
121122
ENV TARGETS=$TARGETS,sparcv9-sun-solaris
122123
ENV TARGETS=$TARGETS,x86_64-pc-solaris
123124
ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32

src/ci/docker/scripts/rfl-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
LINUX_VERSION=v6.12-rc2
5+
LINUX_VERSION=28e848386b92645f93b9f2fdba5882c3ca7fb3e2
66

77
# Build rustc, rustdoc, cargo, clippy-driver and rustfmt
88
../x.py build --stage 2 library rustdoc clippy rustfmt

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- [wasm32-wasip2](platform-support/wasm32-wasip2.md)
8787
- [wasm32-unknown-emscripten](platform-support/wasm32-unknown-emscripten.md)
8888
- [wasm32-unknown-unknown](platform-support/wasm32-unknown-unknown.md)
89+
- [wasm32v1-none](platform-support/wasm32v1-none.md)
8990
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
9091
- [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md)
9192
- [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ target | std | notes
195195
`wasm32-wasi` | ✓ | WebAssembly with WASI (undergoing a [rename to `wasm32-wasip1`][wasi-rename])
196196
[`wasm32-wasip1`](platform-support/wasm32-wasip1.md) | ✓ | WebAssembly with WASI
197197
[`wasm32-wasip1-threads`](platform-support/wasm32-wasip1-threads.md) | ✓ | WebAssembly with WASI Preview 1 and threads
198+
[`wasm32v1-none`](platform-support/wasm32v1-none.md) | * | WebAssembly limited to 1.0 features and no imports
198199
[`x86_64-apple-ios`](platform-support/apple-ios.md) | ✓ | 64-bit x86 iOS
199200
[`x86_64-apple-ios-macabi`](platform-support/apple-ios-macabi.md) | ✓ | Mac Catalyst on x86_64
200201
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX

src/doc/rustc/src/platform-support/wasm32-unknown-unknown.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,20 @@ As of the time of this writing the proposals that are enabled by default (the
132132

133133
If you're compiling WebAssembly code for an engine that does not support a
134134
feature in LLVM's default feature set then the feature must be disabled at
135-
compile time. Note, though, that enabled features may be used in the standard
136-
library or precompiled libraries shipped via rustup. This means that not only
137-
does your own code need to be compiled with the correct set of flags but the
138-
Rust standard library additionally must be recompiled.
135+
compile time. There are two approaches to choose from:
136+
137+
- If you are targeting a feature set no smaller than the W3C WebAssembly Core
138+
1.0 recommendation -- which is equivalent to the WebAssembly MVP plus the
139+
`mutable-globals` feature -- and you are building `no_std`, then you can
140+
simply use the [`wasm32v1-none` target](./wasm32v1-none.md) instead of
141+
`wasm32-unknown-unknown`, which uses only those minimal features and
142+
includes a core and alloc library built with only those minimal features.
143+
144+
- Otherwise -- if you need std, or if you need to target the ultra-minimal
145+
"MVP" feature set, excluding `mutable-globals` -- you will need to manually
146+
specify `-Ctarget-cpu=mvp` and also rebuild the stdlib using that target to
147+
ensure no features are used in the stdlib. This in turn requires use of a
148+
nightly compiler.
139149

140150
Compiling all code for the initial release of WebAssembly looks like:
141151

@@ -150,9 +160,9 @@ then used to recompile the standard library in addition to your own code. This
150160
will produce a binary that uses only the original WebAssembly features by
151161
default and no proposals since its inception.
152162

153-
To enable individual features it can be done with `-Ctarget-feature=+foo`.
154-
Available features for Rust code itself are documented in the [reference] and
155-
can also be found through:
163+
To enable individual features on either this target or `wasm32v1-none`, pass
164+
arguments of the form `-Ctarget-feature=+foo`. Available features for Rust code
165+
itself are documented in the [reference] and can also be found through:
156166

157167
```sh
158168
$ rustc -Ctarget-feature=help --target wasm32-unknown-unknown

0 commit comments

Comments
 (0)