Skip to content

Commit 4dbafef

Browse files
committed
Return Compiler from build_sysroot
1 parent bbb7a3b commit 4dbafef

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

build_system/abi_cafe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) fn run(
3232
sysroot_kind,
3333
cg_clif_dylib,
3434
bootstrap_host_compiler,
35-
&bootstrap_host_compiler.triple,
35+
bootstrap_host_compiler.triple.clone(),
3636
);
3737

3838
eprintln!("Running abi-cafe");

build_system/build_sysroot.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ pub(crate) fn build_sysroot(
1818
sysroot_kind: SysrootKind,
1919
cg_clif_dylib_src: &Path,
2020
bootstrap_host_compiler: &Compiler,
21-
target_triple: &str,
22-
) {
21+
target_triple: String,
22+
) -> Compiler {
2323
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
2424

2525
DIST_DIR.ensure_fresh(dirs);
2626
BIN_DIR.ensure_exists(dirs);
2727
LIB_DIR.ensure_exists(dirs);
2828

29+
let is_native = bootstrap_host_compiler.triple == target_triple;
30+
2931
// Copy the backend
3032
let cg_clif_dylib_path = if cfg!(windows) {
3133
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -55,20 +57,20 @@ pub(crate) fn build_sysroot(
5557

5658
let host_rustlib_lib =
5759
RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib");
58-
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib");
60+
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&target_triple).join("lib");
5961
fs::create_dir_all(&host_rustlib_lib).unwrap();
6062
fs::create_dir_all(&target_rustlib_lib).unwrap();
6163

6264
if target_triple == "x86_64-pc-windows-gnu" {
63-
if !default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib").exists() {
65+
if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() {
6466
eprintln!(
6567
"The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
6668
to compile a sysroot for it.",
6769
);
6870
process::exit(1);
6971
}
7072
for file in fs::read_dir(
71-
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"),
73+
default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
7274
)
7375
.unwrap()
7476
{
@@ -108,9 +110,9 @@ pub(crate) fn build_sysroot(
108110
try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap()));
109111
}
110112

111-
if target_triple != bootstrap_host_compiler.triple {
113+
if !is_native {
112114
for file in fs::read_dir(
113-
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"),
115+
default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
114116
)
115117
.unwrap()
116118
{
@@ -127,13 +129,13 @@ pub(crate) fn build_sysroot(
127129
&cg_clif_dylib_path,
128130
);
129131

130-
if bootstrap_host_compiler.triple != target_triple {
132+
if !is_native {
131133
build_clif_sysroot_for_triple(
132134
dirs,
133135
channel,
134136
{
135137
let mut bootstrap_target_compiler = bootstrap_host_compiler.clone();
136-
bootstrap_target_compiler.triple = target_triple.to_owned();
138+
bootstrap_target_compiler.triple = target_triple.clone();
137139
bootstrap_target_compiler.set_cross_linker_and_runner();
138140
bootstrap_target_compiler
139141
},
@@ -152,6 +154,12 @@ pub(crate) fn build_sysroot(
152154
}
153155
}
154156
}
157+
158+
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
159+
if !is_native {
160+
target_compiler.set_cross_linker_and_runner();
161+
}
162+
target_compiler
155163
}
156164

157165
pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");

build_system/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn main() {
154154
sysroot_kind,
155155
&cg_clif_dylib,
156156
&bootstrap_host_compiler,
157-
&target_triple,
157+
target_triple.clone(),
158158
);
159159

160160
if bootstrap_host_compiler.triple == target_triple {
@@ -177,7 +177,7 @@ pub fn main() {
177177
sysroot_kind,
178178
&cg_clif_dylib,
179179
&bootstrap_host_compiler,
180-
&target_triple,
180+
target_triple,
181181
);
182182
}
183183
Command::Bench => {
@@ -187,7 +187,7 @@ pub fn main() {
187187
sysroot_kind,
188188
&cg_clif_dylib,
189189
&bootstrap_host_compiler,
190-
&target_triple,
190+
target_triple,
191191
);
192192
bench::benchmark(&dirs, &bootstrap_host_compiler);
193193
}

build_system/tests.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -242,21 +242,21 @@ pub(crate) fn run_tests(
242242
sysroot_kind: SysrootKind,
243243
cg_clif_dylib: &Path,
244244
bootstrap_host_compiler: &Compiler,
245-
target_triple: &str,
245+
target_triple: String,
246246
) {
247-
let runner =
248-
TestRunner::new(dirs.clone(), target_triple.to_owned(), get_host_triple() == target_triple);
249-
250247
if config::get_bool("testsuite.no_sysroot") {
251-
build_sysroot::build_sysroot(
248+
let target_compiler = build_sysroot::build_sysroot(
252249
dirs,
253250
channel,
254251
SysrootKind::None,
255252
cg_clif_dylib,
256253
bootstrap_host_compiler,
257-
&target_triple,
254+
target_triple.clone(),
258255
);
259256

257+
let runner =
258+
TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
259+
260260
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
261261
runner.run_testsuite(NO_SYSROOT_SUITE);
262262
} else {
@@ -267,26 +267,29 @@ pub(crate) fn run_tests(
267267
let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot");
268268

269269
if run_base_sysroot || run_extended_sysroot {
270-
build_sysroot::build_sysroot(
270+
let target_compiler = build_sysroot::build_sysroot(
271271
dirs,
272272
channel,
273273
sysroot_kind,
274274
cg_clif_dylib,
275275
bootstrap_host_compiler,
276-
&target_triple,
276+
target_triple.clone(),
277277
);
278-
}
279278

280-
if run_base_sysroot {
281-
runner.run_testsuite(BASE_SYSROOT_SUITE);
282-
} else {
283-
eprintln!("[SKIP] base_sysroot tests");
284-
}
279+
let runner =
280+
TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
285281

286-
if run_extended_sysroot {
287-
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
288-
} else {
289-
eprintln!("[SKIP] extended_sysroot tests");
282+
if run_base_sysroot {
283+
runner.run_testsuite(BASE_SYSROOT_SUITE);
284+
} else {
285+
eprintln!("[SKIP] base_sysroot tests");
286+
}
287+
288+
if run_extended_sysroot {
289+
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
290+
} else {
291+
eprintln!("[SKIP] extended_sysroot tests");
292+
}
290293
}
291294
}
292295

@@ -298,11 +301,7 @@ struct TestRunner {
298301
}
299302

300303
impl TestRunner {
301-
pub fn new(dirs: Dirs, target_triple: String, is_native: bool) -> Self {
302-
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
303-
if !is_native {
304-
target_compiler.set_cross_linker_and_runner();
305-
}
304+
pub fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self {
306305
if let Ok(rustflags) = env::var("RUSTFLAGS") {
307306
target_compiler.rustflags.push(' ');
308307
target_compiler.rustflags.push_str(&rustflags);

0 commit comments

Comments
 (0)