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

Improve Android support #471

Merged
merged 2 commits into from
Jul 30, 2024
Merged
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
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
Loading