Skip to content

Consider compiletest a staged ToolStd tool #144563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,17 @@
# passed to cargo invocations.
#build.jobs = 0

# Whether to force `compiletest` to be built and run against the stage 0
# toolchain (i.e. stage 0 compiler and library).
#
# Both `compiletest`-managed test suites and `compiletest`'s own unit tests are
# **not an explicitly supported configuration**, and almost certainly will incur
# test failures against the stage 0 compiler and library.
#build.compiletest-force-stage0 = false

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

# Whether to use the precompiled stage0 libtest with compiletest.
#build.compiletest-use-stage0-libtest = true

# Default value for the `--extra-checks` flag of tidy.
#
# See `./x test tidy --help` for details.
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap/defaults/bootstrap.dist.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ test-stage = 2
doc-stage = 2
# When compiling from source, you usually want all tools.
extended = true
# Use libtest built from the source tree instead of the precompiled one from stage 0.
compiletest-use-stage0-libtest = false

# Most users installing from source want to build all parts of the project from source.
[llvm]
Expand Down
44 changes: 19 additions & 25 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ macro_rules! tool_check_step {
// The part of this path after the final '/' is also used as a display name.
path: $path:literal
$(, alt_path: $alt_path:literal )*
// Closure that returns `Mode` based on the passed `&Builder<'_>`
// Under which tool mode should the tool be checked with?
, mode: $mode:expr
// Subset of nightly features that are allowed to be used when checking
$(, allow_features: $allow_features:expr )?
Expand Down Expand Up @@ -404,8 +404,7 @@ macro_rules! tool_check_step {

fn make_run(run: RunConfig<'_>) {
let target = run.target;
let builder = run.builder;
let mode = $mode(builder);
let mode = $mode;

let build_compiler = prepare_compiler_for_check(run.builder, target, mode);

Expand All @@ -426,7 +425,7 @@ macro_rules! tool_check_step {
_value
};
let extra_features: &[&str] = &[$($($enable_features),*)?];
let mode = $mode(builder);
let mode = $mode;
run_tool_check_step(builder, build_compiler, target, $path, mode, allow_features, extra_features);
}

Expand Down Expand Up @@ -493,66 +492,61 @@ fn run_tool_check_step(
tool_check_step!(Rustdoc {
path: "src/tools/rustdoc",
alt_path: "src/librustdoc",
mode: |_builder| Mode::ToolRustc
mode: Mode::ToolRustc
});
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
// of a submodule. Since the SourceType only drives the deny-warnings
// behavior, treat it as in-tree so that any new warnings in clippy will be
// rejected.
tool_check_step!(Clippy { path: "src/tools/clippy", mode: |_builder| Mode::ToolRustc });
tool_check_step!(Miri { path: "src/tools/miri", mode: |_builder| Mode::ToolRustc });
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: |_builder| Mode::ToolRustc });
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: |_builder| Mode::ToolRustc });
tool_check_step!(Clippy { path: "src/tools/clippy", mode: Mode::ToolRustc });
tool_check_step!(Miri { path: "src/tools/miri", mode: Mode::ToolRustc });
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: Mode::ToolRustc });
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: Mode::ToolRustc });
tool_check_step!(RustAnalyzer {
path: "src/tools/rust-analyzer",
mode: |_builder| Mode::ToolRustc,
mode: Mode::ToolRustc,
allow_features: tool::RustAnalyzer::ALLOW_FEATURES,
enable_features: ["in-rust-tree"],
});
tool_check_step!(MiroptTestTools {
path: "src/tools/miropt-test-tools",
mode: |_builder| Mode::ToolBootstrap
mode: Mode::ToolBootstrap
});
// We want to test the local std
tool_check_step!(TestFloatParse {
path: "src/tools/test-float-parse",
mode: |_builder| Mode::ToolStd,
mode: Mode::ToolStd,
allow_features: tool::TestFloatParse::ALLOW_FEATURES
});
tool_check_step!(FeaturesStatusDump {
path: "src/tools/features-status-dump",
mode: |_builder| Mode::ToolBootstrap
mode: Mode::ToolBootstrap
});

tool_check_step!(Bootstrap {
path: "src/bootstrap",
mode: |_builder| Mode::ToolBootstrap,
default: false
});
tool_check_step!(Bootstrap { path: "src/bootstrap", mode: Mode::ToolBootstrap, default: false });

// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
// check to make it easier to work on.
tool_check_step!(RunMakeSupport {
path: "src/tools/run-make-support",
mode: |_builder| Mode::ToolBootstrap,
mode: Mode::ToolBootstrap,
default: false
});

tool_check_step!(CoverageDump {
path: "src/tools/coverage-dump",
mode: |_builder| Mode::ToolBootstrap,
mode: Mode::ToolBootstrap,
default: false
});

// Compiletest is implicitly "checked" when it gets built in order to run tests,
// so this is mainly for people working on compiletest to run locally.
tool_check_step!(Compiletest {
path: "src/tools/compiletest",
mode: |builder: &Builder<'_>| if builder.config.compiletest_use_stage0_libtest {
Mode::ToolBootstrap
} else {
Mode::ToolStd
},
// Note: compiletest currently still depends on `#![feature(internal_output_capture)]`, so
// should be considered a `ToolStd` tool for robustness, as it is *possible* for that internal
// library feature to be changed.
mode: Mode::ToolStd,
allow_features: COMPILETEST_ALLOW_FEATURES,
default: false,
});
26 changes: 17 additions & 9 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::{env, fs, iter};

use build_helper::exit;

use crate::core::build_steps::compile::{Std, run_cargo};
use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
Expand Down Expand Up @@ -714,17 +716,24 @@ impl Step for CompiletestTest {

/// Runs `cargo test` for compiletest.
fn run(self, builder: &Builder<'_>) {
if builder.top_stage == 0 && !builder.config.compiletest_force_stage0 {
eprintln!(
"`compiletest` unit tests cannot be run against stage 0 unless `build.compiletest-force-stage0` override is specified"
);
exit!(1);
}

let host = self.host;
let compiler = builder.compiler(builder.top_stage, host);

// We need `ToolStd` for the locally-built sysroot because
// compiletest uses unstable features of the `test` crate.
// We need `ToolStd` for the locally-built sysroot because compiletest uses unstable
// features of the `test` crate.
builder.std(compiler, host);
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
// compiletest uses libtest internals; make it use the in-tree std to make sure it never breaks
// when std sources change.
// compiletest uses libtest internals; make it use the in-tree std to make sure it never
// breaks when std sources change.
Mode::ToolStd,
host,
Kind::Test,
Expand Down Expand Up @@ -1612,12 +1621,11 @@ impl Step for Compiletest {
return;
}

if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
if builder.top_stage == 0 && !builder.config.compiletest_force_stage0 {
eprintln!("\
ERROR: `--stage 0` runs compiletest on the stage0 (precompiled) compiler, not your local changes, and will almost always cause tests to fail
HELP: to test the compiler, use `--stage 1` instead
HELP: to test the standard library, use `--stage 0 library/std` instead
NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
ERROR: `--stage 0` runs `compiletest` on the stage0 (precompiled) compiler, not your local changes, and will almost always cause tests to fail
HELP: to test the staged compiler/library, use `--stage 1` instead
NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `--set build.compiletest-force-stage0=true`."
);
crate::exit!(1);
}
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,12 @@ macro_rules! bootstrap_tool {
)*

let is_unstable = false $(|| $unstable)*;
let compiletest_wants_stage0 = $tool_name == "compiletest" && builder.config.compiletest_use_stage0_libtest;

builder.ensure(ToolBuild {
build_compiler: self.compiler,
target: self.target,
tool: $tool_name,
mode: if is_unstable && !compiletest_wants_stage0 {
mode: if is_unstable || !builder.config.compiletest_force_stage0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing something weird, it compiles compiletest using the stage0 compiler, but uses Mode::ToolStd. We should have an assert against that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, yeah this is unintended.

// use in-tree libraries for unstable features
Mode::ToolStd
} else {
Expand Down
30 changes: 20 additions & 10 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,16 +1531,6 @@ mod snapshot {
insta::assert_snapshot!(
ctx.config("check")
.path("compiletest")
.render_steps(), @"[check] rustc 0 <host> -> Compiletest 1 <host>");
}

#[test]
fn check_compiletest_stage1_libtest() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("check")
.path("compiletest")
.args(&["--set", "build.compiletest-use-stage0-libtest=false"])
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
Expand All @@ -1549,6 +1539,26 @@ mod snapshot {
");
}

#[test]
#[should_panic]
fn test_compiletest_stage0_no_force() {
let ctx = TestCtx::new();
ctx.config("test").path("compiletest").stage(0).run();
}

#[test]
fn test_compiletest_force_stage0() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("test")
.path("compiletest")
.stage(0)
.args(&[
"--set", "build.compiletest-force-stage0=true"
])
.render_steps(), @"[build] rustdoc 0 <host>");
}

#[test]
fn check_codegen() {
let ctx = TestCtx::new();
Expand Down
12 changes: 8 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,13 @@ pub struct Config {
/// `paths=["foo", "bar"]`.
pub paths: Vec<PathBuf>,

/// Force `compiletest` to be built and tested with stage 0 (compiler, library). Note that
/// `compiletest`'s own unit tests are not guaranteed to pass against stage 0 (compiler,
/// library)!
pub compiletest_force_stage0: bool,
/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub compiletest_diff_tool: Option<String>,

/// Whether to use the precompiled stage0 libtest with compiletest.
pub compiletest_use_stage0_libtest: bool,
/// Default value for `--extra-checks`
pub tidy_extra_checks: Option<String>,
pub is_running_on_ci: bool,
Expand Down Expand Up @@ -746,8 +748,8 @@ impl Config {
android_ndk,
optimized_compiler_builtins,
jobs,
compiletest_force_stage0,
compiletest_diff_tool,
compiletest_use_stage0_libtest,
tidy_extra_checks,
ccache,
exclude,
Expand Down Expand Up @@ -1012,8 +1014,10 @@ impl Config {

config.optimized_compiler_builtins =
optimized_compiler_builtins.unwrap_or(config.channel != "dev");

config.compiletest_force_stage0 = compiletest_force_stage0.unwrap_or(false);
config.compiletest_diff_tool = compiletest_diff_tool;
config.compiletest_use_stage0_libtest = compiletest_use_stage0_libtest.unwrap_or(true);

config.tidy_extra_checks = tidy_extra_checks;

let download_rustc = config.download_rustc_commit.is_some();
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/config/toml/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ define_config! {
android_ndk: Option<PathBuf> = "android-ndk",
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jobs: Option<u32> = "jobs",
compiletest_force_stage0: Option<bool> = "compiletest-force-stage0",
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
tidy_extra_checks: Option<String> = "tidy-extra-checks",
ccache: Option<StringOrBool> = "ccache",
exclude: Option<Vec<PathBuf>> = "exclude",
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 @@ -486,4 +486,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning,
summary: "Removed `rust.description` and `llvm.ccache` as it was deprecated in #137723 and #136941 long time ago.",
},
ChangeInfo {
change_id: 144563,
severity: ChangeSeverity::Warning,
summary: "Removed `build.compiletest-use-stage0-libtest` as `compiletest` is now considered a staged `ToolStd` tool. The possibility to run `compiletest`-managed test suites or `compiletest` unit tests against a stage 0 compiler is retained, but instead of `COMPILETEST_FORCE_STAGE0` env var, it is now a proper config option `build.compiletest-force-stage0`.",
},
];
2 changes: 1 addition & 1 deletion src/ci/citool/tests/test-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ runners:
<<: *base-job
envs:
env-x86_64-apple-tests: &env-x86_64-apple-tests
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
SCRIPT: ./x.py check compiletest && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
# Ensure that host tooling is tested on our minimum supported macOS version.
Expand Down
5 changes: 2 additions & 3 deletions src/ci/docker/host-x86_64/pr-check-1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ ENV SCRIPT \
python3 ../x.py check bootstrap && \
/scripts/check-default-config-profiles.sh && \
python3 ../x.py build src/tools/build-manifest && \
python3 ../x.py test --stage 0 src/tools/compiletest && \
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
python3 ../x.py check --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \
/scripts/validate-toolstate.sh && \
reuse --include-submodules lint && \
python3 ../x.py test collect-license-metadata
python3 ../x.py test collect-license-metadata && \
python3 ../x.py test src/tools/compiletest
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ ENV HOST_TARGET x86_64-unknown-linux-gnu
COPY scripts/shared.sh /scripts/

ENV SCRIPT /tmp/checktools.sh ../x.py && \
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
python3 ../x.py check compiletest && \
python3 ../x.py test tests/rustdoc-gui --stage 2 --test-args "'--jobs 1'"
2 changes: 1 addition & 1 deletion src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ runners:

envs:
env-x86_64-apple-tests: &env-x86_64-apple-tests
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
SCRIPT: ./x.py check compiletest && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc
# Ensure that host tooling is tested on our minimum supported macOS version.
MACOSX_DEPLOYMENT_TARGET: 10.12
Expand Down
Loading