Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Honor RUSTFLAGS's target-cpu if given #1

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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 Apache-2.0)
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