Skip to content

Commit 6bd01ef

Browse files
authored
Rollup merge of rust-lang#59341 - o01eg:use-custom-libdir, r=Mark-Simulacrum
Fix custom relative libdir While working on rust-lang#58947 I found out relative libdir ignored during setting LD_LIBRARY_PATH.
2 parents a2f3f0c + 5bcc365 commit 6bd01ef

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

src/bootstrap/builder.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,28 @@ impl<'a> Builder<'a> {
634634
if compiler.is_snapshot(self) {
635635
self.rustc_snapshot_libdir()
636636
} else {
637-
self.sysroot(compiler).join(libdir(&compiler.host))
637+
match self.config.libdir_relative() {
638+
Some(relative_libdir) if compiler.stage >= 1
639+
=> self.sysroot(compiler).join(relative_libdir),
640+
_ => self.sysroot(compiler).join(libdir(&compiler.host))
641+
}
642+
}
643+
}
644+
645+
/// Returns the compiler's relative libdir where it stores the dynamic libraries that
646+
/// it itself links against.
647+
///
648+
/// For example this returns `lib` on Unix and `bin` on
649+
/// Windows.
650+
pub fn libdir_relative(&self, compiler: Compiler) -> &Path {
651+
if compiler.is_snapshot(self) {
652+
libdir(&self.config.build).as_ref()
653+
} else {
654+
match self.config.libdir_relative() {
655+
Some(relative_libdir) if compiler.stage >= 1
656+
=> relative_libdir,
657+
_ => libdir(&compiler.host).as_ref()
658+
}
638659
}
639660
}
640661

src/bootstrap/compile.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use filetime::FileTime;
2020
use serde_json;
2121

2222
use crate::dist;
23-
use crate::util::{exe, libdir, is_dylib};
23+
use crate::util::{exe, is_dylib};
2424
use crate::{Compiler, Mode, GitRepo};
2525
use crate::native;
2626

@@ -1005,13 +1005,13 @@ impl Step for Assemble {
10051005

10061006
// Link in all dylibs to the libdir
10071007
let sysroot = builder.sysroot(target_compiler);
1008-
let sysroot_libdir = sysroot.join(libdir(&*host));
1009-
t!(fs::create_dir_all(&sysroot_libdir));
1008+
let rustc_libdir = builder.rustc_libdir(target_compiler);
1009+
t!(fs::create_dir_all(&rustc_libdir));
10101010
let src_libdir = builder.sysroot_libdir(build_compiler, host);
10111011
for f in builder.read_dir(&src_libdir) {
10121012
let filename = f.file_name().into_string().unwrap();
10131013
if is_dylib(&filename) {
1014-
builder.copy(&f.path(), &sysroot_libdir.join(&filename));
1014+
builder.copy(&f.path(), &rustc_libdir.join(&filename));
10151015
}
10161016
}
10171017

src/bootstrap/dist.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use build_helper::output;
1818

1919
use crate::{Compiler, Mode, LLVM_TOOLS};
2020
use crate::channel;
21-
use crate::util::{libdir, is_dylib, exe};
21+
use crate::util::{is_dylib, exe};
2222
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2323
use crate::compile;
2424
use crate::tool::{self, Tool};
@@ -473,21 +473,23 @@ impl Step for Rustc {
473473
fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
474474
let host = compiler.host;
475475
let src = builder.sysroot(compiler);
476-
let libdir = libdir(&host);
476+
let libdir = builder.rustc_libdir(compiler);
477477

478478
// Copy rustc/rustdoc binaries
479479
t!(fs::create_dir_all(image.join("bin")));
480480
builder.cp_r(&src.join("bin"), &image.join("bin"));
481481

482482
builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);
483483

484+
let libdir_relative = builder.libdir_relative(compiler);
485+
484486
// Copy runtime DLLs needed by the compiler
485-
if libdir != "bin" {
486-
for entry in builder.read_dir(&src.join(libdir)) {
487+
if libdir_relative.to_str() != Some("bin") {
488+
for entry in builder.read_dir(&libdir) {
487489
let name = entry.file_name();
488490
if let Some(s) = name.to_str() {
489491
if is_dylib(s) {
490-
builder.install(&entry.path(), &image.join(libdir), 0o644);
492+
builder.install(&entry.path(), &image.join(&libdir_relative), 0o644);
491493
}
492494
}
493495
}
@@ -516,7 +518,8 @@ impl Step for Rustc {
516518
.join("bin")
517519
.join(&exe);
518520
// for the rationale about this rename check `compile::copy_lld_to_sysroot`
519-
let dst = image.join("lib/rustlib")
521+
let dst = image.join(libdir_relative)
522+
.join("rustlib")
520523
.join(&*host)
521524
.join("bin")
522525
.join(&exe);

src/bootstrap/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ impl Build {
12751275
fn install(&self, src: &Path, dstdir: &Path, perms: u32) {
12761276
if self.config.dry_run { return; }
12771277
let dst = dstdir.join(src.file_name().unwrap());
1278+
self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst));
12781279
t!(fs::create_dir_all(dstdir));
12791280
drop(fs::remove_file(&dst));
12801281
{

0 commit comments

Comments
 (0)