From f91f795fc7a95b550ed3bdcf6aae97b2f1eab9d1 Mon Sep 17 00:00:00 2001 From: Sergey Kvachonok Date: Mon, 29 Mar 2021 09:00:57 +0300 Subject: [PATCH] Clean up CARGO_CFG_TARGET_FAMILY variable parsing Match the target OS family strings exactly and provide better error messages when CARGO_CFG_TARGET_FAMILY is not set (e.g. on wasm32). --- build.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 1e2e3e82..40a65e75 100644 --- a/build.rs +++ b/build.rs @@ -516,13 +516,15 @@ fn windows_hardcoded_cross_compile( fn load_cross_compile_info( cross_compile_config: CrossCompileConfig, ) -> Result<(InterpreterConfig, BuildFlags)> { - let target_family = env::var("CARGO_CFG_TARGET_FAMILY")?; - // Because compiling for windows on linux still includes the unix target family - if target_family == "unix" { + match env::var("CARGO_CFG_TARGET_FAMILY") { // Configure for unix platforms using the sysconfigdata file - load_cross_compile_from_sysconfigdata(cross_compile_config) - } else { - windows_hardcoded_cross_compile(cross_compile_config) + Ok(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()), } }