Skip to content

Commit 5ddf3d3

Browse files
committed
Reduce usage of RelPath in build_sysroot
1 parent eebb569 commit 5ddf3d3

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

build_system/build_sysroot.rs

Lines changed: 9 additions & 15 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("bin");
15-
static LIB_DIR: RelPath = RelPath::dist("lib");
16-
1713
pub(crate) fn build_sysroot(
1814
dirs: &Dirs,
1915
sysroot_kind: SysrootKind,
@@ -28,8 +24,8 @@ pub(crate) fn build_sysroot(
2824

2925
remove_dir_if_exists(&dirs.dist_dir);
3026
fs::create_dir_all(&dirs.dist_dir).unwrap();
31-
fs::create_dir_all(BIN_DIR.to_path(dirs)).unwrap();
32-
fs::create_dir_all(LIB_DIR.to_path(dirs)).unwrap();
27+
fs::create_dir_all(dirs.dist_dir.join("bin")).unwrap();
28+
fs::create_dir_all(dirs.dist_dir.join("lib")).unwrap();
3329

3430
let is_native = bootstrap_host_compiler.triple == target_triple;
3531

@@ -39,11 +35,10 @@ pub(crate) fn build_sysroot(
3935
let cg_clif_dylib_path = if cfg!(windows) {
4036
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
4137
// binaries.
42-
BIN_DIR
38+
dirs.dist_dir.join("bin")
4339
} else {
44-
LIB_DIR
40+
dirs.dist_dir.join("lib")
4541
}
46-
.to_path(dirs)
4742
.join(src_path.file_name().unwrap());
4843
try_hard_link(src_path, &cg_clif_dylib_path);
4944
CodegenBackend::Local(cg_clif_dylib_path)
@@ -57,7 +52,7 @@ pub(crate) fn build_sysroot(
5752
let wrapper_name = wrapper_base_name.replace("____", wrapper);
5853

5954
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
60-
let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name);
55+
let wrapper_path = dirs.dist_dir.join(&wrapper_name);
6156
build_cargo_wrapper_cmd
6257
.arg(dirs.source_dir.join("scripts").join(&format!("{wrapper}.rs")))
6358
.arg("-o")
@@ -80,7 +75,7 @@ pub(crate) fn build_sysroot(
8075
build_cargo_wrapper_cmd.env("BUILTIN_BACKEND", name);
8176
}
8277
spawn_and_wait(build_cargo_wrapper_cmd);
83-
try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
78+
try_hard_link(wrapper_path, dirs.dist_dir.join("bin").join(wrapper_name));
8479
}
8580

8681
let host = build_sysroot_for_triple(
@@ -89,7 +84,7 @@ pub(crate) fn build_sysroot(
8984
&cg_clif_dylib_path,
9085
sysroot_kind,
9186
);
92-
host.install_into_sysroot(&DIST_DIR.to_path(dirs));
87+
host.install_into_sysroot(&dirs.dist_dir);
9388

9489
if !is_native {
9590
build_sysroot_for_triple(
@@ -103,20 +98,19 @@ pub(crate) fn build_sysroot(
10398
&cg_clif_dylib_path,
10499
sysroot_kind,
105100
)
106-
.install_into_sysroot(&DIST_DIR.to_path(dirs));
101+
.install_into_sysroot(&dirs.dist_dir);
107102
}
108103

109104
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
110105
// libstd.
111106
for lib in host.libs {
112107
let filename = lib.file_name().unwrap().to_str().unwrap();
113108
if filename.contains("std-") && !filename.contains(".rlib") {
114-
try_hard_link(&lib, LIB_DIR.to_path(dirs).join(lib.file_name().unwrap()));
109+
try_hard_link(&lib, dirs.dist_dir.join("lib").join(lib.file_name().unwrap()));
115110
}
116111
}
117112

118113
let mut target_compiler = {
119-
let dirs: &Dirs = &dirs;
120114
let rustc_clif = dirs.dist_dir.join(wrapper_base_name.replace("____", "rustc-clif"));
121115
let rustdoc_clif = dirs.dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif"));
122116

build_system/path.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub(crate) enum PathBase {
1818
Source,
1919
Download,
2020
Build,
21-
Dist,
2221
}
2322

2423
impl PathBase {
@@ -27,7 +26,6 @@ impl PathBase {
2726
PathBase::Source => dirs.source_dir.clone(),
2827
PathBase::Download => dirs.download_dir.clone(),
2928
PathBase::Build => dirs.build_dir.clone(),
30-
PathBase::Dist => dirs.dist_dir.clone(),
3129
}
3230
}
3331
}
@@ -51,10 +49,6 @@ impl RelPath {
5149
RelPath { base: PathBase::Build, suffix }
5250
}
5351

54-
pub(crate) const fn dist(suffix: &'static str) -> RelPath {
55-
RelPath { base: PathBase::Dist, suffix }
56-
}
57-
5852
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
5953
self.base.to_path(dirs).join(self.suffix)
6054
}

0 commit comments

Comments
 (0)