Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): armv7a and x86_64's ohos should set asm args #456

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,23 @@ impl CmakeBuilder {
return cmake_cfg;
}

if target_vendor() == "apple" {
if target_os().trim() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().trim().ends_with("-ios-sim") {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
}
}
if target_arch().trim() == "aarch64" {
// If the build environment vendor is Apple
#[cfg(target_vendor = "apple")]
{
if target_arch() == "aarch64" {
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "arm64");
}
if target_arch() == "x86_64" {
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "x86_64");
}
}

if target_vendor() == "apple" && target_os().trim() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().trim().ends_with("-ios-sim") {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
}
}

Expand All @@ -168,22 +176,53 @@ 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());
}
Self::configure_open_harmony(&mut cmake_cfg);
}

cmake_cfg
}

fn configure_open_harmony(cmake_cfg: &mut cmake::Config) {
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"),
);
let mut cflags = vec!["-Wno-unused-command-line-argument"];
let mut asmflags = vec![];
match target().as_str() {
"aarch64-unknown-linux-ohos" => {}
"armv7-unknown-linux-ohos" => {
const ARM7_FLAGS: [&str; 6] = [
"-march=armv7-a",
"-mfloat-abi=softfp",
"-mtune=generic-armv7-a",
"-mthumb",
"-mfpu=neon",
"-DHAVE_NEON",
];
cflags.extend(ARM7_FLAGS);
asmflags.extend(ARM7_FLAGS);
}
"x86_64-unknown-linux-ohos" => {
const X86_64_FLAGS: [&str; 3] = ["-msse4.1", "-DHAVE_NEON_X86", "-DHAVE_NEON"];
cflags.extend(X86_64_FLAGS);
asmflags.extend(X86_64_FLAGS);
}
ohos_target => {
emit_warning(format!("Target: {ohos_target} is not support yet!").as_str());
}
}
cmake_cfg
.cflag(cflags.join(" ").as_str())
.cxxflag(cflags.join(" ").as_str())
.asmflag(asmflags.join(" ").as_str());
} else {
emit_warning(format!("{OHOS_NDK_HOME} not set!").as_str());
}
}

fn build_rust_wrapper(&self) -> PathBuf {
self.prepare_cmake_build()
.configure_arg("--no-warn-unused-cli")
Expand Down
76 changes: 55 additions & 21 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,9 @@ impl CmakeBuilder {
return cmake_cfg;
}

if target_vendor() == "apple" {
if target_os().to_lowercase() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().ends_with("-ios-sim") || target_arch() == "x86_64" {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
} else {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphoneos");
}
cmake_cfg.define("CMAKE_THREAD_LIBS_INIT", "-lpthread");
}
// If the build environment vendor is Apple
#[cfg(target_vendor = "apple")]
{
if target_arch() == "aarch64" {
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "arm64");
Expand All @@ -154,6 +147,16 @@ impl CmakeBuilder {
}
}

if target_vendor() == "apple" && target_os().to_lowercase() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().ends_with("-ios-sim") || target_arch() == "x86_64" {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
} else {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphoneos");
}
cmake_cfg.define("CMAKE_THREAD_LIBS_INIT", "-lpthread");
}

if (target_env() != "msvc") && test_ninja_command() {
// Use Ninja if available
cmake_cfg.generator("Ninja");
Expand All @@ -175,22 +178,53 @@ 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());
}
Self::configure_open_harmony(&mut cmake_cfg);
}

cmake_cfg
}

fn configure_open_harmony(cmake_cfg: &mut cmake::Config) {
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"),
);
let mut cflags = vec!["-Wno-unused-command-line-argument"];
let mut asmflags = vec![];
match target().as_str() {
"aarch64-unknown-linux-ohos" => {}
"armv7-unknown-linux-ohos" => {
const ARM7_FLAGS: [&str; 6] = [
"-march=armv7-a",
"-mfloat-abi=softfp",
"-mtune=generic-armv7-a",
"-mthumb",
"-mfpu=neon",
"-DHAVE_NEON",
];
cflags.extend(ARM7_FLAGS);
asmflags.extend(ARM7_FLAGS);
}
"x86_64-unknown-linux-ohos" => {
const X86_64_FLAGS: [&str; 3] = ["-msse4.1", "-DHAVE_NEON_X86", "-DHAVE_NEON"];
cflags.extend(X86_64_FLAGS);
asmflags.extend(X86_64_FLAGS);
}
ohos_target => {
emit_warning(format!("Target: {ohos_target} is not support yet!").as_str());
}
}
cmake_cfg
.cflag(cflags.join(" ").as_str())
.cxxflag(cflags.join(" ").as_str())
.asmflag(asmflags.join(" ").as_str());
} else {
emit_warning(format!("{OHOS_NDK_HOME} not set!").as_str());
}
}

fn build_rust_wrapper(&self) -> PathBuf {
self.prepare_cmake_build()
.configure_arg("--no-warn-unused-cli")
Expand Down
Loading