Skip to content

Commit 581cf99

Browse files
committed
fix(bootstrap): set dylib path for rustc tests
Signed-off-by: HNO3Miracle <xiangao.or@isrc.iscas.ac.cn>
1 parent 2574810 commit 581cf99

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,7 @@ fn prepare_cargo_test(
32533253
builder: &Builder<'_>,
32543254
) -> BootstrapCommand {
32553255
let compiler = cargo.compiler();
3256+
let mode = cargo.mode();
32563257
let mut cargo: BootstrapCommand = cargo.into();
32573258

32583259
// Propagate `--bless` if it has not already been set/unset
@@ -3300,6 +3301,11 @@ fn prepare_cargo_test(
33003301
if builder.kind != Kind::Miri {
33013302
let mut dylib_paths = builder.rustc_lib_paths(compiler);
33023303
dylib_paths.push(builder.sysroot_target_libdir(compiler, target));
3304+
if mode == Mode::Rustc {
3305+
dylib_paths.extend(tool::discover_out_dirs_with_dylibs(
3306+
builder.cargo_out(compiler, Mode::Rustc, target).join("build"),
3307+
));
3308+
}
33033309
helpers::add_dylib_path(dylib_paths, &mut cargo);
33043310
}
33053311

@@ -3373,6 +3379,17 @@ impl Step for Crate {
33733379
builder.ensure(Std::new(build_compiler, build_compiler.host).force_recompile(true));
33743380
let record_failed_tests = builder.ensure(SetupFailedTestsFile);
33753381

3382+
let new_cargo = || {
3383+
builder::Cargo::new(
3384+
builder,
3385+
build_compiler,
3386+
mode,
3387+
SourceType::InTree,
3388+
target,
3389+
builder.kind,
3390+
)
3391+
};
3392+
33763393
let mut cargo = if builder.kind == Kind::Miri {
33773394
if builder.top_stage == 0 {
33783395
eprintln!("ERROR: `x.py miri` requires stage 1 or higher");
@@ -3425,14 +3442,7 @@ impl Step for Crate {
34253442
}
34263443

34273444
// Build `cargo test` command
3428-
builder::Cargo::new(
3429-
builder,
3430-
build_compiler,
3431-
mode,
3432-
SourceType::InTree,
3433-
target,
3434-
builder.kind,
3435-
)
3445+
new_cargo()
34363446
};
34373447

34383448
match mode {
@@ -3456,6 +3466,21 @@ impl Step for Crate {
34563466
_ => panic!("can only test libraries"),
34573467
};
34583468

3469+
if mode == Mode::Rustc {
3470+
// Build the test binaries before preparing the command that runs them. Some rustc
3471+
// dylibs are emitted into Cargo's build directory, and the run command needs to add
3472+
// those freshly-created directories to the dynamic library lookup path.
3473+
let mut build_only = new_cargo();
3474+
compile::rustc_cargo(builder, &mut build_only, target, &build_compiler, &self.crates);
3475+
build_only.arg("--no-run");
3476+
for krate in &self.crates {
3477+
build_only.arg("-p").arg(krate);
3478+
}
3479+
3480+
let mut build_only: BootstrapCommand = build_only.into();
3481+
build_only.run(builder);
3482+
}
3483+
34593484
let mut crates = self.crates.clone();
34603485
// The core and alloc crates can't directly be tested. We
34613486
// could silently ignore them, but adding their own test

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,8 +1660,9 @@ impl Builder<'_> {
16601660
}
16611661
}
16621662

1663-
/// Gets all of the `out` dirs in a given Cargo `build-dir/<profile>/build` dir.
1664-
fn discover_out_dirs_with_dylibs(dir: PathBuf) -> Vec<PathBuf> {
1663+
/// Gets all of the `out` dirs containing dylibs in a given Cargo
1664+
/// `build-dir/<profile>/build` dir.
1665+
pub(super) fn discover_out_dirs_with_dylibs(dir: PathBuf) -> Vec<PathBuf> {
16651666
if !dir.exists() {
16661667
return Vec::new();
16671668
}

0 commit comments

Comments
 (0)