Skip to content

Commit

Permalink
Auto merge of rust-lang#132070 - fmease:rollup-4i4k587, r=fmease
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 23, 2024
2 parents be01dab + 5f0626c commit 4f2f477
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 115 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ supported_targets! {

("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
("wasm32-unknown-unknown", wasm32_unknown_unknown),
("wasm32v1-none", wasm32v1_none),
("wasm32-wasi", wasm32_wasi),
("wasm32-wasip1", wasm32_wasip1),
("wasm32-wasip2", wasm32_wasip2),
Expand Down
51 changes: 51 additions & 0 deletions compiler/rustc_target/src/spec/targets/wasm32v1_none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! A "bare wasm" target representing a WebAssembly output that does not import
//! anything from its environment and also specifies an _upper_ bound on the set
//! of WebAssembly proposals that are supported.
//!
//! It's equivalent to the `wasm32-unknown-unknown` target with the additional
//! flags `-Ctarget-cpu=mvp` and `-Ctarget-feature=+mutable-globals`. This
//! enables just the features specified in <https://www.w3.org/TR/wasm-core-1/>
//!
//! This is a _separate target_ because using `wasm32-unknown-unknown` with
//! those target flags doesn't automatically rebuild libcore / liballoc with
//! them, and in order to get those libraries rebuilt you need to use the
//! nightly Rust feature `-Zbuild-std`. This target is for people who want to
//! use stable Rust, and target a stable set pf WebAssembly features.

use crate::spec::{Cc, LinkerFlavor, Target, base};

pub(crate) fn target() -> Target {
let mut options = base::wasm::options();
options.os = "none".into();

// WebAssembly 1.0 shipped in 2019 and included exactly one proposal
// after the initial "MVP" feature set: "mutable-globals".
options.cpu = "mvp".into();
options.features = "+mutable-globals".into();

options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::No), &[
// For now this target just never has an entry symbol no matter the output
// type, so unconditionally pass this.
"--no-entry",
]);
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &[
// Make sure clang uses LLD as its linker and is configured appropriately
// otherwise
"--target=wasm32-unknown-unknown",
"-Wl,--no-entry",
]);

Target {
llvm_target: "wasm32-unknown-unknown".into(),
metadata: crate::spec::TargetMetadata {
description: Some("WebAssembly".into()),
tier: Some(2),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(),
arch: "wasm32".into(),
options,
}
}
8 changes: 7 additions & 1 deletion compiler/rustc_target/src/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ impl Target {
// Check dynamic linking stuff
// BPF: when targeting user space vms (like rbpf), those can load dynamic libraries.
// hexagon: when targeting QuRT, that OS can load dynamic libraries.
if self.os == "none" && (self.arch != "bpf" && self.arch != "hexagon") {
// wasm{32,64}: dynamic linking is inherent in the definition of the VM.
if self.os == "none"
&& (self.arch != "bpf"
&& self.arch != "hexagon"
&& self.arch != "wasm32"
&& self.arch != "wasm64")
{
assert!(!self.dynamic_linking);
}
if self.only_cdylib
Expand Down
3 changes: 3 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@
# passed to cargo invocations.
#jobs = 0

# What custom diff tool to use for displaying compiletest tests.
#compiletest-diff-tool = <none>

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,6 @@ def check_vendored_status(self):
if not os.path.exists(cargo_dir):
eprint('ERROR: vendoring required, but .cargo/config does not exist.')
raise Exception("{} not found".format(cargo_dir))
else:
if os.path.exists(cargo_dir):
shutil.rmtree(cargo_dir)

def parse_args(args):
"""Parse the command line arguments that the python script needs."""
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
if builder.config.cmd.only_modified() {
cmd.arg("--only-modified");
}
if let Some(compiletest_diff_tool) = &builder.config.compiletest_diff_tool {
cmd.arg("--compiletest-diff-tool").arg(compiletest_diff_tool);
}

let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
Expand Down
31 changes: 6 additions & 25 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::path::PathBuf;
use std::{env, fs};

use build_helper::git::get_closest_merge_commit;

use crate::core::build_steps::compile;
use crate::core::build_steps::toolstate::ToolState;
use crate::core::builder;
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::channel::GitInfo;
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{add_dylib_path, exe, git, t};
use crate::utils::helpers::{add_dylib_path, exe, t};
use crate::{Compiler, Kind, Mode, gha};

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -596,28 +594,11 @@ impl Step for Rustdoc {
&& target_compiler.stage > 0
&& builder.rust_info().is_managed_git_subrepository()
{
let commit = get_closest_merge_commit(
Some(&builder.config.src),
&builder.config.git_config(),
&[],
)
.unwrap();

let librustdoc_src = builder.config.src.join("src/librustdoc");
let rustdoc_src = builder.config.src.join("src/tools/rustdoc");

// FIXME: The change detection logic here is quite similar to `Config::download_ci_rustc_commit`.
// It would be better to unify them.
let has_changes = !git(Some(&builder.config.src))
.allow_failure()
.run_always()
.args(["diff-index", "--quiet", &commit])
.arg("--")
.arg(librustdoc_src)
.arg(rustdoc_src)
.run(builder);

if !has_changes {
let files_to_track = &["src/librustdoc", "src/tools/rustdoc"];

// Check if unchanged
if builder.config.last_modified_commit(files_to_track, "download-rustc", true).is_some()
{
let precompiled_rustdoc = builder
.config
.ci_rustc_dir()
Expand Down
64 changes: 23 additions & 41 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ pub struct Config {
/// The paths to work with. For example: with `./x check foo bar` we get
/// `paths=["foo", "bar"]`.
pub paths: Vec<PathBuf>,

/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub compiletest_diff_tool: Option<String>,
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -892,6 +895,7 @@ define_config! {
android_ndk: Option<PathBuf> = "android-ndk",
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jobs: Option<u32> = "jobs",
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
}
}

Expand Down Expand Up @@ -1512,6 +1516,7 @@ impl Config {
android_ndk,
optimized_compiler_builtins,
jobs,
compiletest_diff_tool,
} = toml.build.unwrap_or_default();

config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0))));
Expand Down Expand Up @@ -2158,6 +2163,7 @@ impl Config {
config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(DebuginfoLevel::None);
config.optimized_compiler_builtins =
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
config.compiletest_diff_tool = compiletest_diff_tool;

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

let files_to_track = &[
self.src.join("compiler"),
self.src.join("library"),
self.src.join("src/version"),
self.src.join("src/stage0"),
self.src.join("src/ci/channel"),
];
let files_to_track =
&["compiler", "library", "src/version", "src/stage0", "src/ci/channel"];

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

if CiEnv::is_ci() && {
let head_sha =
Expand All @@ -2787,31 +2793,7 @@ impl Config {
return None;
}

// Warn if there were changes to the compiler or standard library since the ancestor commit.
let has_changes = !t!(helpers::git(Some(&self.src))
.args(["diff-index", "--quiet", &commit])
.arg("--")
.args(files_to_track)
.as_command_mut()
.status())
.success();
if has_changes {
if if_unchanged {
if self.is_verbose() {
println!(
"WARNING: saw changes to compiler/ or library/ since {commit}; \
ignoring `download-rustc`"
);
}
return None;
}
println!(
"WARNING: `download-rustc` is enabled, but there are changes to \
compiler/ or library/"
);
}

Some(commit.to_string())
Some(commit)
}

fn parse_download_ci_llvm(
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "Allow setting `--jobs` in config.toml with `build.jobs`.",
},
ChangeInfo {
change_id: 131181,
severity: ChangeSeverity::Info,
summary: "New option `build.compiletest-diff-tool` that adds support for a custom differ for compiletest",
},
];
1 change: 1 addition & 0 deletions src/ci/docker/host-x86_64/dist-various-2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ENV TARGETS=$TARGETS,wasm32-wasi
ENV TARGETS=$TARGETS,wasm32-wasip1
ENV TARGETS=$TARGETS,wasm32-wasip1-threads
ENV TARGETS=$TARGETS,wasm32-wasip2
ENV TARGETS=$TARGETS,wasm32v1-none
ENV TARGETS=$TARGETS,sparcv9-sun-solaris
ENV TARGETS=$TARGETS,x86_64-pc-solaris
ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/scripts/rfl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

LINUX_VERSION=v6.12-rc2
LINUX_VERSION=28e848386b92645f93b9f2fdba5882c3ca7fb3e2

# Build rustc, rustdoc, cargo, clippy-driver and rustfmt
../x.py build --stage 2 library rustdoc clippy rustfmt
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
- [wasm32-wasip2](platform-support/wasm32-wasip2.md)
- [wasm32-unknown-emscripten](platform-support/wasm32-unknown-emscripten.md)
- [wasm32-unknown-unknown](platform-support/wasm32-unknown-unknown.md)
- [wasm32v1-none](platform-support/wasm32v1-none.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
- [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md)
- [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ target | std | notes
`wasm32-wasi` | ✓ | WebAssembly with WASI (undergoing a [rename to `wasm32-wasip1`][wasi-rename])
[`wasm32-wasip1`](platform-support/wasm32-wasip1.md) | ✓ | WebAssembly with WASI
[`wasm32-wasip1-threads`](platform-support/wasm32-wasip1-threads.md) | ✓ | WebAssembly with WASI Preview 1 and threads
[`wasm32v1-none`](platform-support/wasm32v1-none.md) | * | WebAssembly limited to 1.0 features and no imports
[`x86_64-apple-ios`](platform-support/apple-ios.md) | ✓ | 64-bit x86 iOS
[`x86_64-apple-ios-macabi`](platform-support/apple-ios-macabi.md) | ✓ | Mac Catalyst on x86_64
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
Expand Down
24 changes: 17 additions & 7 deletions src/doc/rustc/src/platform-support/wasm32-unknown-unknown.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,20 @@ As of the time of this writing the proposals that are enabled by default (the

If you're compiling WebAssembly code for an engine that does not support a
feature in LLVM's default feature set then the feature must be disabled at
compile time. Note, though, that enabled features may be used in the standard
library or precompiled libraries shipped via rustup. This means that not only
does your own code need to be compiled with the correct set of flags but the
Rust standard library additionally must be recompiled.
compile time. There are two approaches to choose from:

- If you are targeting a feature set no smaller than the W3C WebAssembly Core
1.0 recommendation -- which is equivalent to the WebAssembly MVP plus the
`mutable-globals` feature -- and you are building `no_std`, then you can
simply use the [`wasm32v1-none` target](./wasm32v1-none.md) instead of
`wasm32-unknown-unknown`, which uses only those minimal features and
includes a core and alloc library built with only those minimal features.

- Otherwise -- if you need std, or if you need to target the ultra-minimal
"MVP" feature set, excluding `mutable-globals` -- you will need to manually
specify `-Ctarget-cpu=mvp` and also rebuild the stdlib using that target to
ensure no features are used in the stdlib. This in turn requires use of a
nightly compiler.

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

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

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

```sh
$ rustc -Ctarget-feature=help --target wasm32-unknown-unknown
Expand Down
Loading

0 comments on commit 4f2f477

Please sign in to comment.