Skip to content

Commit ebb7aa0

Browse files
Apply suggestions
1 parent 996635b commit ebb7aa0

File tree

5 files changed

+156
-190
lines changed

5 files changed

+156
-190
lines changed

build_system/src/build.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,8 @@ impl BuildArg {
6767
}
6868
}
6969

70-
fn build_sysroot_inner(
71-
env: &HashMap<String, String>,
72-
sysroot_panic_abort: bool,
73-
sysroot_release_channel: bool,
74-
config: &ConfigInfo,
75-
start_dir: Option<&Path>,
76-
) -> Result<(), String> {
77-
let start_dir = start_dir.unwrap_or_else(|| Path::new("."));
70+
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
71+
let start_dir = Path::new("build_sysroot");
7872
// Cleanup for previous run
7973
// Clean target dir except for build scripts and incremental cache
8074
let _ = walk_dir(
@@ -121,12 +115,11 @@ fn build_sysroot_inner(
121115

122116
// Builds libs
123117
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
124-
if sysroot_panic_abort {
118+
if config.sysroot_panic_abort {
125119
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
126120
}
127-
rustflags.push_str(" -Z force-unstable-if-unmarked");
128121
let mut env = env.clone();
129-
let channel = if sysroot_release_channel {
122+
let channel = if config.sysroot_release_channel {
130123
env.insert(
131124
"RUSTFLAGS".to_string(),
132125
format!("{} -Zmir-opt-level=3", rustflags),
@@ -194,21 +187,6 @@ fn build_sysroot_inner(
194187
Ok(())
195188
}
196189

197-
pub fn build_sysroot(
198-
env: &HashMap<String, String>,
199-
sysroot_panic_abort: bool,
200-
sysroot_release_channel: bool,
201-
config: &ConfigInfo,
202-
) -> Result<(), String> {
203-
build_sysroot_inner(
204-
env,
205-
sysroot_panic_abort,
206-
sysroot_release_channel,
207-
config,
208-
Some(Path::new("build_sysroot")),
209-
)
210-
}
211-
212190
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
213191
let mut env = HashMap::new();
214192

@@ -229,8 +207,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
229207
}
230208
run_command_with_output_and_env(&command, None, Some(&env))?;
231209

232-
args.config_info
233-
.setup(&mut env, &[], Some(&args.gcc_path))?;
210+
args.config_info.setup(&mut env, Some(&args.gcc_path))?;
234211

235212
// We voluntarily ignore the error.
236213
let _ = fs::remove_dir_all("target/out");
@@ -243,12 +220,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
243220
})?;
244221

245222
println!("[BUILD] sysroot");
246-
build_sysroot(
247-
&env,
248-
args.config_info.sysroot_panic_abort,
249-
args.config_info.sysroot_release_channel,
250-
&args.config_info,
251-
)?;
223+
build_sysroot(&env, &args.config_info)?;
252224
Ok(())
253225
}
254226

build_system/src/config.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::utils::{get_gcc_path, get_os_name, rustc_version_info, split_args};
22
use std::collections::HashMap;
33
use std::env as std_env;
4+
use std::ffi::OsStr;
45

5-
#[derive(Default)]
6+
#[derive(Default, Debug)]
67
pub struct ConfigInfo {
78
pub target_triple: String,
89
pub host_triple: String,
@@ -32,7 +33,6 @@ impl ConfigInfo {
3233
},
3334
"--out-dir" => match args.next() {
3435
Some(arg) if !arg.is_empty() => {
35-
// env.insert("CARGO_TARGET_DIR".to_string(), arg.to_string());
3636
self.cargo_target_dir = arg.to_string();
3737
}
3838
_ => return Err("Expected a value after `--out-dir`, found nothing".to_string()),
@@ -44,10 +44,17 @@ impl ConfigInfo {
4444
Ok(true)
4545
}
4646

47+
pub fn rustc_command_vec(&self) -> Vec<&dyn AsRef<OsStr>> {
48+
let mut command: Vec<&dyn AsRef<OsStr>> = Vec::with_capacity(self.rustc_command.len());
49+
for arg in self.rustc_command.iter() {
50+
command.push(arg);
51+
}
52+
command
53+
}
54+
4755
pub fn setup(
4856
&mut self,
4957
env: &mut HashMap<String, String>,
50-
test_flags: &[String],
5158
gcc_path: Option<&str>,
5259
) -> Result<(), String> {
5360
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
@@ -90,15 +97,10 @@ impl ConfigInfo {
9097
let mut linker = None;
9198

9299
if self.host_triple != self.target_triple {
93-
if self.target_triple == "m68k-unknown-linux-gnu" {
94-
linker = Some("-Clinker=m68k-unknown-linux-gnu-gcc".to_string());
95-
} else if self.target_triple == "aarch64-unknown-linux-gnu" {
96-
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
97-
linker = Some("-Clinker=aarch64-linux-gnu-gcc".to_string());
98-
} else {
100+
if self.target_triple.is_empty() {
99101
return Err("Unknown non-native platform".to_string());
100102
}
101-
103+
linker = Some(format!("-Clinker={}-gcc", self.target_triple));
102104
self.run_in_vm = true;
103105
}
104106

@@ -145,7 +147,7 @@ impl ConfigInfo {
145147

146148
// This environment variable is useful in case we want to change options of rustc commands.
147149
if let Some(cg_rustflags) = env.get("CG_RUSTFLAGS") {
148-
rustflags.extend_from_slice(&split_args(&cg_rustflags));
150+
rustflags.extend_from_slice(&split_args(&cg_rustflags)?);
149151
}
150152

151153
if let Some(linker) = linker {
@@ -162,7 +164,6 @@ impl ConfigInfo {
162164
if !env.contains_key(&"FAT_LTO".to_string()) {
163165
rustflags.push("-Clto=off".to_string());
164166
}
165-
rustflags.extend_from_slice(test_flags);
166167
// FIXME(antoyo): remove once the atomic shim is gone
167168
if os_name == "Darwin" {
168169
rustflags.extend_from_slice(&[

build_system/src/prepare.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::rustc_info::get_rustc_path;
2-
use crate::utils::{cargo_install, git_clone, run_command, run_command_with_output, walk_dir};
2+
use crate::utils::{
3+
cargo_install, git_clone, remove_file, run_command, run_command_with_output, walk_dir,
4+
};
35

46
use std::fs;
57
use std::path::Path;
@@ -137,8 +139,7 @@ fn build_raytracer(repo_dir: &Path) -> Result<(), String> {
137139
run_command(&[&"cargo", &"build"], Some(repo_dir))?;
138140
let mv_target = repo_dir.join("raytracer_cg_llvm");
139141
if mv_target.is_file() {
140-
std::fs::remove_file(&mv_target)
141-
.map_err(|e| format!("Failed to remove file `{}`: {e:?}", mv_target.display()))?;
142+
remove_file(&mv_target)?;
142143
}
143144
run_command(
144145
&[&"mv", &"target/debug/main", &"raytracer_cg_llvm"],

0 commit comments

Comments
 (0)