Correctly handle "master" feature

This commit is contained in:
Guillaume Gomez 2024-02-21 13:30:04 +01:00
parent e785093382
commit b87de7325f
3 changed files with 46 additions and 34 deletions

View File

@ -19,9 +19,6 @@ fn new() -> Result<Option<Self>, String> {
while let Some(arg) = args.next() {
match arg.as_str() {
"--no-default-features" => {
build_arg.flags.push("--no-default-features".to_string());
}
"--features" => {
if let Some(arg) = args.next() {
build_arg.flags.push("--features".to_string());
@ -51,7 +48,6 @@ fn usage() {
r#"
`build` command help:
--no-default-features : Add `--no-default-features` flag
--features [arg] : Add a new feature [arg]"#
);
ConfigInfo::show_usage();
@ -111,6 +107,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
}
rustflags.push_str(" -Z force-unstable-if-unmarked");
if config.no_default_features {
rustflags.push_str(" -Csymbol-mangling-version=v0");
}
let mut env = env.clone();
let channel = if config.sysroot_release_channel {
env.insert(
@ -193,6 +192,13 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
args.config_info.gcc_path.clone(),
);
if args.config_info.no_default_features {
env.insert(
"RUSTFLAGS".to_string(),
"-Csymbol-mangling-version=v0".to_string(),
);
}
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
if args.config_info.channel == Channel::Release {
command.push(&"--release");

View File

@ -127,6 +127,7 @@ pub struct ConfigInfo {
// Needed for the `info` command which doesn't want to actually download the lib if needed,
// just to set the `gcc_path` field to display it.
pub no_download: bool,
pub no_default_features: bool,
}
impl ConfigInfo {
@ -177,6 +178,7 @@ pub fn parse_argument(
return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string())
}
},
"--no-default-features" => self.no_default_features = true,
_ => return Ok(false),
}
Ok(true)
@ -416,8 +418,9 @@ pub fn setup(
rustflags.push(linker.to_string());
}
#[cfg(not(feature="master"))]
rustflags.push("-Csymbol-mangling-version=v0".to_string());
if self.no_default_features {
rustflags.push("-Csymbol-mangling-version=v0".to_string());
}
rustflags.extend_from_slice(&[
"-Cdebuginfo=2".to_string(),
@ -495,7 +498,8 @@ pub fn show_usage() {
--sysroot-panic-abort : Build the sysroot without unwinding support
--config-file : Location of the config file to be used
--cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
when ran from another directory)"
when ran from another directory)
--no-default-features : Add `--no-default-features` flag to cargo commands"
);
}
}

View File

@ -90,7 +90,6 @@ fn show_usage() {
--release : Build codegen in release mode
--sysroot-panic-abort : Build the sysroot without unwinding support.
--no-default-features : Add `--no-default-features` flag
--features [arg] : Add a new feature [arg]
--use-system-gcc : Use system installed libgccjit
--build-only : Only build rustc_codegen_gcc then exits
@ -110,7 +109,6 @@ fn show_usage() {
#[derive(Default, Debug)]
struct TestArg {
no_default_features: bool,
build_only: bool,
use_system_gcc: bool,
runners: BTreeSet<String>,
@ -132,13 +130,6 @@ fn new() -> Result<Option<Self>, String> {
while let Some(arg) = args.next() {
match arg.as_str() {
"--no-default-features" => {
// To prevent adding it more than once.
if !test_arg.no_default_features {
test_arg.flags.push("--no-default-features".into());
}
test_arg.no_default_features = true;
}
"--features" => match args.next() {
Some(feature) if !feature.is_empty() => {
test_arg
@ -196,11 +187,14 @@ fn new() -> Result<Option<Self>, String> {
);
}
}
if test_arg.config_info.no_default_features {
test_arg.flags.push("--no-default-features".into());
}
Ok(Some(test_arg))
}
pub fn is_using_gcc_master_branch(&self) -> bool {
!self.no_default_features
!self.config_info.no_default_features
}
}
@ -612,20 +606,23 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
let rustc_args =
&format!(
r#"-Zpanic-abort-tests \
-Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
--sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort"#,
pwd = std::env::current_dir()
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
.display(),
channel = args.config_info.channel.as_str(),
dylib_ext = args.config_info.dylib_ext,
);
let extra = if args.is_using_gcc_master_branch() {
""
} else {
" -Csymbol-mangling-version=v0"
};
#[cfg(not(feature="master"))]
let rustc_args = format!("{} -Csymbol-mangling-version=v0", rustc_args);
let rustc_args = &format!(
r#"-Zpanic-abort-tests \
-Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
--sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort{extra}"#,
pwd = std::env::current_dir()
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
.display(),
channel = args.config_info.channel.as_str(),
dylib_ext = args.config_info.dylib_ext,
extra = extra,
);
run_command_with_env(
&[
@ -1069,16 +1066,21 @@ fn file_handling(file_path: &Path) -> Result<(), String> {
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rustc test suite");
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
let extra = if args.is_using_gcc_master_branch() {
""
} else {
" -Csymbol-mangling-version=v0"
};
let rustc_args = format!(
"{} -Zcodegen-backend={} --sysroot {}",
"{} -Zcodegen-backend={} --sysroot {}{}",
env.get("TEST_FLAGS").unwrap_or(&String::new()),
args.config_info.cg_backend_path,
args.config_info.sysroot_path,
extra,
);
#[cfg(not(feature="master"))]
let rustc_args = format!("{} -Csymbol-mangling-version=v0", rustc_args);
env.get_mut("RUSTFLAGS").unwrap().clear();
run_command_with_output_and_env(
&[