Skip to content

Commit

Permalink
feat: support openharmony platform (#434)
Browse files Browse the repository at this point in the history
* feat: support openharmony platform

* feat: fips support openharmony platform

* fix: fix clippy warning

* Warn on missing OHOS_NDK_HOME env-var

---------

Co-authored-by: Justin Smith <[email protected]>
  • Loading branch information
richerfu and justsmth authored Jun 11, 2024
1 parent 0aeff58 commit 697167a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
44 changes: 30 additions & 14 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
29 changes: 21 additions & 8 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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");
Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down

0 comments on commit 697167a

Please sign in to comment.