Skip to content

Commit 1456b67

Browse files
authored
Rollup merge of #146124 - Kobzol:distcheck-ext, r=jieyouxu
Test `rustc-dev` in `distcheck` Adds a new `distcheck` test component. Fixes: #138646 r? ``@jieyouxu`` try-job: x86_64-gnu-distcheck
2 parents 5848328 + fe90610 commit 1456b67

File tree

2 files changed

+99
-62
lines changed

2 files changed

+99
-62
lines changed

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,18 @@ pub struct RustcDev {
823823
target: TargetSelection,
824824
}
825825

826+
impl RustcDev {
827+
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
828+
Self {
829+
// We currently always ship a stage 2 rustc-dev component, so we build it with the
830+
// stage 1 compiler. This might change in the future.
831+
// The precise stage used here is important, so we hard-code it.
832+
build_compiler: builder.compiler(1, builder.config.host_target),
833+
target,
834+
}
835+
}
836+
}
837+
826838
impl Step for RustcDev {
827839
type Output = Option<GeneratedTarball>;
828840
const DEFAULT: bool = true;
@@ -833,13 +845,7 @@ impl Step for RustcDev {
833845
}
834846

835847
fn make_run(run: RunConfig<'_>) {
836-
run.builder.ensure(RustcDev {
837-
// We currently always ship a stage 2 rustc-dev component, so we build it with the
838-
// stage 1 compiler. This might change in the future.
839-
// The precise stage used here is important, so we hard-code it.
840-
build_compiler: run.builder.compiler(1, run.builder.config.host_target),
841-
target: run.target,
842-
});
848+
run.builder.ensure(RustcDev::new(run.builder, run.target));
843849
}
844850

845851
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {

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

Lines changed: 86 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,68 +3182,99 @@ impl Step for Distcheck {
31823182
/// check steps from those sources.
31833183
/// - Check that selected dist components (`rust-src` only at the moment) at least have expected
31843184
/// directory shape and crate manifests that cargo can generate a lockfile from.
3185+
/// - Check that we can run `cargo metadata` on the workspace in the `rustc-dev` component
31853186
///
31863187
/// FIXME(#136822): dist components are under-tested.
31873188
fn run(self, builder: &Builder<'_>) {
31883189
// Use a temporary directory completely outside the current checkout, to avoid reusing any
31893190
// local source code, built artifacts or configuration by accident
31903191
let root_dir = std::env::temp_dir().join("distcheck");
31913192

3192-
// Check that we can build some basic things from the plain source tarball
3193-
builder.info("Distcheck plain source tarball");
3194-
let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3195-
let plain_src_dir = root_dir.join("distcheck-plain-src");
3196-
builder.clear_dir(&plain_src_dir);
3197-
3198-
let configure_args: Vec<String> = std::env::var("DISTCHECK_CONFIGURE_ARGS")
3199-
.map(|args| args.split(" ").map(|s| s.to_string()).collect::<Vec<String>>())
3200-
.unwrap_or_default();
3201-
3202-
command("tar")
3203-
.arg("-xf")
3204-
.arg(plain_src_tarball.tarball())
3205-
.arg("--strip-components=1")
3206-
.current_dir(&plain_src_dir)
3207-
.run(builder);
3208-
command("./configure")
3209-
.arg("--set")
3210-
.arg("rust.omit-git-hash=false")
3211-
.args(&configure_args)
3212-
.arg("--enable-vendor")
3213-
.current_dir(&plain_src_dir)
3214-
.run(builder);
3215-
command(helpers::make(&builder.config.host_target.triple))
3216-
.arg("check")
3217-
// Do not run the build as if we were in CI, otherwise git would be assumed to be
3218-
// present, but we build from a tarball here
3219-
.env("GITHUB_ACTIONS", "0")
3220-
.current_dir(&plain_src_dir)
3221-
.run(builder);
3222-
3223-
// Now make sure that rust-src has all of libstd's dependencies
3224-
builder.info("Distcheck rust-src");
3225-
let src_tarball = builder.ensure(dist::Src);
3226-
let src_dir = root_dir.join("distcheck-src");
3227-
builder.clear_dir(&src_dir);
3228-
3229-
command("tar")
3230-
.arg("-xf")
3231-
.arg(src_tarball.tarball())
3232-
.arg("--strip-components=1")
3233-
.current_dir(&src_dir)
3234-
.run(builder);
3235-
3236-
let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3237-
command(&builder.initial_cargo)
3238-
// Will read the libstd Cargo.toml
3239-
// which uses the unstable `public-dependency` feature.
3240-
.env("RUSTC_BOOTSTRAP", "1")
3241-
.arg("generate-lockfile")
3242-
.arg("--manifest-path")
3243-
.arg(&toml)
3244-
.current_dir(&src_dir)
3245-
.run(builder);
3246-
}
3193+
distcheck_plain_source_tarball(builder, &root_dir.join("distcheck-rustc-src"));
3194+
distcheck_rust_src(builder, &root_dir.join("distcheck-rust-src"));
3195+
distcheck_rustc_dev(builder, &root_dir.join("distcheck-rustc-dev"));
3196+
}
3197+
}
3198+
3199+
/// Check that we can build some basic things from the plain source tarball
3200+
fn distcheck_plain_source_tarball(builder: &Builder<'_>, plain_src_dir: &Path) {
3201+
builder.info("Distcheck plain source tarball");
3202+
let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3203+
builder.clear_dir(plain_src_dir);
3204+
3205+
let configure_args: Vec<String> = std::env::var("DISTCHECK_CONFIGURE_ARGS")
3206+
.map(|args| args.split(" ").map(|s| s.to_string()).collect::<Vec<String>>())
3207+
.unwrap_or_default();
3208+
3209+
command("tar")
3210+
.arg("-xf")
3211+
.arg(plain_src_tarball.tarball())
3212+
.arg("--strip-components=1")
3213+
.current_dir(plain_src_dir)
3214+
.run(builder);
3215+
command("./configure")
3216+
.arg("--set")
3217+
.arg("rust.omit-git-hash=false")
3218+
.args(&configure_args)
3219+
.arg("--enable-vendor")
3220+
.current_dir(plain_src_dir)
3221+
.run(builder);
3222+
command(helpers::make(&builder.config.host_target.triple))
3223+
.arg("check")
3224+
// Do not run the build as if we were in CI, otherwise git would be assumed to be
3225+
// present, but we build from a tarball here
3226+
.env("GITHUB_ACTIONS", "0")
3227+
.current_dir(plain_src_dir)
3228+
.run(builder);
3229+
}
3230+
3231+
/// Check that rust-src has all of libstd's dependencies
3232+
fn distcheck_rust_src(builder: &Builder<'_>, src_dir: &Path) {
3233+
builder.info("Distcheck rust-src");
3234+
let src_tarball = builder.ensure(dist::Src);
3235+
builder.clear_dir(src_dir);
3236+
3237+
command("tar")
3238+
.arg("-xf")
3239+
.arg(src_tarball.tarball())
3240+
.arg("--strip-components=1")
3241+
.current_dir(src_dir)
3242+
.run(builder);
3243+
3244+
let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3245+
command(&builder.initial_cargo)
3246+
// Will read the libstd Cargo.toml
3247+
// which uses the unstable `public-dependency` feature.
3248+
.env("RUSTC_BOOTSTRAP", "1")
3249+
.arg("generate-lockfile")
3250+
.arg("--manifest-path")
3251+
.arg(&toml)
3252+
.current_dir(src_dir)
3253+
.run(builder);
3254+
}
3255+
3256+
/// Check that rustc-dev's compiler crate source code can be loaded with `cargo metadata`
3257+
fn distcheck_rustc_dev(builder: &Builder<'_>, dir: &Path) {
3258+
builder.info("Distcheck rustc-dev");
3259+
let tarball = builder.ensure(dist::RustcDev::new(builder, builder.host_target)).unwrap();
3260+
builder.clear_dir(dir);
3261+
3262+
command("tar")
3263+
.arg("-xf")
3264+
.arg(tarball.tarball())
3265+
.arg("--strip-components=1")
3266+
.current_dir(dir)
3267+
.run(builder);
3268+
3269+
command(&builder.initial_cargo)
3270+
.arg("metadata")
3271+
.arg("--manifest-path")
3272+
.arg("rustc-dev/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml")
3273+
.env("RUSTC_BOOTSTRAP", "1")
3274+
// We might not have a globally available `rustc` binary on CI
3275+
.env("RUSTC", &builder.initial_rustc)
3276+
.current_dir(dir)
3277+
.run(builder);
32473278
}
32483279

32493280
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)