Skip to content

Commit a1ab3d9

Browse files
authored
Rollup merge of rust-lang#139386 - onur-ozkan:configurable-compiletest-libtest, r=jieyouxu,kobzol
make it possible to use stage0 libtest on compiletest With rust-lang#119899, building the library tree will require a stage 1 compiler. This is because `compiletest` is defined as a `ToolStd` (since rust-lang#68019) in order to use the in-tree library. As a result, rust-lang#119899 makes certain development workflows more difficult as changes on the compiler tree will now require recompiling `compiletest` each time. This PR allows switching `ToolStd` to `ToolBootstrap` with a simple boolean option in `bootstrap.toml` to allow `compiletest` to use the stage 0 `libtest` instead. The changes under `src/ci` are clearly intended to make sure that `compiletest` doesn't break during future bootstrap beta bumps.
2 parents c8f0356 + cae28b5 commit a1ab3d9

File tree

11 files changed

+91
-9
lines changed

11 files changed

+91
-9
lines changed

bootstrap.example.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# - A new option
2929
# - A change in the default values
3030
#
31-
# If the change-id does not match the version currently in use, x.py will
31+
# If the change-id does not match the version currently in use, x.py will
3232
# display the changes made to the bootstrap.
3333
# To suppress these warnings, you can set change-id = "ignore".
3434
#change-id = <latest change id in src/bootstrap/src/utils/change_tracker.rs>
@@ -442,6 +442,9 @@
442442
# What custom diff tool to use for displaying compiletest tests.
443443
#compiletest-diff-tool = <none>
444444

445+
# Whether to use the precompiled stage0 libtest with compiletest.
446+
#compiletest-use-stage0-libtest = true
447+
445448
# Indicates whether ccache is used when building certain artifacts (e.g. LLVM).
446449
# Set to `true` to use the first `ccache` in PATH, or set an absolute path to use
447450
# a specific version.

src/bootstrap/defaults/bootstrap.dist.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ test-stage = 2
77
doc-stage = 2
88
# When compiling from source, you usually want all tools.
99
extended = true
10+
# Use libtest built from the source tree instead of the precompiled one from stage 0.
11+
compiletest-use-stage0-libtest = false
1012

1113
# Most users installing from source want to build all parts of the project from source.
1214
[llvm]

src/bootstrap/src/core/build_steps/check.rs

+63-4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,69 @@ impl Step for RustAnalyzer {
369369
}
370370
}
371371

372+
/// Compiletest is implicitly "checked" when it gets built in order to run tests,
373+
/// so this is mainly for people working on compiletest to run locally.
374+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
375+
pub struct Compiletest {
376+
pub target: TargetSelection,
377+
}
378+
379+
impl Step for Compiletest {
380+
type Output = ();
381+
const ONLY_HOSTS: bool = true;
382+
const DEFAULT: bool = false;
383+
384+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
385+
run.path("src/tools/compiletest")
386+
}
387+
388+
fn make_run(run: RunConfig<'_>) {
389+
run.builder.ensure(Compiletest { target: run.target });
390+
}
391+
392+
fn run(self, builder: &Builder<'_>) {
393+
let mode = if builder.config.compiletest_use_stage0_libtest {
394+
Mode::ToolBootstrap
395+
} else {
396+
Mode::ToolStd
397+
};
398+
399+
let compiler = builder.compiler(
400+
if mode == Mode::ToolBootstrap { 0 } else { builder.top_stage },
401+
builder.config.build,
402+
);
403+
404+
if mode != Mode::ToolBootstrap {
405+
builder.ensure(Rustc::new(self.target, builder));
406+
}
407+
408+
let mut cargo = prepare_tool_cargo(
409+
builder,
410+
compiler,
411+
mode,
412+
self.target,
413+
builder.kind,
414+
"src/tools/compiletest",
415+
SourceType::InTree,
416+
&[],
417+
);
418+
419+
cargo.allow_features("test");
420+
421+
// For ./x.py clippy, don't run with --all-targets because
422+
// linting tests and benchmarks can produce very noisy results
423+
if builder.kind != Kind::Clippy {
424+
cargo.arg("--all-targets");
425+
}
426+
427+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, mode, self.target))
428+
.with_prefix("compiletest-check");
429+
430+
let _guard = builder.msg_check("compiletest artifacts", self.target);
431+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
432+
}
433+
}
434+
372435
macro_rules! tool_check_step {
373436
(
374437
$name:ident {
@@ -464,7 +527,3 @@ tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
464527
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
465528
// check to make it easier to work on.
466529
tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: false });
467-
468-
// Compiletest is implicitly "checked" when it gets built in order to run tests,
469-
// so this is mainly for people working on compiletest to run locally.
470-
tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,9 @@ pub fn run_cargo(
23982398
// Ok now we need to actually find all the files listed in `toplevel`. We've
23992399
// got a list of prefix/extensions and we basically just need to find the
24002400
// most recent file in the `deps` folder corresponding to each one.
2401-
let contents = t!(target_deps_dir.read_dir())
2401+
let contents = target_deps_dir
2402+
.read_dir()
2403+
.unwrap_or_else(|e| panic!("Couldn't read {}: {}", target_deps_dir.display(), e))
24022404
.map(|e| t!(e))
24032405
.map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata())))
24042406
.collect::<Vec<_>>();

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,14 @@ macro_rules! bootstrap_tool {
425425
}
426426
)*
427427

428+
let is_unstable = false $(|| $unstable)*;
429+
let compiletest_wants_stage0 = $tool_name == "compiletest" && builder.config.compiletest_use_stage0_libtest;
430+
428431
builder.ensure(ToolBuild {
429432
compiler: self.compiler,
430433
target: self.target,
431434
tool: $tool_name,
432-
mode: if false $(|| $unstable)* {
435+
mode: if is_unstable && !compiletest_wants_stage0 {
433436
// use in-tree libraries for unstable features
434437
Mode::ToolStd
435438
} else {

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

+6
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ pub struct Config {
417417
/// Command for visual diff display, e.g. `diff-tool --color=always`.
418418
pub compiletest_diff_tool: Option<String>,
419419

420+
/// Whether to use the precompiled stage0 libtest with compiletest.
421+
pub compiletest_use_stage0_libtest: bool,
422+
420423
pub is_running_on_ci: bool,
421424
}
422425

@@ -983,6 +986,7 @@ define_config! {
983986
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
984987
jobs: Option<u32> = "jobs",
985988
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
989+
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
986990
ccache: Option<StringOrBool> = "ccache",
987991
exclude: Option<Vec<PathBuf>> = "exclude",
988992
}
@@ -1682,6 +1686,7 @@ impl Config {
16821686
optimized_compiler_builtins,
16831687
jobs,
16841688
compiletest_diff_tool,
1689+
compiletest_use_stage0_libtest,
16851690
mut ccache,
16861691
exclude,
16871692
} = toml.build.unwrap_or_default();
@@ -2415,6 +2420,7 @@ impl Config {
24152420
config.optimized_compiler_builtins =
24162421
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
24172422
config.compiletest_diff_tool = compiletest_diff_tool;
2423+
config.compiletest_use_stage0_libtest = compiletest_use_stage0_libtest.unwrap_or(true);
24182424

24192425
let download_rustc = config.download_rustc_commit.is_some();
24202426
config.explicit_stage_from_cli = flags.stage.is_some();

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
391391
severity: ChangeSeverity::Info,
392392
summary: "You can now use `change-id = \"ignore\"` to suppress `change-id ` warnings in the console.",
393393
},
394+
ChangeInfo {
395+
change_id: 139386,
396+
severity: ChangeSeverity::Info,
397+
summary: "Added a new option `build.compiletest-use-stage0-libtest` to force `compiletest` to use the stage 0 libtest.",
398+
},
394399
];

src/ci/citool/tests/test-jobs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runners:
2727
<<: *base-job
2828
envs:
2929
env-x86_64-apple-tests: &env-x86_64-apple-tests
30-
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
30+
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
3131
RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc
3232
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
3333
# Ensure that host tooling is tested on our minimum supported macOS version.

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/
4747
ENV SCRIPT \
4848
python3 ../x.py check --stage 0 --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 && \
4949
/scripts/check-default-config-profiles.sh && \
50+
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
5051
python3 ../x.py check --target=x86_64-pc-windows-gnu --host=x86_64-pc-windows-gnu && \
5152
python3 ../x.py clippy ci && \
5253
python3 ../x.py build --stage 0 src/tools/build-manifest && \

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,5 @@ COPY scripts/shared.sh /scripts/
101101
# the local version of the package is different than the one used by the CI.
102102
ENV SCRIPT /tmp/checktools.sh ../x.py && \
103103
npm install browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true && \
104+
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
104105
python3 ../x.py test tests/rustdoc-gui --stage 2 --test-args "'--jobs 1'"

src/ci/github-actions/jobs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ runners:
5858
<<: *base-job
5959
envs:
6060
env-x86_64-apple-tests: &env-x86_64-apple-tests
61-
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
61+
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
6262
RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc
6363
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
6464
# Ensure that host tooling is tested on our minimum supported macOS version.

0 commit comments

Comments
 (0)