Skip to content

Commit 6250a47

Browse files
committed
make codegen-backends directory name configurable
This allows to parallel-install several versions of rust system-wide Fixes #48263 Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent ddfbf2b commit 6250a47

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@
321321
# bootstrap)
322322
#codegen-backends = ["llvm"]
323323

324+
# This is the name of the directory in which codegen backends will get installed
325+
#codegen-backends-dir = "codegen-backends"
326+
324327
# Flag indicating whether `libstd` calls an imported function to handle basic IO
325328
# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
326329
# target, as without this option the test output will not be captured.

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a> Builder<'a> {
462462

463463
pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
464464
self.sysroot_libdir(compiler, compiler.host)
465-
.with_file_name("codegen-backends")
465+
.with_file_name(self.build.config.rust_codegen_backends_dir.clone())
466466
}
467467

468468
/// Returns the compiler's libdir where it stores the dynamic libraries that

src/bootstrap/compile.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
514514
cargo.env("CFG_RELEASE", build.rust_release())
515515
.env("CFG_RELEASE_CHANNEL", &build.config.channel)
516516
.env("CFG_VERSION", build.rust_version())
517-
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
517+
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default())
518+
.env("CFG_CODEGEN_BACKENDS_DIR", &build.config.rust_codegen_backends_dir);
518519

519520
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
520521
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);

src/bootstrap/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub struct Config {
9696
pub rust_debuginfo_tests: bool,
9797
pub rust_dist_src: bool,
9898
pub rust_codegen_backends: Vec<Interned<String>>,
99+
pub rust_codegen_backends_dir: String,
99100

100101
pub build: Interned<String>,
101102
pub hosts: Vec<Interned<String>>,
@@ -289,6 +290,7 @@ struct Rust {
289290
test_miri: Option<bool>,
290291
save_toolstates: Option<String>,
291292
codegen_backends: Option<Vec<String>>,
293+
codegen_backends_dir: Option<String>,
292294
wasm_syscall: Option<bool>,
293295
}
294296

@@ -330,6 +332,7 @@ impl Config {
330332
config.rust_dist_src = true;
331333
config.test_miri = false;
332334
config.rust_codegen_backends = vec![INTERNER.intern_str("llvm")];
335+
config.rust_codegen_backends_dir = "codegen-backends".to_owned();
333336

334337
config.rustc_error_format = flags.rustc_error_format;
335338
config.on_fail = flags.on_fail;
@@ -488,6 +491,8 @@ impl Config {
488491
.collect();
489492
}
490493

494+
set(&mut config.rust_codegen_backends_dir, rust.codegen_backends_dir.clone());
495+
491496
match rust.codegen_units {
492497
Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
493498
Some(n) => config.rust_codegen_units = Some(n),

src/bootstrap/dist.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ impl Step for Std {
590590
let mut src = builder.sysroot_libdir(compiler, target).to_path_buf();
591591
src.pop(); // Remove the trailing /lib folder from the sysroot_libdir
592592
cp_filtered(&src, &dst, &|path| {
593-
path.file_name().and_then(|s| s.to_str()) != Some("codegen-backends")
593+
path.file_name().and_then(|s| s.to_str()) !=
594+
Some(build.config.rust_codegen_backends_dir.as_str())
594595
});
595596

596597
let mut cmd = rust_installer(builder);

src/librustc_driver/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ fn get_trans_sysroot(backend_name: &str) -> fn() -> Box<TransCrate> {
303303
let sysroot = sysroot_candidates.iter()
304304
.map(|sysroot| {
305305
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
306-
sysroot.join(libdir).with_file_name("codegen-backends")
306+
sysroot.join(libdir)
307+
.with_file_name(option_env!("CFG_CODEGEN_BACKENDS_DIR")
308+
.unwrap_or("codegen-backends"))
307309
})
308310
.filter(|f| {
309311
info!("codegen backend candidate: {}", f.display());

0 commit comments

Comments
 (0)