Skip to content

Commit db9b932

Browse files
Fix sysroot build
1 parent 867ea12 commit db9b932

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

build_system/src/build.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::ConfigInfo;
1+
use crate::config::{Channel, ConfigInfo};
22
use crate::utils::{get_gcc_path, run_command, run_command_with_output_and_env, walk_dir};
33
use std::collections::HashMap;
44
use std::ffi::OsStr;
@@ -7,7 +7,6 @@ use std::path::Path;
77

88
#[derive(Default)]
99
struct BuildArg {
10-
codegen_release_channel: bool,
1110
flags: Vec<String>,
1211
gcc_path: String,
1312
config_info: ConfigInfo,
@@ -25,7 +24,6 @@ impl BuildArg {
2524

2625
while let Some(arg) = args.next() {
2726
match arg.as_str() {
28-
"--release" => build_arg.codegen_release_channel = true,
2927
"--no-default-features" => {
3028
build_arg.flags.push("--no-default-features".to_string());
3129
}
@@ -58,7 +56,6 @@ impl BuildArg {
5856
r#"
5957
`build` command help:
6058
61-
--release : Build codegen in release mode
6259
--no-default-features : Add `--no-default-features` flag
6360
--features [arg] : Add a new feature [arg]"#
6461
);
@@ -118,6 +115,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
118115
if config.sysroot_panic_abort {
119116
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
120117
}
118+
rustflags.push_str(" -Z force-unstable-if-unmarked");
121119
let mut env = env.clone();
122120
let channel = if config.sysroot_release_channel {
123121
env.insert(
@@ -194,7 +192,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
194192
env.insert("LIBRARY_PATH".to_string(), args.gcc_path.clone());
195193

196194
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
197-
if args.codegen_release_channel {
195+
if args.config_info.channel == Channel::Release {
198196
command.push(&"--release");
199197
env.insert("CHANNEL".to_string(), "release".to_string());
200198
env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());

build_system/src/config.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ use std::collections::HashMap;
33
use std::env as std_env;
44
use std::ffi::OsStr;
55

6+
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug)]
7+
pub enum Channel {
8+
#[default]
9+
Debug,
10+
Release,
11+
}
12+
13+
impl Channel {
14+
pub fn as_str(self) -> &'static str {
15+
match self {
16+
Self::Debug => "debug",
17+
Self::Release => "release",
18+
}
19+
}
20+
}
21+
622
#[derive(Default, Debug)]
723
pub struct ConfigInfo {
824
pub target_triple: String,
@@ -12,6 +28,7 @@ pub struct ConfigInfo {
1228
pub cargo_target_dir: String,
1329
pub dylib_ext: String,
1430
pub sysroot_release_channel: bool,
31+
pub channel: Channel,
1532
pub sysroot_panic_abort: bool,
1633
pub cg_backend_path: String,
1734
pub sysroot_path: String,
@@ -40,6 +57,7 @@ impl ConfigInfo {
4057
_ => return Err("Expected a value after `--out-dir`, found nothing".to_string()),
4158
},
4259
"--release-sysroot" => self.sysroot_release_channel = true,
60+
"--release" => self.channel = Channel::Release,
4361
"--sysroot-panic-abort" => self.sysroot_panic_abort = true,
4462
_ => return Ok(false),
4563
}
@@ -108,7 +126,7 @@ impl ConfigInfo {
108126

109127
let current_dir =
110128
std_env::current_dir().map_err(|error| format!("`current_dir` failed: {:?}", error))?;
111-
let channel = if self.sysroot_release_channel {
129+
let channel = if self.channel == Channel::Release {
112130
"release"
113131
} else if let Some(channel) = env.get("CHANNEL") {
114132
channel.as_str()
@@ -152,6 +170,9 @@ impl ConfigInfo {
152170
if let Some(cg_rustflags) = env.get("CG_RUSTFLAGS") {
153171
rustflags.extend_from_slice(&split_args(&cg_rustflags)?);
154172
}
173+
if let Some(test_flags) = env.get("TEST_FLAGS") {
174+
rustflags.extend_from_slice(&split_args(&test_flags)?);
175+
}
155176

156177
if let Some(linker) = linker {
157178
rustflags.push(linker.to_string());
@@ -223,6 +244,7 @@ impl ConfigInfo {
223244
"\
224245
--target-triple [arg] : Set the target triple to [arg]
225246
--out-dir : Location where the files will be generated
247+
--release : Build in release mode
226248
--release-sysroot : Build sysroot in release mode
227249
--sysroot-panic-abort : Build the sysroot without unwinding support."
228250
);

build_system/src/test.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::build;
2-
use crate::config::ConfigInfo;
2+
use crate::config::{Channel, ConfigInfo};
33
use crate::utils::{
44
get_gcc_path, get_toolchain, remove_file, run_command, run_command_with_env,
55
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
@@ -104,28 +104,11 @@ fn show_usage() {
104104
println!(" --help : Show this help");
105105
}
106106

107-
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug)]
108-
enum Channel {
109-
#[default]
110-
Debug,
111-
Release,
112-
}
113-
114-
impl Channel {
115-
pub fn as_str(self) -> &'static str {
116-
match self {
117-
Self::Debug => "debug",
118-
Self::Release => "release",
119-
}
120-
}
121-
}
122-
123107
#[derive(Default, Debug)]
124108
struct TestArg {
125109
no_default_features: bool,
126110
build_only: bool,
127111
gcc_path: String,
128-
channel: Channel,
129112
use_backend: bool,
130113
runners: BTreeSet<String>,
131114
flags: Vec<String>,
@@ -147,10 +130,6 @@ impl TestArg {
147130

148131
while let Some(arg) = args.next() {
149132
match arg.as_str() {
150-
"--release" => {
151-
test_arg.channel = Channel::Release;
152-
test_arg.config_info.sysroot_release_channel = true;
153-
}
154133
"--no-default-features" => {
155134
// To prevent adding it more than once.
156135
if !test_arg.no_default_features {
@@ -233,7 +212,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
233212
}
234213
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
235214
let mut tmp_env;
236-
let env = if args.channel == Channel::Release {
215+
let env = if args.config_info.channel == Channel::Release {
237216
tmp_env = env.clone();
238217
tmp_env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
239218
command.push(&"--release");
@@ -613,7 +592,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
613592
pwd = std::env::current_dir()
614593
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
615594
.display(),
616-
channel = args.channel.as_str(),
595+
channel = args.config_info.channel.as_str(),
617596
dylib_ext = args.config_info.dylib_ext,
618597
)
619598
.as_str(),

0 commit comments

Comments
 (0)