Skip to content

Commit

Permalink
incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 1, 2023
1 parent ce48b71 commit 3edc53c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 113 deletions.
40 changes: 6 additions & 34 deletions build_system/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,8 @@ impl BuildArg {
}
}

fn build_sysroot_inner(
env: &HashMap<String, String>,
sysroot_panic_abort: bool,
sysroot_release_channel: bool,
config: &ConfigInfo,
start_dir: Option<&Path>,
) -> Result<(), String> {
let start_dir = start_dir.unwrap_or_else(|| Path::new("."));
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
let start_dir = Path::new("build_sysroot");
// Cleanup for previous run
// Clean target dir except for build scripts and incremental cache
let _ = walk_dir(
Expand Down Expand Up @@ -121,12 +115,11 @@ fn build_sysroot_inner(

// Builds libs
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
if sysroot_panic_abort {
if config.sysroot_panic_abort {
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
}
rustflags.push_str(" -Z force-unstable-if-unmarked");
let mut env = env.clone();
let channel = if sysroot_release_channel {
let channel = if config.sysroot_release_channel {
env.insert(
"RUSTFLAGS".to_string(),
format!("{} -Zmir-opt-level=3", rustflags),
Expand Down Expand Up @@ -194,21 +187,6 @@ fn build_sysroot_inner(
Ok(())
}

pub fn build_sysroot(
env: &HashMap<String, String>,
sysroot_panic_abort: bool,
sysroot_release_channel: bool,
config: &ConfigInfo,
) -> Result<(), String> {
build_sysroot_inner(
env,
sysroot_panic_abort,
sysroot_release_channel,
config,
Some(Path::new("build_sysroot")),
)
}

fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
let mut env = HashMap::new();

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

args.config_info
.setup(&mut env, &[], Some(&args.gcc_path))?;
args.config_info.setup(&mut env, Some(&args.gcc_path))?;

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

println!("[BUILD] sysroot");
build_sysroot(
&env,
args.config_info.sysroot_panic_abort,
args.config_info.sysroot_release_channel,
&args.config_info,
)?;
build_sysroot(&env, &args.config_info)?;
Ok(())
}

Expand Down
21 changes: 11 additions & 10 deletions build_system/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::{get_gcc_path, get_os_name, rustc_version_info, split_args};
use std::collections::HashMap;
use std::env as std_env;
use std::ffi::OsStr;

#[derive(Default)]
pub struct ConfigInfo {
Expand Down Expand Up @@ -32,7 +33,6 @@ impl ConfigInfo {
},
"--out-dir" => match args.next() {
Some(arg) if !arg.is_empty() => {
// env.insert("CARGO_TARGET_DIR".to_string(), arg.to_string());
self.cargo_target_dir = arg.to_string();
}
_ => return Err("Expected a value after `--out-dir`, found nothing".to_string()),
Expand All @@ -44,10 +44,17 @@ impl ConfigInfo {
Ok(true)
}

pub fn rustc_command_vec(&self) -> Vec<&dyn AsRef<OsStr>> {
let mut command: Vec<&dyn AsRef<OsStr>> = Vec::with_capacity(self.rustc_command.len());
for arg in self.rustc_command.iter() {
command.push(arg);
}
command
}

pub fn setup(
&mut self,
env: &mut HashMap<String, String>,
test_flags: &[String],
gcc_path: Option<&str>,
) -> Result<(), String> {
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
Expand Down Expand Up @@ -90,15 +97,10 @@ impl ConfigInfo {
let mut linker = None;

if self.host_triple != self.target_triple {
if self.target_triple == "m68k-unknown-linux-gnu" {
linker = Some("-Clinker=m68k-unknown-linux-gnu-gcc".to_string());
} else if self.target_triple == "aarch64-unknown-linux-gnu" {
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
linker = Some("-Clinker=aarch64-linux-gnu-gcc".to_string());
} else {
if self.target_triple.is_empty() {
return Err("Unknown non-native platform".to_string());
}

linker = Some(format!("-Clinker={}-gcc", self.target_triple));
self.run_in_vm = true;
}

Expand Down Expand Up @@ -162,7 +164,6 @@ impl ConfigInfo {
if !env.contains_key(&"FAT_LTO".to_string()) {
rustflags.push("-Clto=off".to_string());
}
rustflags.extend_from_slice(test_flags);
// FIXME(antoyo): remove once the atomic shim is gone
if os_name == "Darwin" {
rustflags.extend_from_slice(&[
Expand Down
Loading

0 comments on commit 3edc53c

Please sign in to comment.