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

Honor RUSTFLAGS's target-cpu if given #75

Merged
merged 1 commit into from
Apr 4, 2020
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
20 changes: 19 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,27 @@ fn write_tables() {
not(any(target_os = "android", target_os = "ios"))
))]
fn compile_simd_c() {
fn guess_target_cpu() -> String {
// Copied and adapted from https://github.com/alexcrichton/proc-macro2/blob/4173a21dc497c67326095e438ff989cc63cd9279/build.rs#L115
// Licensed under Apache-2.0 + MIT (compatible because we're MIT)
let rustflags = env::var_os("RUSTFLAGS");
if let Some(rustflags) = rustflags {
for mut flag in rustflags.to_string_lossy().split(' ') {
if flag.starts_with("-C") {
flag = &flag["-C".len()..];
}
if flag.starts_with("target-cpu=") {
return flag["target-cpu=".len()..].to_owned()
}
}
}

"native".to_string()
}

cc::Build::new()
.opt_level(3)
.flag("-march=native")
.flag(&format!("-march={}", guess_target_cpu()))
.flag("-std=c11")
.file("simd_c/reedsolomon.c")
.compile("reedsolomon");
Expand Down