Skip to content

Commit

Permalink
Improve Android support (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth authored Jul 30, 2024
1 parent a6571b4 commit 2e1d26c
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
target_arch, target_env, target_os, target_underscored, target_vendor, OutputLibType,
};
use std::env;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::PathBuf;

pub(crate) struct CmakeBuilder {
Expand All @@ -25,11 +25,21 @@ fn test_nasm_command() -> bool {
execute_command("nasm".as_ref(), &["-version".as_ref()]).status
}

fn find_cmake_command() -> Option<&'static OsStr> {
if execute_command("cmake3".as_ref(), &["--version".as_ref()]).status {
Some("cmake3".as_ref())
fn find_cmake_command() -> Option<OsString> {
if let Some(cmake) = option_env("CMAKE") {
emit_warning(&format!(
"CMAKE environment variable set: {}",
cmake.clone()
));
if execute_command(cmake.as_ref(), &["--version".as_ref()]).status {
Some(cmake.into())
} else {
None
}
} else if execute_command("cmake3".as_ref(), &["--version".as_ref()]).status {
Some("cmake3".into())
} else if execute_command("cmake".as_ref(), &["--version".as_ref()]).status {
Some("cmake".as_ref())
Some("cmake".into())
} else {
None
}
Expand Down Expand Up @@ -124,12 +134,25 @@ impl CmakeBuilder {
}

// Allow environment to specify CMake toolchain.
if option_env("CMAKE_TOOLCHAIN_FILE").is_some()
|| option_env(format!("CMAKE_TOOLCHAIN_FILE_{}", target_underscored())).is_some()
{
if let Some(toolchain) = option_env("CMAKE_TOOLCHAIN_FILE").or(option_env(format!(
"CMAKE_TOOLCHAIN_FILE_{}",
target_underscored()
))) {
emit_warning(&format!(
"CMAKE_TOOLCHAIN_FILE environment variable set: {toolchain}"
));
return cmake_cfg;
}

if let Some(cc) = option_env("CC") {
emit_warning(&format!("CC environment variable set: {}", cc.clone()));
cmake_cfg.define("CMAKE_C_COMPILER", cc);
}
if let Some(cxx) = option_env("CXX") {
emit_warning(&format!("CXX environment variable set: {}", cxx.clone()));
cmake_cfg.define("CMAKE_CXX_COMPILER", cxx);
}

// See issue: https://github.com/aws/aws-lc-rs/issues/453
if target_os() == "windows" {
Self::configure_windows(&mut cmake_cfg);
Expand All @@ -148,6 +171,24 @@ impl CmakeBuilder {
}
}

if target_os() == "android" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "Android");

let target = target();
let proc = target.split('-').next().unwrap();
match proc {
"armv7" => {
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "armv7-a");
}
"arm" => {
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "armv6");
}
_ => {
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", proc);
}
}
}

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" {
Expand Down

0 comments on commit 2e1d26c

Please sign in to comment.