diff --git a/aws-lc-fips-sys/builder/cmake_builder.rs b/aws-lc-fips-sys/builder/cmake_builder.rs index a98d81e953b..865a5cdb25f 100644 --- a/aws-lc-fips-sys/builder/cmake_builder.rs +++ b/aws-lc-fips-sys/builder/cmake_builder.rs @@ -3,8 +3,8 @@ use crate::OutputLib::{Crypto, RustWrapper, Ssl}; use crate::{ - cargo_env, execute_command, is_no_asm, option_env, target, target_arch, target_os, - target_vendor, OutputLibType, + cargo_env, emit_warning, execute_command, is_no_asm, option_env, target, target_arch, + target_env, target_os, target_underscored, target_vendor, OutputLibType, }; use std::collections::HashMap; use std::env; @@ -111,17 +111,6 @@ impl CmakeBuilder { cmake_cfg.define("CMAKE_BUILD_TYPE", "debug"); } - if target_os() == "windows" { - cmake_cfg.generator("Ninja"); - let env_map = self - .collect_vcvarsall_bat() - .map_err(|x| panic!("{}", x)) - .unwrap(); - for (key, value) in env_map { - cmake_cfg.env(key, value); - } - } - if let Some(prefix) = &self.build_prefix { cmake_cfg.define("BORINGSSL_PREFIX", format!("{prefix}_")); let include_path = self.manifest_dir.join("generated-include"); @@ -149,7 +138,9 @@ impl CmakeBuilder { } // Allow environment to specify CMake toolchain. - if option_env("CMAKE_TOOLCHAIN_FILE").is_some() { + if option_env("CMAKE_TOOLCHAIN_FILE").is_some() + || option_env(format!("CMAKE_TOOLCHAIN_FILE_{}", target_underscored())).is_some() + { return cmake_cfg; } @@ -165,6 +156,31 @@ impl CmakeBuilder { } } + if target_os() == "windows" { + cmake_cfg.generator("Ninja"); + let env_map = self + .collect_vcvarsall_bat() + .map_err(|x| panic!("{}", x)) + .unwrap(); + for (key, value) in env_map { + cmake_cfg.env(key, value); + } + } + + if target_env() == "ohos" { + const OHOS_NDK_HOME: &str = "OHOS_NDK_HOME"; + if let Ok(ndk) = env::var(OHOS_NDK_HOME) { + cmake_cfg.define( + "CMAKE_TOOLCHAIN_FILE", + format!("{ndk}/native/build/cmake/ohos.toolchain.cmake"), + ); + cmake_cfg.define("CMAKE_C_FLAGS", "-Wno-unused-command-line-argument"); + cmake_cfg.define("CMAKE_CXX_FLAGS", "-Wno-unused-command-line-argument"); + } else { + emit_warning(format!("{OHOS_NDK_HOME} not set!").as_str()); + } + } + cmake_cfg } diff --git a/aws-lc-fips-sys/builder/main.rs b/aws-lc-fips-sys/builder/main.rs index f38a1605524..da6de18856a 100644 --- a/aws-lc-fips-sys/builder/main.rs +++ b/aws-lc-fips-sys/builder/main.rs @@ -249,6 +249,11 @@ fn target() -> String { cargo_env("TARGET") } +#[allow(unused)] +fn target_underscored() -> String { + target().replace('-', "_") +} + fn out_dir() -> PathBuf { PathBuf::from(cargo_env("OUT_DIR")) } diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index 910b8afc91f..eeeacb74019 100644 --- a/aws-lc-sys/builder/cmake_builder.rs +++ b/aws-lc-sys/builder/cmake_builder.rs @@ -3,8 +3,8 @@ use crate::OutputLib::{Crypto, RustWrapper, Ssl}; use crate::{ - cargo_env, execute_command, is_no_asm, option_env, target, target_arch, target_env, target_os, - target_vendor, OutputLibType, + cargo_env, emit_warning, execute_command, is_no_asm, option_env, target, target_arch, + target_env, target_os, target_underscored, target_vendor, OutputLibType, }; use std::env; use std::ffi::OsStr; @@ -128,7 +128,9 @@ impl CmakeBuilder { } // Allow environment to specify CMake toolchain. - if option_env("CMAKE_TOOLCHAIN_FILE").is_some() { + if option_env("CMAKE_TOOLCHAIN_FILE").is_some() + || option_env(format!("CMAKE_TOOLCHAIN_FILE_{}", target_underscored())).is_some() + { return cmake_cfg; } @@ -151,16 +153,13 @@ impl CmakeBuilder { cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "x86_64"); } } + if (target_env() != "msvc") && test_ninja_command() { // Use Ninja if available cmake_cfg.generator("Ninja"); } - if target_os() == "windows" - && target_arch() == "aarch64" - && target_env() == "msvc" - && option_env("CMAKE_TOOLCHAIN_FILE_aarch64_pc_windows_msvc").is_none() - { + if target_underscored() == "aarch64_pc_windows_msvc" { cmake_cfg.generator("Ninja"); cmake_cfg.define("CMAKE_C_COMPILER", "clang-cl"); cmake_cfg.define("CMAKE_CXX_COMPILER", "clang-cl"); @@ -175,6 +174,20 @@ impl CmakeBuilder { } } + if target_env() == "ohos" { + const OHOS_NDK_HOME: &str = "OHOS_NDK_HOME"; + if let Ok(ndk) = env::var(OHOS_NDK_HOME) { + cmake_cfg.define( + "CMAKE_TOOLCHAIN_FILE", + format!("{ndk}/native/build/cmake/ohos.toolchain.cmake"), + ); + cmake_cfg.define("CMAKE_C_FLAGS", "-Wno-unused-command-line-argument"); + cmake_cfg.define("CMAKE_CXX_FLAGS", "-Wno-unused-command-line-argument"); + } else { + emit_warning(format!("{OHOS_NDK_HOME} not set!").as_str()); + } + } + cmake_cfg } diff --git a/aws-lc-sys/builder/main.rs b/aws-lc-sys/builder/main.rs index 27ed94cfb67..866d2055b89 100644 --- a/aws-lc-sys/builder/main.rs +++ b/aws-lc-sys/builder/main.rs @@ -248,6 +248,11 @@ fn target() -> String { cargo_env("TARGET") } +#[allow(unused)] +fn target_underscored() -> String { + target().replace('-', "_") +} + fn out_dir() -> PathBuf { PathBuf::from(cargo_env("OUT_DIR")) }