Skip to content

Commit

Permalink
Support x test --stage 1 ui-fulldeps
Browse files Browse the repository at this point in the history
Nils had an excellent idea the other day: the same way that rustdoc is
able to load `rustc_driver` from the sysroot, ui-fulldeps tests should
also be able to load it from the sysroot. That allows us to run fulldeps
tests with stage1, without having to fully rebuild the compiler twice.
It does unfortunately have the downside that we're running the tests on
the *bootstrap* compiler, not the in-tree sources, but since most of the
fulldeps tests are for the *API* of the compiler, that seems ok.

I think it's possible to extend this to `run-make-fulldeps`, but I've
run out of energy for tonight.

- Move `plugin` tests into a subdirectory.

  Plugins are loaded at runtime with `dlopen` and so require the ABI of
  the running compile to match the ABI of the compiler linked with
  `rustc_driver`. As a result they can't be supported in stage 1 and have
  to use `// ignore-stage1`.

- Remove `ignore-stage1` from most non-plugin tests

- Ignore diagnostic tests in stage 1. Even though this requires a stage
  2 build to load rustc_driver, it's primarily testing the error message
  that the *running* compiler emits when the diagnostic struct is malformed.

- Pass `-Zforce-unstable-if-unmarked` in stage1, not just stage2. That
  allows running `hash-stable-is-unstable` in stage1, since it now
  suggests adding `rustc_private` to enable loading the crates.

- Add libLLVM.so to the stage0 target sysroot, to allow fulldeps tests
  that act as custom drivers to load it at runtime.

- Pass `--sysroot stage0-sysroot` in compiletest so that we use the
  correct version of std.
  • Loading branch information
jyn514 committed Apr 18, 2023
1 parent ce1073b commit d6af602
Show file tree
Hide file tree
Showing 72 changed files with 236 additions and 204 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn main() {
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot. We also do this for host crates, since those
// may be proc macros, in which case we might ship them.
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != "0" || target.is_some()) {
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,24 @@ impl<'a> Builder<'a> {
// Avoid deleting the rustlib/ directory we just copied
// (in `impl Step for Sysroot`).
if !builder.download_rustc() {
builder.verbose(&format!(
"Removing sysroot {} to avoid caching bugs",
sysroot.display()
));
let _ = fs::remove_dir_all(&sysroot);
t!(fs::create_dir_all(&sysroot));
}

if self.compiler.stage == 0 {
// The stage 0 compiler for the build triple is always pre-built.
// Ensure that `libLLVM.so` ends up in the target libdir, so that ui-fulldeps tests can use it when run.
dist::maybe_install_llvm_target(
builder,
self.compiler.host,
&builder.sysroot(self.compiler),
);
}

INTERNER.intern_path(sysroot)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ impl Step for Sysroot {
};
let sysroot = sysroot_dir(compiler.stage);

builder.verbose(&format!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
let _ = fs::remove_dir_all(&sysroot);
t!(fs::create_dir_all(&sysroot));

Expand Down
25 changes: 19 additions & 6 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
crate::detail_exit(1);
}

let compiler = self.compiler;
let mut compiler = self.compiler;
let target = self.target;
let mode = self.mode;
let suite = self.suite;
Expand All @@ -1461,15 +1461,28 @@ note: if you're sure you want to do this, please open an issue as to why. In the
return;
}

if suite == "debuginfo" {
builder
.ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
}
// Support stage 1 ui-fulldeps. This is somewhat complicated: ui-fulldeps tests for the most
// part test the *API* of the compiler, not how it compiles a given file. As a result, we
// can run them against the stage 1 sources as long as we build them with the stage 0
// bootstrap compiler.
// NOTE: Only stage 1 is special cased because we need the rustc_private artifacts to match the
// running compiler in stage 2 when plugins run.
let stage_id = if suite == "ui-fulldeps" && compiler.stage == 1 {
compiler = builder.compiler(compiler.stage - 1, target);
format!("stage{}-{}", compiler.stage + 1, target)
} else {
format!("stage{}-{}", compiler.stage, target)
};

if suite.ends_with("fulldeps") {
builder.ensure(compile::Rustc::new(compiler, target));
}

if suite == "debuginfo" {
builder
.ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
}

builder.ensure(compile::Std::new(compiler, target));
// ensure that `libproc_macro` is available on the host.
builder.ensure(compile::Std::new(compiler, compiler.host));
Expand Down Expand Up @@ -1528,7 +1541,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
cmd.arg("--src-base").arg(builder.src.join("tests").join(suite));
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
cmd.arg("--sysroot-base").arg(builder.sysroot(compiler));
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
cmd.arg("--stage-id").arg(stage_id);
cmd.arg("--suite").arg(suite);
cmd.arg("--mode").arg(mode);
cmd.arg("--target").arg(target.rustc_target_arg());
Expand Down
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ pub struct TargetCfgs {

impl TargetCfgs {
fn new(config: &Config) -> TargetCfgs {
let targets: HashMap<String, TargetCfg> = if config.stage_id.starts_with("stage0-") {
let targets: HashMap<String, TargetCfg> = if config.stage_id.starts_with("stage0-")
|| (config.suite == "ui-fulldeps" && config.stage_id.starts_with("stage1-"))
{
// #[cfg(bootstrap)]
// Needed only for one cycle, remove during the bootstrap bump.
Self::collect_all_slow(config)
Expand Down
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,9 @@ impl<'test> TestCx<'test> {
// Use a single thread for efficiency and a deterministic error message order
rustc.arg("-Zthreads=1");

// In stage 0, make sure we use `stage0-sysroot` instead of the bootstrap sysroot.
rustc.arg("--sysroot").arg(&self.config.sysroot_base);

// Optionally prevent default --target if specified in test compile-flags.
let custom_target = self.props.compile_flags.iter().any(|x| x.starts_with("--target"));

Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};

// FIXME: The following limits should be reduced eventually.
const ENTRY_LIMIT: usize = 885;
const ROOT_ENTRY_LIMIT: usize = 891;
const ROOT_ENTRY_LIMIT: usize = 894;
const ISSUES_ENTRY_LIMIT: usize = 1977;

fn check_entries(tests_path: &Path, bad: &mut bool) {
Expand Down
1 change: 0 additions & 1 deletion tests/ui-fulldeps/compiler-calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Test that the Callbacks interface to the compiler works.

// ignore-cross-compile
// ignore-stage1
// ignore-remote

#![feature(rustc_private)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui-fulldeps/hash-stable-is-unstable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-stage1
// compile-flags: -Zdeduplicate-diagnostics=yes
extern crate rustc_data_structures;
//~^ use of unstable library feature 'rustc_private'
Expand Down
10 changes: 5 additions & 5 deletions tests/ui-fulldeps/hash-stable-is-unstable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:3:1
--> $DIR/hash-stable-is-unstable.rs:2:1
|
LL | extern crate rustc_data_structures;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | extern crate rustc_data_structures;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:5:1
--> $DIR/hash-stable-is-unstable.rs:4:1
|
LL | extern crate rustc_macros;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | extern crate rustc_macros;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:7:1
--> $DIR/hash-stable-is-unstable.rs:6:1
|
LL | extern crate rustc_query_system;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -26,7 +26,7 @@ LL | extern crate rustc_query_system;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:10:5
--> $DIR/hash-stable-is-unstable.rs:9:5
|
LL | use rustc_macros::HashStable;
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -35,7 +35,7 @@ LL | use rustc_macros::HashStable;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:13:10
--> $DIR/hash-stable-is-unstable.rs:12:10
|
LL | #[derive(HashStable)]
| ^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui-fulldeps/pathless-extern-unstable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-stage1
// edition:2018
// compile-flags:--extern rustc_middle

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/pathless-extern-unstable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/pathless-extern-unstable.rs:7:9
--> $DIR/pathless-extern-unstable.rs:6:9
|
LL | pub use rustc_middle;
| ^^^^^^^^^^^^
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// aux-build:rlib-crate-test.rs
// ignore-stage1
// ignore-cross-compile gives a different error message

#![feature(plugin)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0457]: plugin `rlib_crate_test` only found in rlib format, but must be available in dylib format
--> $DIR/macro-crate-rlib.rs:5:11
--> $DIR/macro-crate-rlib.rs:6:11
|
LL | #![plugin(rlib_crate_test)]
| ^^^^^^^^^^^^^^^
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
// changing the output of this test. Since Diagnostic is strictly internal to the compiler
// the test is just ignored on stable and beta:
// ignore-stage1
// ignore-beta
// ignore-stable

Expand Down
Loading

0 comments on commit d6af602

Please sign in to comment.