Skip to content

Commit

Permalink
Fix sysroot build
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 13, 2023
1 parent 867ea12 commit e756915
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
8 changes: 3 additions & 5 deletions build_system/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::ConfigInfo;
use crate::config::{Channel, ConfigInfo};
use crate::utils::{get_gcc_path, run_command, run_command_with_output_and_env, walk_dir};
use std::collections::HashMap;
use std::ffi::OsStr;
Expand All @@ -7,7 +7,6 @@ use std::path::Path;

#[derive(Default)]
struct BuildArg {
codegen_release_channel: bool,
flags: Vec<String>,
gcc_path: String,
config_info: ConfigInfo,
Expand All @@ -25,7 +24,6 @@ impl BuildArg {

while let Some(arg) = args.next() {
match arg.as_str() {
"--release" => build_arg.codegen_release_channel = true,
"--no-default-features" => {
build_arg.flags.push("--no-default-features".to_string());
}
Expand Down Expand Up @@ -58,7 +56,6 @@ impl BuildArg {
r#"
`build` command help:
--release : Build codegen in release mode
--no-default-features : Add `--no-default-features` flag
--features [arg] : Add a new feature [arg]"#
);
Expand Down Expand Up @@ -118,6 +115,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
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 config.sysroot_release_channel {
env.insert(
Expand Down Expand Up @@ -194,7 +192,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
env.insert("LIBRARY_PATH".to_string(), args.gcc_path.clone());

let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
if args.codegen_release_channel {
if args.config_info.channel == Channel::Release {
command.push(&"--release");
env.insert("CHANNEL".to_string(), "release".to_string());
env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
Expand Down
21 changes: 20 additions & 1 deletion build_system/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ use std::collections::HashMap;
use std::env as std_env;
use std::ffi::OsStr;

#[derive(Default, PartialEq, Eq, Clone, Copy, Debug)]
pub enum Channel {
#[default]
Debug,
Release,
}

impl Channel {
pub fn as_str(self) -> &'static str {
match self {
Self::Debug => "debug",
Self::Release => "release",
}
}
}

#[derive(Default, Debug)]
pub struct ConfigInfo {
pub target_triple: String,
Expand All @@ -12,6 +28,7 @@ pub struct ConfigInfo {
pub cargo_target_dir: String,
pub dylib_ext: String,
pub sysroot_release_channel: bool,
pub channel: Channel,
pub sysroot_panic_abort: bool,
pub cg_backend_path: String,
pub sysroot_path: String,
Expand Down Expand Up @@ -40,6 +57,7 @@ impl ConfigInfo {
_ => return Err("Expected a value after `--out-dir`, found nothing".to_string()),
},
"--release-sysroot" => self.sysroot_release_channel = true,
"--release" => self.channel = Channel::Release,
"--sysroot-panic-abort" => self.sysroot_panic_abort = true,
_ => return Ok(false),
}
Expand Down Expand Up @@ -108,7 +126,7 @@ impl ConfigInfo {

let current_dir =
std_env::current_dir().map_err(|error| format!("`current_dir` failed: {:?}", error))?;
let channel = if self.sysroot_release_channel {
let channel = if self.channel == Channel::Release {
"release"
} else if let Some(channel) = env.get("CHANNEL") {
channel.as_str()
Expand Down Expand Up @@ -223,6 +241,7 @@ impl ConfigInfo {
"\
--target-triple [arg] : Set the target triple to [arg]
--out-dir : Location where the files will be generated
--release : Build in release mode
--release-sysroot : Build sysroot in release mode
--sysroot-panic-abort : Build the sysroot without unwinding support."
);
Expand Down
27 changes: 3 additions & 24 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::build;
use crate::config::ConfigInfo;
use crate::config::{Channel, ConfigInfo};
use crate::utils::{
get_gcc_path, get_toolchain, remove_file, run_command, run_command_with_env,
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
Expand Down Expand Up @@ -104,28 +104,11 @@ fn show_usage() {
println!(" --help : Show this help");
}

#[derive(Default, PartialEq, Eq, Clone, Copy, Debug)]
enum Channel {
#[default]
Debug,
Release,
}

impl Channel {
pub fn as_str(self) -> &'static str {
match self {
Self::Debug => "debug",
Self::Release => "release",
}
}
}

#[derive(Default, Debug)]
struct TestArg {
no_default_features: bool,
build_only: bool,
gcc_path: String,
channel: Channel,
use_backend: bool,
runners: BTreeSet<String>,
flags: Vec<String>,
Expand All @@ -147,10 +130,6 @@ impl TestArg {

while let Some(arg) = args.next() {
match arg.as_str() {
"--release" => {
test_arg.channel = Channel::Release;
test_arg.config_info.sysroot_release_channel = true;
}
"--no-default-features" => {
// To prevent adding it more than once.
if !test_arg.no_default_features {
Expand Down Expand Up @@ -233,7 +212,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
}
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
let mut tmp_env;
let env = if args.channel == Channel::Release {
let env = if args.config_info.channel == Channel::Release {
tmp_env = env.clone();
tmp_env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
command.push(&"--release");
Expand Down Expand Up @@ -613,7 +592,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
pwd = std::env::current_dir()
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
.display(),
channel = args.channel.as_str(),
channel = args.config_info.channel.as_str(),
dylib_ext = args.config_info.dylib_ext,
)
.as_str(),
Expand Down

0 comments on commit e756915

Please sign in to comment.