Skip to content

Remove unused feature = "master" cfg in build_system #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions build_system/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ impl BuildArg {

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());
Expand Down Expand Up @@ -51,7 +48,6 @@ impl BuildArg {
r#"
`build` command help:

--no-default-features : Add `--no-default-features` flag
--features [arg] : Add a new feature [arg]"#
);
ConfigInfo::show_usage();
Expand Down Expand Up @@ -112,34 +108,25 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
}
rustflags.push_str(" -Z force-unstable-if-unmarked");
let mut env = env.clone();

let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];

if config.no_default_features {
rustflags.push_str(" -Csymbol-mangling-version=v0");
args.push(&"--no-default-features");
}

let channel = if config.sysroot_release_channel {
env.insert(
"RUSTFLAGS".to_string(),
format!("{} -Zmir-opt-level=3", rustflags),
);
run_command_with_output_and_env(
&[
&"cargo",
&"build",
&"--release",
&"--target",
&config.target,
],
Some(start_dir),
Some(&env),
)?;
rustflags.push_str(" -Zmir-opt-level=3");
args.push(&"--release");
"release"
} else {
env.insert("RUSTFLAGS".to_string(), rustflags);

run_command_with_output_and_env(
&[&"cargo", &"build", &"--target", &config.target],
Some(start_dir),
Some(&env),
)?;
"debug"
};

env.insert("RUSTFLAGS".to_string(), rustflags);
run_command_with_output_and_env(&args, Some(start_dir), Some(&env))?;

// Copy files to sysroot
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
fs::create_dir_all(&sysroot_path).map_err(|error| {
Expand Down Expand Up @@ -193,6 +180,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");
Expand All @@ -201,6 +195,9 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
} else {
env.insert("CHANNEL".to_string(), "debug".to_string());
}
if args.config_info.no_default_features {
command.push(&"--no-default-features");
}
let flags = args.flags.iter().map(|s| s.as_str()).collect::<Vec<_>>();
for flag in &flags {
command.push(flag);
Expand Down
10 changes: 7 additions & 3 deletions build_system/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -177,6 +178,7 @@ impl ConfigInfo {
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)
Expand Down Expand Up @@ -416,8 +418,9 @@ impl ConfigInfo {
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(),
Expand Down Expand Up @@ -495,7 +498,8 @@ impl ConfigInfo {
--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"
);
}
}
Expand Down
56 changes: 29 additions & 27 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>,
Expand All @@ -132,13 +130,6 @@ impl TestArg {

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
Expand Down Expand Up @@ -196,11 +187,14 @@ impl TestArg {
);
}
}
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
}
}

Expand Down Expand Up @@ -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(
&[
Expand Down Expand Up @@ -1069,16 +1066,21 @@ where
// 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(
&[
Expand Down