Skip to content

fix(bootstrap): set dylib path for rustc tests#158530

Open
HNO3Miracle wants to merge 1 commit into
rust-lang:mainfrom
HNO3Miracle:fix-rustc-main-test-dylib-path
Open

fix(bootstrap): set dylib path for rustc tests#158530
HNO3Miracle wants to merge 1 commit into
rust-lang:mainfrom
HNO3Miracle:fix-rustc-main-test-dylib-path

Conversation

@HNO3Miracle

@HNO3Miracle HNO3Miracle commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #158526

compiler/rustc builds temporary test binaries when running ./x test --stage 2 compiler/rustc. With Cargo's new build-dir layout, dylibs such as rustc_driver can be emitted under Cargo's build/*/*/out directories rather than a directory that is already present in the test command's dynamic library lookup path.

Build the rustc test binaries once with cargo test --no-run, then scan the Cargo build directory for out directories containing dylibs and add them to the dynamic library lookup path used by the actual test run. This avoids target-specific rpath handling and uses the platform-specific lookup variable selected by bootstrap (LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PATH, etc.).

Tests:

  • ./x fmt --all
  • git diff --check
  • ./x check src/bootstrap
  • ./x test src/bootstrap

r? @bjorn3

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 28, 2026
@bjorn3

bjorn3 commented Jun 28, 2026

Copy link
Copy Markdown
Member

-Wl,-rpath only works for ELF targets. The Apple linker has a different cli flag and Windows doesn't support rpath at all. Instead tests should run with the right dynamic linker library path set.

Signed-off-by: HNO3Miracle <xiangao.or@isrc.iscas.ac.cn>
@HNO3Miracle HNO3Miracle force-pushed the fix-rustc-main-test-dylib-path branch from bfc9c00 to 581cf99 Compare June 28, 2026 20:32
@rustbot rustbot added the A-testsuite Area: The testsuite used to check the correctness of rustc label Jun 28, 2026
@HNO3Miracle HNO3Miracle changed the title fix(bootstrap): set rpath for rustc-main tests fix(bootstrap): set dylib path for rustc tests Jun 28, 2026
@HNO3Miracle

Copy link
Copy Markdown
Contributor Author

I'm not entirely sure if this is the best approach, and I'd appreciate any feedback or suggestions.

if mode == Mode::Rustc {
// Build the test binaries before preparing the command that runs them. Some rustc
// dylibs are emitted into Cargo's build directory, and the run command needs to add
// those freshly-created directories to the dynamic library lookup path.

@bjorn3 bjorn3 Jun 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm curious why cargo doesn't already add those dylibs. It should in principle do so for all dylibs that are dependencies of an executable. Or maybe that logic is broken in cargo with the new build dir layout?

View changes since the review

@HNO3Miracle

Copy link
Copy Markdown
Contributor Author

I looked into Cargo a bit more, and I think this is likely related to the new build-dir layout indeed.

For compilation, Cargo does recursively add dependency dirs through lib_search_paths / add_dep_arg, so rustc can link against rustc_driver.

For running test binaries, however, Compilation::target_process only adds deps_output[&kind] to the dynamic library search path. With the new layout, deps_output is still a single HashMap<CompileKind, PathBuf>, and BuildRunner::prepare seems to repeatedly overwrite it while iterating units. So the runtime path can miss the per unit directory that contains librustc_driver.

This PR works around that in bootstrap by doing cargo test --no-run first and then adding the generated dylib-containing out dirs to the test command's dynamic library path. But I agree the more fundamental fix may belong in Cargo's new-layout runtime search path handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[riscv64] test: rustc-main fails to run due to missing librustc_driver in stage2 runtime lib directory

3 participants