Support TARGET_CC and CC_{target}

This commit is contained in:
Kornel 2025-08-26 11:58:21 +01:00 committed by Kornel
parent 21f2885be3
commit a50a39fde7
3 changed files with 23 additions and 11 deletions

View File

@ -145,8 +145,8 @@ jobs:
apt_packages: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi apt_packages: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
check_only: true check_only: true
custom_env: custom_env:
CC: arm-linux-gnueabi-gcc CC_arm-unknown-linux-gnueabi: arm-linux-gnueabi-gcc
CXX: arm-linux-gnueabi-g++ CXX_arm-unknown-linux-gnueabi: arm-linux-gnueabi-g++
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER: arm-linux-gnueabi-g++ CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER: arm-linux-gnueabi-g++
- thing: aarch64-linux - thing: aarch64-linux
target: aarch64-unknown-linux-gnu target: aarch64-unknown-linux-gnu
@ -155,8 +155,8 @@ jobs:
apt_packages: crossbuild-essential-arm64 apt_packages: crossbuild-essential-arm64
check_only: true check_only: true
custom_env: custom_env:
CC: aarch64-linux-gnu-gcc CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
CXX: aarch64-linux-gnu-g++ CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-g++ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-g++
- thing: arm64-macos - thing: arm64-macos
target: aarch64-apple-darwin target: aarch64-apple-darwin

View File

@ -36,6 +36,9 @@ pub(crate) struct Env {
pub(crate) android_ndk_home: Option<PathBuf>, pub(crate) android_ndk_home: Option<PathBuf>,
pub(crate) cmake_toolchain_file: Option<PathBuf>, pub(crate) cmake_toolchain_file: Option<PathBuf>,
pub(crate) cpp_runtime_lib: Option<OsString>, pub(crate) cpp_runtime_lib: Option<OsString>,
/// C compiler (ignored if using FIPS)
pub(crate) cc: Option<OsString>,
pub(crate) cxx: Option<OsString>,
pub(crate) docs_rs: bool, pub(crate) docs_rs: bool,
} }
@ -146,18 +149,15 @@ impl Env {
const NORMAL_PREFIX: &str = "BORING_BSSL"; const NORMAL_PREFIX: &str = "BORING_BSSL";
const FIPS_PREFIX: &str = "BORING_BSSL_FIPS"; const FIPS_PREFIX: &str = "BORING_BSSL_FIPS";
let var_prefix = if host == target { "HOST" } else { "TARGET" };
let target_with_underscores = target.replace('-', "_"); let target_with_underscores = target.replace('-', "_");
// Logic stolen from cmake-rs. let target_only_var = |name: &str| {
let target_var = |name: &str| {
let kind = if host == target { "HOST" } else { "TARGET" };
// TODO(rmehra): look for just `name` first, as most people just set that
var(&format!("{name}_{target}")) var(&format!("{name}_{target}"))
.or_else(|| var(&format!("{name}_{target_with_underscores}"))) .or_else(|| var(&format!("{name}_{target_with_underscores}")))
.or_else(|| var(&format!("{kind}_{name}"))) .or_else(|| var(&format!("{var_prefix}_{name}")))
.or_else(|| var(name))
}; };
let target_var = |name: &str| target_only_var(name).or_else(|| var(name));
let boringssl_var = |name: &str| { let boringssl_var = |name: &str| {
// The passed name is the non-fips version of the environment variable, // The passed name is the non-fips version of the environment variable,
@ -186,6 +186,9 @@ impl Env {
android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into), android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into),
cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into), cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into),
cpp_runtime_lib: target_var("BORING_BSSL_RUST_CPPLIB"), cpp_runtime_lib: target_var("BORING_BSSL_RUST_CPPLIB"),
// matches the `cc` crate
cc: target_only_var("CC"),
cxx: target_only_var("CXX"),
docs_rs: var("DOCS_RS").is_some(), docs_rs: var("DOCS_RS").is_some(),
} }
} }

View File

@ -216,6 +216,15 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
.define("CMAKE_ASM_COMPILER_TARGET", &config.target); .define("CMAKE_ASM_COMPILER_TARGET", &config.target);
} }
if !config.features.fips {
if let Some(cc) = &config.env.cc {
boringssl_cmake.define("CMAKE_C_COMPILER", cc);
}
if let Some(cxx) = &config.env.cxx {
boringssl_cmake.define("CMAKE_CXX_COMPILER", cxx);
}
}
if let Some(sysroot) = &config.env.sysroot { if let Some(sysroot) = &config.env.sysroot {
boringssl_cmake.define("CMAKE_SYSROOT", sysroot); boringssl_cmake.define("CMAKE_SYSROOT", sysroot);
} }