Skip to content

Commit b31b74e

Browse files
authored
Merge pull request rust-lang#1340 from bjorn3/non_rustup_build
Push up a lot of rustc and cargo references
2 parents 395eaa1 + 629eab7 commit b31b74e

12 files changed

+135
-100
lines changed

build_system/abi_cafe.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub(crate) fn run(
1818
sysroot_kind: SysrootKind,
1919
dirs: &Dirs,
2020
cg_clif_dylib: &Path,
21-
host_compiler: &Compiler,
21+
bootstrap_host_compiler: &Compiler,
2222
) {
2323
if !config::get_bool("testsuite.abi-cafe") {
24-
eprintln!("[SKIP] abi-cafe");
24+
eprintln!("[RUN] abi-cafe (skipped)");
2525
return;
2626
}
2727

@@ -31,15 +31,15 @@ pub(crate) fn run(
3131
channel,
3232
sysroot_kind,
3333
cg_clif_dylib,
34-
host_compiler,
35-
&host_compiler.triple,
34+
bootstrap_host_compiler,
35+
bootstrap_host_compiler.triple.clone(),
3636
);
3737

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

4040
let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
4141

42-
let mut cmd = ABI_CAFE.run(host_compiler, dirs);
42+
let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs);
4343
cmd.arg("--");
4444
cmd.arg("--pairs");
4545
cmd.args(pairs);

build_system/bench.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ pub(crate) static SIMPLE_RAYTRACER_LLVM: CargoProject =
2121
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
2222
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
2323

24-
pub(crate) fn benchmark(dirs: &Dirs, host_compiler: &Compiler) {
25-
benchmark_simple_raytracer(dirs, host_compiler);
24+
pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
25+
benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
2626
}
2727

28-
fn benchmark_simple_raytracer(dirs: &Dirs, host_compiler: &Compiler) {
28+
fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
2929
if std::process::Command::new("hyperfine").output().is_err() {
3030
eprintln!("Hyperfine not installed");
3131
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
3232
std::process::exit(1);
3333
}
3434

3535
eprintln!("[LLVM BUILD] simple-raytracer");
36-
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(host_compiler, dirs);
36+
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
3737
spawn_and_wait(build_cmd);
3838
fs::copy(
3939
SIMPLE_RAYTRACER_LLVM
4040
.target_dir(dirs)
41-
.join(&host_compiler.triple)
41+
.join(&bootstrap_host_compiler.triple)
4242
.join("debug")
4343
.join(get_file_name("main", "bin")),
4444
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),

build_system/build_backend.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "c
1010
pub(crate) fn build_backend(
1111
dirs: &Dirs,
1212
channel: &str,
13-
host_compiler: &Compiler,
13+
bootstrap_host_compiler: &Compiler,
1414
use_unstable_features: bool,
1515
) -> PathBuf {
16-
let mut cmd = CG_CLIF.build(&host_compiler, dirs);
16+
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
1717

1818
cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
1919

@@ -48,7 +48,7 @@ pub(crate) fn build_backend(
4848

4949
CG_CLIF
5050
.target_dir(dirs)
51-
.join(&host_compiler.triple)
51+
.join(&bootstrap_host_compiler.triple)
5252
.join(channel)
5353
.join(get_file_name("rustc_codegen_cranelift", "dylib"))
5454
}

build_system/build_sysroot.rs

+36-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::path::Path;
33
use std::process::{self, Command};
44

55
use super::path::{Dirs, RelPath};
6-
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
6+
use super::rustc_info::{
7+
get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
8+
};
79
use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
810
use super::SysrootKind;
911

@@ -17,15 +19,17 @@ pub(crate) fn build_sysroot(
1719
channel: &str,
1820
sysroot_kind: SysrootKind,
1921
cg_clif_dylib_src: &Path,
20-
host_compiler: &Compiler,
21-
target_triple: &str,
22-
) {
22+
bootstrap_host_compiler: &Compiler,
23+
target_triple: String,
24+
) -> Compiler {
2325
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
2426

2527
DIST_DIR.ensure_fresh(dirs);
2628
BIN_DIR.ensure_exists(dirs);
2729
LIB_DIR.ensure_exists(dirs);
2830

31+
let is_native = bootstrap_host_compiler.triple == target_triple;
32+
2933
// Copy the backend
3034
let cg_clif_dylib_path = if cfg!(windows) {
3135
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -42,32 +46,34 @@ pub(crate) fn build_sysroot(
4246
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
4347
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
4448

45-
let mut build_cargo_wrapper_cmd = Command::new("rustc");
49+
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
4650
build_cargo_wrapper_cmd
51+
.env("TOOLCHAIN_NAME", get_toolchain_name())
4752
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
4853
.arg("-o")
4954
.arg(DIST_DIR.to_path(dirs).join(wrapper_name))
5055
.arg("-g");
5156
spawn_and_wait(build_cargo_wrapper_cmd);
5257
}
5358

54-
let default_sysroot = super::rustc_info::get_default_sysroot();
59+
let default_sysroot = super::rustc_info::get_default_sysroot(&bootstrap_host_compiler.rustc);
5560

56-
let host_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&host_compiler.triple).join("lib");
57-
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib");
61+
let host_rustlib_lib =
62+
RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib");
63+
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&target_triple).join("lib");
5864
fs::create_dir_all(&host_rustlib_lib).unwrap();
5965
fs::create_dir_all(&target_rustlib_lib).unwrap();
6066

6167
if target_triple == "x86_64-pc-windows-gnu" {
62-
if !default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib").exists() {
68+
if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() {
6369
eprintln!(
6470
"The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
6571
to compile a sysroot for it.",
6672
);
6773
process::exit(1);
6874
}
6975
for file in fs::read_dir(
70-
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"),
76+
default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
7177
)
7278
.unwrap()
7379
{
@@ -83,7 +89,11 @@ pub(crate) fn build_sysroot(
8389
SysrootKind::None => {} // Nothing to do
8490
SysrootKind::Llvm => {
8591
for file in fs::read_dir(
86-
default_sysroot.join("lib").join("rustlib").join(&host_compiler.triple).join("lib"),
92+
default_sysroot
93+
.join("lib")
94+
.join("rustlib")
95+
.join(&bootstrap_host_compiler.triple)
96+
.join("lib"),
8797
)
8898
.unwrap()
8999
{
@@ -103,9 +113,9 @@ pub(crate) fn build_sysroot(
103113
try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap()));
104114
}
105115

106-
if target_triple != host_compiler.triple {
116+
if !is_native {
107117
for file in fs::read_dir(
108-
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"),
118+
default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
109119
)
110120
.unwrap()
111121
{
@@ -118,19 +128,19 @@ pub(crate) fn build_sysroot(
118128
build_clif_sysroot_for_triple(
119129
dirs,
120130
channel,
121-
host_compiler.clone(),
131+
bootstrap_host_compiler.clone(),
122132
&cg_clif_dylib_path,
123133
);
124134

125-
if host_compiler.triple != target_triple {
135+
if !is_native {
126136
build_clif_sysroot_for_triple(
127137
dirs,
128138
channel,
129139
{
130-
let mut target_compiler = host_compiler.clone();
131-
target_compiler.triple = target_triple.to_owned();
132-
target_compiler.set_cross_linker_and_runner();
133-
target_compiler
140+
let mut bootstrap_target_compiler = bootstrap_host_compiler.clone();
141+
bootstrap_target_compiler.triple = target_triple.clone();
142+
bootstrap_target_compiler.set_cross_linker_and_runner();
143+
bootstrap_target_compiler
134144
},
135145
&cg_clif_dylib_path,
136146
);
@@ -147,6 +157,12 @@ pub(crate) fn build_sysroot(
147157
}
148158
}
149159
}
160+
161+
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
162+
if !is_native {
163+
target_compiler.set_cross_linker_and_runner();
164+
}
165+
target_compiler
150166
}
151167

152168
pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
@@ -169,7 +185,7 @@ fn build_clif_sysroot_for_triple(
169185
process::exit(1);
170186
}
171187
Ok(source_version) => {
172-
let rustc_version = get_rustc_version();
188+
let rustc_version = get_rustc_version(&compiler.rustc);
173189
if source_version != rustc_version {
174190
eprintln!("The patched sysroot source is outdated");
175191
eprintln!("Source version: {}", source_version.trim());

build_system/mod.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn main() {
9797
}
9898
}
9999

100-
let host_compiler = Compiler::llvm_with_triple(
100+
let bootstrap_host_compiler = Compiler::bootstrap_with_triple(
101101
std::env::var("HOST_TRIPLE")
102102
.ok()
103103
.or_else(|| config::get_value("host"))
@@ -106,7 +106,7 @@ pub fn main() {
106106
let target_triple = std::env::var("TARGET_TRIPLE")
107107
.ok()
108108
.or_else(|| config::get_value("target"))
109-
.unwrap_or_else(|| host_compiler.triple.clone());
109+
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
110110

111111
// FIXME allow changing the location of these dirs using cli arguments
112112
let current_dir = std::env::current_dir().unwrap();
@@ -134,8 +134,15 @@ pub fn main() {
134134
process::exit(0);
135135
}
136136

137-
let cg_clif_dylib =
138-
build_backend::build_backend(&dirs, channel, &host_compiler, use_unstable_features);
137+
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
138+
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
139+
140+
let cg_clif_dylib = build_backend::build_backend(
141+
&dirs,
142+
channel,
143+
&bootstrap_host_compiler,
144+
use_unstable_features,
145+
);
139146
match command {
140147
Command::Prepare => {
141148
// Handled above
@@ -146,14 +153,20 @@ pub fn main() {
146153
channel,
147154
sysroot_kind,
148155
&cg_clif_dylib,
149-
&host_compiler,
150-
&target_triple,
156+
&bootstrap_host_compiler,
157+
target_triple.clone(),
151158
);
152159

153-
if host_compiler.triple == target_triple {
154-
abi_cafe::run(channel, sysroot_kind, &dirs, &cg_clif_dylib, &host_compiler);
160+
if bootstrap_host_compiler.triple == target_triple {
161+
abi_cafe::run(
162+
channel,
163+
sysroot_kind,
164+
&dirs,
165+
&cg_clif_dylib,
166+
&bootstrap_host_compiler,
167+
);
155168
} else {
156-
eprintln!("[SKIP] abi-cafe (cross-compilation not supported)");
169+
eprintln!("[RUN] abi-cafe (skipped, cross-compilation not supported)");
157170
return;
158171
}
159172
}
@@ -163,8 +176,8 @@ pub fn main() {
163176
channel,
164177
sysroot_kind,
165178
&cg_clif_dylib,
166-
&host_compiler,
167-
&target_triple,
179+
&bootstrap_host_compiler,
180+
target_triple,
168181
);
169182
}
170183
Command::Bench => {
@@ -173,10 +186,10 @@ pub fn main() {
173186
channel,
174187
sysroot_kind,
175188
&cg_clif_dylib,
176-
&host_compiler,
177-
&target_triple,
189+
&bootstrap_host_compiler,
190+
target_triple,
178191
);
179-
bench::benchmark(&dirs, &host_compiler);
192+
bench::benchmark(&dirs, &bootstrap_host_compiler);
180193
}
181194
}
182195
}

build_system/prepare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) fn prepare(dirs: &Dirs) {
3535
}
3636

3737
fn prepare_sysroot(dirs: &Dirs) {
38-
let sysroot_src_orig = get_default_sysroot().join("lib/rustlib/src/rust");
38+
let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust");
3939
assert!(sysroot_src_orig.exists());
4040

4141
eprintln!("[COPY] sysroot src");
@@ -50,7 +50,7 @@ fn prepare_sysroot(dirs: &Dirs) {
5050
&SYSROOT_SRC.to_path(dirs).join("library"),
5151
);
5252

53-
let rustc_version = get_rustc_version();
53+
let rustc_version = get_rustc_version(Path::new("rustc"));
5454
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
5555

5656
eprintln!("[GIT] init");

build_system/rustc_info.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::path::{Path, PathBuf};
22
use std::process::{Command, Stdio};
33

4-
pub(crate) fn get_rustc_version() -> String {
4+
pub(crate) fn get_rustc_version(rustc: &Path) -> String {
55
let version_info =
6-
Command::new("rustc").stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout;
6+
Command::new(rustc).stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout;
77
String::from_utf8(version_info).unwrap()
88
}
99

@@ -23,6 +23,16 @@ pub(crate) fn get_host_triple() -> String {
2323
.to_owned()
2424
}
2525

26+
pub(crate) fn get_toolchain_name() -> String {
27+
let active_toolchain = Command::new("rustup")
28+
.stderr(Stdio::inherit())
29+
.args(&["show", "active-toolchain"])
30+
.output()
31+
.unwrap()
32+
.stdout;
33+
String::from_utf8(active_toolchain).unwrap().trim().split_once(' ').unwrap().0.to_owned()
34+
}
35+
2636
pub(crate) fn get_cargo_path() -> PathBuf {
2737
let cargo_path = Command::new("rustup")
2838
.stderr(Stdio::inherit())
@@ -53,8 +63,8 @@ pub(crate) fn get_rustdoc_path() -> PathBuf {
5363
Path::new(String::from_utf8(rustc_path).unwrap().trim()).to_owned()
5464
}
5565

56-
pub(crate) fn get_default_sysroot() -> PathBuf {
57-
let default_sysroot = Command::new("rustc")
66+
pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf {
67+
let default_sysroot = Command::new(rustc)
5868
.stderr(Stdio::inherit())
5969
.args(&["--print", "sysroot"])
6070
.output()

0 commit comments

Comments
 (0)