Fix sysroot build
This commit is contained in:
parent
867ea12488
commit
db9b932314
@ -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;
|
||||
@ -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,
|
||||
@ -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());
|
||||
}
|
||||
@ -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]"#
|
||||
);
|
||||
@ -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(
|
||||
@ -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());
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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),
|
||||
}
|
||||
@ -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()
|
||||
@ -152,6 +170,9 @@ impl ConfigInfo {
|
||||
if let Some(cg_rustflags) = env.get("CG_RUSTFLAGS") {
|
||||
rustflags.extend_from_slice(&split_args(&cg_rustflags)?);
|
||||
}
|
||||
if let Some(test_flags) = env.get("TEST_FLAGS") {
|
||||
rustflags.extend_from_slice(&split_args(&test_flags)?);
|
||||
}
|
||||
|
||||
if let Some(linker) = linker {
|
||||
rustflags.push(linker.to_string());
|
||||
@ -223,6 +244,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."
|
||||
);
|
||||
|
@ -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,
|
||||
@ -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>,
|
||||
@ -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 {
|
||||
@ -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");
|
||||
@ -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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user