From d3af89bd099562d0da2eb7e108d3715412aa8e91 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 28 Jun 2024 06:42:14 +0200 Subject: [PATCH] Handle multi-valued `target_family` --- mbedtls-sys/build/features.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mbedtls-sys/build/features.rs b/mbedtls-sys/build/features.rs index 6006bc0b6..91f30b03a 100644 --- a/mbedtls-sys/build/features.rs +++ b/mbedtls-sys/build/features.rs @@ -36,21 +36,21 @@ impl Features { self.with_feature("c_compiler").unwrap().insert("freestanding"); } if let Some(components) = self.with_feature("threading") { - if !have_custom_threading && env_have_target_cfg("family", "unix") { + if !have_custom_threading && env_have_target_family("unix") { components.insert("pthread"); } else { components.insert("custom"); } } if let Some(components) = self.with_feature("std") { - if env_have_target_cfg("family", "unix") || env_have_target_cfg("family", "windows") { + if env_have_target_family("unix") || env_have_target_family("windows") { components.insert("net"); components.insert("fs"); components.insert("entropy"); } } if let Some(components) = self.with_feature("time") { - if !have_custom_gmtime_r && (env_have_target_cfg("family", "unix") || env_have_target_cfg("family", "windows")) { + if !have_custom_gmtime_r && (env_have_target_family("unix") || env_have_target_family("windows")) { components.insert("libc"); } else { components.insert("custom"); @@ -100,6 +100,10 @@ fn env_have_target_cfg(var: &'static str, value: &'static str) -> bool { env::var_os(env).map_or(false, |s| s == value) } +fn env_have_target_family(value: &'static str) -> bool { + env::var("CARGO_CFG_TARGET_FAMILY").map_or(false, |var| var.split(",").any(|s| s == value)) +} + fn env_have_feature(feature: &'static str) -> bool { let env = format!("CARGO_FEATURE_{}", feature).to_uppercase().replace("-", "_"); env::var_os(env).is_some()