From c56fe81a932c850b8b74ba9990ef1edc16e0aa62 Mon Sep 17 00:00:00 2001 From: Johannes Cornelis Draaijer Date: Wed, 3 Sep 2025 08:56:38 +0200 Subject: [PATCH 1/2] Replace periods with underscores as well when parsing env variables --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e63b7b0d..e3d1cc25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,8 +114,8 @@ //! Each of these variables can also be supplied with certain prefixes and suffixes, //! in the following prioritized order: //! -//! 1. `_` - for example, `CC_x86_64-unknown-linux-gnu` -//! 2. `_` - for example, `CC_x86_64_unknown_linux_gnu` +//! 1. `_` - for example, `CC_x86_64-unknown-linux-gnu` or `CC_thumbv8m.main-none-eabi` +//! 2. `_` - for example, `CC_x86_64_unknown_linux_gnu` or `CC_thumbv8m_main_none_eabi` (both periods and underscores are replaced) //! 3. `_` - for example, `HOST_CC` or `TARGET_CFLAGS` //! 4. `` - a plain `CC`, `AR` as above. //! @@ -3928,7 +3928,7 @@ impl Build { } else { "HOST" }; - let target_u = target.replace('-', "_"); + let target_u = target.replace(['-', '.'], "_"); Ok([ format!("{env}_{target}"), From c4159ddb4fb79652c206cff3004ede8ffe72c232 Mon Sep 17 00:00:00 2001 From: Johannes Cornelis Draaijer Date: Wed, 3 Sep 2025 09:31:59 +0200 Subject: [PATCH 2/2] Test environment variable with dots and underscores replaced --- tests/cc_env.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cc_env.rs b/tests/cc_env.rs index 65015f78..5f090b32 100644 --- a/tests/cc_env.rs +++ b/tests/cc_env.rs @@ -133,12 +133,14 @@ fn env_var_alternatives_override() { let compiler2 = format!("clang2{}", env::consts::EXE_SUFFIX); let compiler3 = format!("clang3{}", env::consts::EXE_SUFFIX); let compiler4 = format!("clang4{}", env::consts::EXE_SUFFIX); + let compiler5 = format!("clang5{}", env::consts::EXE_SUFFIX); let test = Test::new(); test.shim(&compiler1); test.shim(&compiler2); test.shim(&compiler3); test.shim(&compiler4); + test.shim(&compiler5); env::set_var("CC", &compiler1); let compiler = test.gcc().target("x86_64-unknown-none").get_compiler(); @@ -156,4 +158,8 @@ fn env_var_alternatives_override() { env::set_var("CC_x86_64-unknown-none", &compiler4); let compiler = test.gcc().target("x86_64-unknown-none").get_compiler(); assert_eq!(compiler.path(), Path::new(&compiler4)); + + env::set_var("CC_thumbv8m_main_none_eabi", &compiler5); + let compiler = test.gcc().target("thumbv8m.main-none-eabi").get_compiler(); + assert_eq!(compiler.path(), Path::new(&compiler5)); }