Skip to content

Commit bc67321

Browse files
committed
Reduce usage of RelPath in build_sysroot
1 parent f204181 commit bc67321

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

build_system/build_sysroot.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ use crate::utils::{
1010
};
1111
use crate::{config, CodegenBackend, SysrootKind};
1212

13-
static DIST_DIR: RelPath = RelPath::DIST;
14-
static BIN_DIR: RelPath = RelPath::DIST.join("bin");
15-
static LIB_DIR: RelPath = RelPath::DIST.join("lib");
16-
1713
pub(crate) fn build_sysroot(
1814
dirs: &Dirs,
1915
sysroot_kind: SysrootKind,
@@ -26,9 +22,12 @@ pub(crate) fn build_sysroot(
2622

2723
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
2824

29-
DIST_DIR.ensure_fresh(dirs);
30-
BIN_DIR.ensure_exists(dirs);
31-
LIB_DIR.ensure_exists(dirs);
25+
let dist_dir = RelPath::DIST.to_path(dirs);
26+
27+
remove_dir_if_exists(&dist_dir);
28+
fs::create_dir_all(&dist_dir).unwrap();
29+
fs::create_dir_all(dist_dir.join("bin")).unwrap();
30+
fs::create_dir_all(dist_dir.join("lib")).unwrap();
3231

3332
let is_native = bootstrap_host_compiler.triple == target_triple;
3433

@@ -38,11 +37,10 @@ pub(crate) fn build_sysroot(
3837
let cg_clif_dylib_path = if cfg!(windows) {
3938
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
4039
// binaries.
41-
BIN_DIR
40+
dist_dir.join("bin")
4241
} else {
43-
LIB_DIR
42+
dist_dir.join("lib")
4443
}
45-
.to_path(dirs)
4644
.join(src_path.file_name().unwrap());
4745
try_hard_link(src_path, &cg_clif_dylib_path);
4846
CodegenBackend::Local(cg_clif_dylib_path)
@@ -56,7 +54,7 @@ pub(crate) fn build_sysroot(
5654
let wrapper_name = wrapper_base_name.replace("____", wrapper);
5755

5856
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
59-
let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name);
57+
let wrapper_path = dist_dir.join(&wrapper_name);
6058
build_cargo_wrapper_cmd
6159
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
6260
.arg("-o")
@@ -79,7 +77,7 @@ pub(crate) fn build_sysroot(
7977
build_cargo_wrapper_cmd.env("BUILTIN_BACKEND", name);
8078
}
8179
spawn_and_wait(build_cargo_wrapper_cmd);
82-
try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
80+
try_hard_link(wrapper_path, dist_dir.join("bin").join(wrapper_name));
8381
}
8482

8583
let host = build_sysroot_for_triple(
@@ -88,7 +86,7 @@ pub(crate) fn build_sysroot(
8886
&cg_clif_dylib_path,
8987
sysroot_kind,
9088
);
91-
host.install_into_sysroot(&DIST_DIR.to_path(dirs));
89+
host.install_into_sysroot(&dist_dir);
9290

9391
if !is_native {
9492
build_sysroot_for_triple(
@@ -102,24 +100,21 @@ pub(crate) fn build_sysroot(
102100
&cg_clif_dylib_path,
103101
sysroot_kind,
104102
)
105-
.install_into_sysroot(&DIST_DIR.to_path(dirs));
103+
.install_into_sysroot(&dist_dir);
106104
}
107105

108106
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
109107
// libstd.
110108
for lib in host.libs {
111109
let filename = lib.file_name().unwrap().to_str().unwrap();
112110
if filename.contains("std-") && !filename.contains(".rlib") {
113-
try_hard_link(&lib, LIB_DIR.to_path(dirs).join(lib.file_name().unwrap()));
111+
try_hard_link(&lib, dist_dir.join("lib").join(lib.file_name().unwrap()));
114112
}
115113
}
116114

117115
let mut target_compiler = {
118-
let dirs: &Dirs = &dirs;
119-
let rustc_clif =
120-
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif"));
121-
let rustdoc_clif =
122-
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif"));
116+
let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif"));
117+
let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif"));
123118

124119
Compiler {
125120
cargo: bootstrap_host_compiler.cargo.clone(),

0 commit comments

Comments
 (0)