Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f438b0d

Browse files
mrkajetanpNobodyXu
andauthoredNov 27, 2024··
build: add_inherited_rustflags: Apply code review suggestions
Co-authored-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
1 parent fff1a82 commit f438b0d

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed
 

‎src/flags.rs

+21-26
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ impl RustcCodegenFlags {
2626
// Parse flags obtained from CARGO_ENCODED_RUSTFLAGS
2727
pub(crate) fn parse(rustflags_env: &str) -> Result<RustcCodegenFlags, Error> {
2828
fn is_flag_prefix(flag: &str) -> bool {
29-
matches!(
30-
flag,
31-
"-Z" | "-C"
32-
| "--codegen"
33-
| "-L"
34-
| "-l"
35-
| "-o"
36-
| "-W"
37-
| "--warn"
38-
| "-A"
39-
| "--allow"
40-
| "-D"
41-
| "--deny"
42-
| "-F"
43-
| "--forbid"
44-
)
29+
[
30+
"-Z",
31+
"-C",
32+
"--codegen",
33+
"-L",
34+
"-l",
35+
"-o",
36+
"-W",
37+
"--warn",
38+
"-A",
39+
"--allow",
40+
"-D",
41+
"--deny",
42+
"-F",
43+
"--forbid",
44+
].contains(flag)
4545
}
4646

4747
fn handle_flag_prefix<'a>(prev: &'a str, curr: &'a str) -> Cow<'a, str> {
@@ -64,17 +64,12 @@ impl RustcCodegenFlags {
6464

6565
let mut prev_prefix = None;
6666
for curr in rustflags_env.split("\u{1f}") {
67-
let prev = if let Some(prev) = prev_prefix {
68-
prev_prefix = None;
69-
prev
70-
} else {
67+
let prev = prev_prefix.take().unwrap_or("");
68+
if prev.is_empty() && is_flag_prefix(curr) {
7169
// Do not process prefixes on their own
72-
if is_flag_prefix(curr) {
73-
prev_prefix = Some(curr);
74-
continue;
75-
}
76-
""
77-
};
70+
prev_prefix = Some(curr);
71+
continue;
72+
}
7873

7974
let rustc_flag = handle_flag_prefix(prev, curr);
8075
codegen_flags.set_rustc_flag(&rustc_flag)?;

‎src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2399,9 +2399,7 @@ impl Build {
23992399

24002400
let env = env_os.to_string_lossy();
24012401
let codegen_flags = RustcCodegenFlags::parse(&env)?;
2402-
let mut cc_flags_args: Vec<OsString> = vec![];
2403-
codegen_flags.cc_flags(self, path, *family, target, &mut cc_flags_args);
2404-
args.extend(cc_flags_args);
2402+
codegen_flags.cc_flags(self, path, *family, target, &mut args);
24052403
Ok(())
24062404
}
24072405

0 commit comments

Comments
 (0)
Please sign in to comment.