Skip to content

Commit 3222bef

Browse files
committed
bootstrap: add Builder::rustc_cmd that includes the lib path
When building with `rust.rpath = false`, every `rustc` invocation needs to include the library path as well. I particularly ran into this in `generate_target_spec_json_schema` when testing 1.91-beta in Fedora, where we do disable rpath for our system builds. The new helper function will hopefully encourage the right thing going forward. (cherry picked from commit 03cdcb5)
1 parent 555abc1 commit 3222bef

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
519519
// Query rustc for the deployment target, and the associated env var.
520520
// The env var is one of the standard `*_DEPLOYMENT_TARGET` vars, i.e.
521521
// `MACOSX_DEPLOYMENT_TARGET`, `IPHONEOS_DEPLOYMENT_TARGET`, etc.
522-
let mut cmd = command(builder.rustc(cargo.compiler()));
522+
let mut cmd = builder.rustc_cmd(cargo.compiler());
523523
cmd.arg("--target").arg(target.rustc_target_arg());
524524
cmd.arg("--print=deployment-target");
525525
let output = cmd.run_capture_stdout(builder).stdout();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ fn generate_target_spec_json_schema(builder: &Builder<'_>, sysroot: &Path) {
625625
// We do this by using the stage 1 compiler, which is always compiled for the host,
626626
// even in a cross build.
627627
let stage1_host = builder.compiler(1, builder.host_target);
628-
let mut rustc = command(builder.rustc(stage1_host)).fail_fast();
628+
let mut rustc = builder.rustc_cmd(stage1_host).fail_fast();
629629
rustc
630630
.env("RUSTC_BOOTSTRAP", "1")
631631
.args(["--print=target-spec-json-schema", "-Zunstable-options"]);

src/bootstrap/src/core/build_steps/synthetic_targets.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use crate::Compiler;
1111
use crate::core::builder::{Builder, ShouldRun, Step};
1212
use crate::core::config::TargetSelection;
13-
use crate::utils::exec::command;
1413

1514
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1615
pub(crate) struct MirOptPanicAbortSyntheticTarget {
@@ -55,7 +54,7 @@ fn create_synthetic_target(
5554
return TargetSelection::create_synthetic(&name, path.to_str().unwrap());
5655
}
5756

58-
let mut cmd = command(builder.rustc(compiler));
57+
let mut cmd = builder.rustc_cmd(compiler);
5958
cmd.arg("--target").arg(base.rustc_target_arg());
6059
cmd.args(["-Zunstable-options", "--print", "target-spec-json"]);
6160

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,8 @@ impl Builder<'_> {
722722
// Build proc macros both for the host and the target unless proc-macros are not
723723
// supported by the target.
724724
if target != compiler.host && cmd_kind != Kind::Check {
725-
let mut rustc_cmd = command(self.rustc(compiler));
726-
self.add_rustc_lib_path(compiler, &mut rustc_cmd);
727-
728-
let error = rustc_cmd
725+
let error = self
726+
.rustc_cmd(compiler)
729727
.arg("--target")
730728
.arg(target.rustc_target_arg())
731729
.arg("--print=file-names")

src/bootstrap/src/core/builder/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,14 @@ Alternatively, you can set `build.local-rebuild=true` and use a stage0 compiler
15911591
}
15921592
}
15931593

1594+
/// Gets a command to run the compiler specified, including the dynamic library
1595+
/// path in case the executable has not been build with `rpath` enabled.
1596+
pub fn rustc_cmd(&self, compiler: Compiler) -> BootstrapCommand {
1597+
let mut cmd = command(self.rustc(compiler));
1598+
self.add_rustc_lib_path(compiler, &mut cmd);
1599+
cmd
1600+
}
1601+
15941602
/// Gets the paths to all of the compiler's codegen backends.
15951603
fn codegen_backends(&self, compiler: Compiler) -> impl Iterator<Item = PathBuf> {
15961604
fs::read_dir(self.sysroot_codegen_backends(compiler))

0 commit comments

Comments
 (0)