From ccaabe3ba5276db6db0e73eb3cca3b81ee554cbe Mon Sep 17 00:00:00 2001 From: Sergey Kvachonok Date: Mon, 29 Mar 2021 11:27:35 +0300 Subject: [PATCH] Apply suggestions from code review: env::var() -> env::var_os() and fall back to load_cross_compile_from_sysconfigdata() when unset. Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com> --- build.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 40a65e75..df07592b 100644 --- a/build.rs +++ b/build.rs @@ -516,15 +516,18 @@ fn windows_hardcoded_cross_compile( fn load_cross_compile_info( cross_compile_config: CrossCompileConfig, ) -> Result<(InterpreterConfig, BuildFlags)> { - match env::var("CARGO_CFG_TARGET_FAMILY") { + match env::var_os("CARGO_CFG_TARGET_FAMILY") { // Configure for unix platforms using the sysconfigdata file - Ok(os) if os == "unix" => load_cross_compile_from_sysconfigdata(cross_compile_config), + Some(os) if os == "unix" => load_cross_compile_from_sysconfigdata(cross_compile_config), // Use hardcoded interpreter config when targeting Windows - Ok(os) if os == "windows" => windows_hardcoded_cross_compile(cross_compile_config), - // ??? - Ok(os) => Err(format!("Unsupported target OS family: {}", os).into()), - // wasm32-wasi / bare metal ? - Err(_) => Err("CARGO_CFG_TARGET_FAMILY is not set when cross-compiling".into()), + Some(os) if os == "windows" => windows_hardcoded_cross_compile(cross_compile_config), + // Waiting for users to tell us what they expect on their target platform + Some(os) => bail!( + "Unsupported target OS family for cross-compilation: {:?}", + os + ), + // Unknown os family - try to do something useful + None => load_cross_compile_from_sysconfigdata(cross_compile_config), } }