Skip to content
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

Recognize CARGO_ENCODED_RUSTFLAGS #294

Merged
merged 1 commit into from
Jul 23, 2021
Merged
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
37 changes: 28 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// location inside spans is a performance hit.

use std::env;
use std::iter;
use std::process::{self, Command};
use std::str;

Expand Down Expand Up @@ -132,15 +133,33 @@ fn feature_allowed(feature: &str) -> bool {
//
// -Zallow-features=feature1,feature2

if let Some(rustflags) = env::var_os("RUSTFLAGS") {
for mut flag in rustflags.to_string_lossy().split(' ') {
if flag.starts_with("-Z") {
flag = &flag["-Z".len()..];
}
if flag.starts_with("allow-features=") {
flag = &flag["allow-features=".len()..];
return flag.split(',').any(|allowed| allowed == feature);
}
let flags_var;
let flags_var_string;
let mut flags_var_split;
let mut flags_none;
let flags: &mut dyn Iterator<Item = &str> =
if let Some(encoded_rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") {
flags_var = encoded_rustflags;
flags_var_string = flags_var.to_string_lossy();
flags_var_split = flags_var_string.split('\x1f');
&mut flags_var_split
} else if let Some(rustflags) = env::var_os("RUSTFLAGS") {
flags_var = rustflags;
flags_var_string = flags_var.to_string_lossy();
flags_var_split = flags_var_string.split(' ');
&mut flags_var_split
} else {
flags_none = iter::empty();
&mut flags_none
};

for mut flag in flags {
if flag.starts_with("-Z") {
flag = &flag["-Z".len()..];
}
if flag.starts_with("allow-features=") {
flag = &flag["allow-features=".len()..];
return flag.split(',').any(|allowed| allowed == feature);
}
}

Expand Down