Skip to content

Commit

Permalink
Use CARGO_CFG_TARGET_ARCH in build.rs scripts
Browse files Browse the repository at this point in the history
Using cargos target flags in build.rs doesn't work
because the build.rs is compiled for the host machine
and not the target.
  • Loading branch information
Felix Obenhuber committed Mar 4, 2020
1 parent c9f6fc9 commit 45be0ab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions md5/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
extern crate cc;

fn main() {
let asm_path = if cfg!(target_arch = "x86") {
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

let asm_path = if target_arch == "x86" {
"src/x86.S"
} else if cfg!(target_arch = "x86_64") {
} else if target_arch == "x86_64" {
"src/x64.S"
} else {
panic!("Unsupported target architecture");
Expand Down
10 changes: 6 additions & 4 deletions sha1/build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
extern crate cc;

fn main() {
let asm_path = if cfg!(target_arch = "x86") {
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

let asm_path = if target_arch == "x86" {
"src/x86.S"
} else if cfg!(target_arch = "x86_64") {
} else if target_arch == "x86_64" {
"src/x64.S"
} else if cfg!(target_arch = "aarch64") {
} else if target_arch == "aarch64" {
"src/aarch64.S"
} else {
panic!("Unsupported target architecture");
};
let mut build = cc::Build::new();
if cfg!(target_arch = "aarch64") {
if target_arch == "aarch64" {
build.flag("-march=armv8-a+crypto");
}
build.flag("-c")
Expand Down
10 changes: 6 additions & 4 deletions sha2/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
extern crate cc;

fn main() {
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

let mut build256 = cc::Build::new();
let (sha256_path, sha512_path) = if cfg!(target_arch = "x86") {
let (sha256_path, sha512_path) = if target_arch == "x86" {
("src/sha256_x86.S", "src/sha512_x86.S")
} else if cfg!(target_arch = "x86_64") {
} else if target_arch == "x86_64" {
("src/sha256_x64.S", "src/sha512_x64.S")
} else if cfg!(target_arch = "aarch64") {
} else if target_arch == "aarch64" {
build256.flag("-march=armv8-a+crypto");
("src/sha256_aarch64.S", "")
} else {
panic!("Unsupported target architecture");
};
if !cfg!(target_arch = "aarch64") {
if target_arch != "aarch64" {
cc::Build::new()
.flag("-c")
.file(sha512_path)
Expand Down
6 changes: 4 additions & 2 deletions whirlpool/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
extern crate cc;

fn main() {
let asm_path = if cfg!(target_arch = "x86") {
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

let asm_path = if target_arch == "x86" {
"src/x86.S"
} else if cfg!(target_arch = "x86_64") {
} else if target_arch == "x86_64" {
"src/x64.S"
} else {
panic!("Unsupported target architecture");
Expand Down

0 comments on commit 45be0ab

Please sign in to comment.