Skip to content

Commit 5d29883

Browse files
committed
Move some libs to self-contained directory
1 parent 961974f commit 5d29883

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/bootstrap/compile.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ fn copy_self_contained_objects(
172172
compiler: &Compiler,
173173
target: Interned<String>,
174174
) -> Vec<(PathBuf, DependencyType)> {
175-
let libdir = builder.sysroot_libdir(*compiler, target);
175+
// cfg(bootstrap)
176+
// Remove when upgrading bootstrap compiler.
177+
let libdir_self_contained = if compiler.stage == 0 {
178+
builder.sysroot_libdir(*compiler, target).to_path_buf()
179+
} else {
180+
builder.sysroot_libdir(*compiler, target).join("self-contained")
181+
};
182+
t!(fs::create_dir_all(&libdir_self_contained));
176183
let mut target_deps = vec![];
177184

178185
// Copies the CRT objects.
@@ -207,7 +214,7 @@ fn copy_self_contained_objects(
207214
} else if target.contains("windows-gnu") {
208215
for obj in ["crt2.o", "dllcrt2.o"].iter() {
209216
let src = compiler_file(builder, builder.cc(target), target, obj);
210-
let target = libdir.join(obj);
217+
let target = libdir_self_contained.join(obj);
211218
builder.copy(&src, &target);
212219
target_deps.push((target, DependencyType::TargetSelfContained));
213220
}
@@ -844,14 +851,17 @@ pub fn add_to_sysroot(
844851
sysroot_host_dst: &Path,
845852
stamp: &Path,
846853
) {
854+
let self_contained_dst = &sysroot_dst.join("self-contained");
847855
t!(fs::create_dir_all(&sysroot_dst));
848856
t!(fs::create_dir_all(&sysroot_host_dst));
857+
t!(fs::create_dir_all(&self_contained_dst));
849858
for (path, dependency_type) in builder.read_stamp_file(stamp) {
850-
if dependency_type == DependencyType::Host {
851-
builder.copy(&path, &sysroot_host_dst.join(path.file_name().unwrap()));
852-
} else {
853-
builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
854-
}
859+
let dst = match dependency_type {
860+
DependencyType::Host => sysroot_host_dst,
861+
DependencyType::Target => sysroot_dst,
862+
DependencyType::TargetSelfContained => self_contained_dst,
863+
};
864+
builder.copy(&path, &dst.join(path.file_name().unwrap()));
855865
}
856866
}
857867

src/bootstrap/dist.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ fn make_win_dist(
321321
);
322322

323323
//Copy platform libs to platform-specific lib directory
324-
let target_lib_dir = plat_root.join("lib").join("rustlib").join(target_triple).join("lib");
324+
let target_lib_dir = plat_root
325+
.join("lib")
326+
.join("rustlib")
327+
.join(target_triple)
328+
.join("lib")
329+
.join("self-contained");
325330
fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
326331
for src in target_libs {
327332
builder.copy_to_folder(&src, &target_lib_dir);
@@ -650,9 +655,13 @@ fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
650655
/// Copy stamped files into an image's `target/lib` directory.
651656
fn copy_target_libs(builder: &Builder<'_>, target: &str, image: &Path, stamp: &Path) {
652657
let dst = image.join("lib/rustlib").join(target).join("lib");
658+
let self_contained_dst = dst.join("self-contained");
653659
t!(fs::create_dir_all(&dst));
660+
t!(fs::create_dir_all(&self_contained_dst));
654661
for (path, dependency_type) in builder.read_stamp_file(stamp) {
655-
if dependency_type != DependencyType::Host || builder.config.build == target {
662+
if dependency_type == DependencyType::TargetSelfContained {
663+
builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
664+
} else if dependency_type == DependencyType::Target || builder.config.build == target {
656665
builder.copy(&path, &dst.join(path.file_name().unwrap()));
657666
}
658667
}

src/librustc_codegen_ssa/back/link.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,10 @@ fn get_object_file_path(sess: &Session, name: &str) -> PathBuf {
10751075
if file_path.exists() {
10761076
return file_path;
10771077
}
1078+
let file_path = fs.get_lib_path().join("self-contained").join(name);
1079+
if file_path.exists() {
1080+
return file_path;
1081+
}
10781082
for search_path in fs.search_paths() {
10791083
let file_path = search_path.dir.join(name);
10801084
if file_path.exists() {
@@ -1470,6 +1474,9 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session) {
14701474
// The location of crates will be determined as needed.
14711475
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
14721476
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
1477+
1478+
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path().join("self-contained");
1479+
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
14731480
}
14741481

14751482
/// Add options making relocation sections in the produced ELF files read-only

0 commit comments

Comments
 (0)