Skip to content

Commit

Permalink
sys/build: inline check_static()
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2ec committed Sep 6, 2023
1 parent 45aee3b commit 6d911d5
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions crates/sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ use std::{
use std::{ffi::OsStr, path::Component};

fn main() {
let is_static = check_static();
// check if static build in the order of:
// PLCTAG_STATIC, PLCTAG_DYNAMIC, rustflags: +crt-static
let is_static = get_env_bool("LIBPLCTAG_STATIC").unwrap_or(false)
|| get_env_bool("LIBPLCTAG_DYNAMIC").map_or(false, |v| !v)
|| cfg!(target_feature = "crt-static");

if is_static {
eprintln!("static build");
}
Expand Down Expand Up @@ -124,18 +129,6 @@ fn find_target_profile_dir<'a>(dir: impl AsRef<Path> + 'a) -> Option<PathBuf> {
}
}

/// check if static build in the order of:
/// PLCTAG_STATIC, PLCTAG_DYNAMIC, rustflags: +crt-static
fn check_static() -> bool {
if let Some(v) = get_env_bool("LIBPLCTAG_STATIC") {
return v;
}
if let Some(v) = get_env_bool("LIBPLCTAG_DYNAMIC") {
return !v;
}
cfg!(target_feature = "crt-static")
}

fn get_env_bool(key: &str) -> Option<bool> {
env::var(key)
.ok()
Expand Down

0 comments on commit 6d911d5

Please sign in to comment.