Skip to content

Commit

Permalink
use env variables instead of cfg! (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosestito authored Jun 29, 2023
1 parent 4e1c4cc commit 37275ea
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rustler_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,21 +895,31 @@ fn get_nif_version_from_features() -> (u32, u32) {

fn main() {
let nif_version = get_nif_version_from_features();
let target_family_or_current =
env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_else(|_| env::consts::FAMILY.to_string());

let target_family = if cfg!(target_family = "windows") {
let target_family = if target_family_or_current == "windows" {
OsFamily::Win
} else if cfg!(target_family = "unix") {
OsFamily::Unix
} else {
panic!("Unsupported Operational System Family")
};

let target_pointer_width = match env::var("CARGO_CFG_TARGET_POINTER_WIDTH") {
Ok(target_pointer_width) => target_pointer_width,
Err(err) => panic!(
"An error occurred while determining the pointer width to compile `rustler_sys` for:\n\n{:?}\n\nPlease report a bug.",
err
)
};

let ulong_size = match target_family {
OsFamily::Win => 4,
OsFamily::Unix => {
if cfg!(target_pointer_width = "32") {
if target_pointer_width == "32" {
4
} else if cfg!(target_pointer_width = "64") {
} else if target_pointer_width == "64" {
8
} else {
panic!("Unsupported target pointer width")
Expand Down

0 comments on commit 37275ea

Please sign in to comment.