-
-
Notifications
You must be signed in to change notification settings - Fork 398
Implement Android platform tag support #2900
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ use ignore::overrides::{Override, OverrideBuilder}; | |
| use lddtree::Library; | ||
| use normpath::PathExt; | ||
| use platform_info::*; | ||
| use regex::Regex; | ||
| use sha2::{Digest, Sha256}; | ||
| use std::borrow::Borrow; | ||
| use std::collections::{BTreeMap, HashSet}; | ||
|
|
@@ -550,16 +551,28 @@ impl BuildContext { | |
| // Linux | ||
| (Os::Linux, _) => { | ||
| let arch = target.get_platform_arch()?; | ||
| let mut platform_tags = platform_tags.to_vec(); | ||
| platform_tags.sort(); | ||
| let mut tags = vec![]; | ||
| for platform_tag in platform_tags { | ||
| tags.push(format!("{platform_tag}_{arch}")); | ||
| for alias in platform_tag.aliases() { | ||
| tags.push(format!("{alias}_{arch}")); | ||
| if target.target_triple().contains("android") { | ||
| let android_arch = match arch.as_str() { | ||
| "armv7l" => "armeabi_v7a", | ||
| "aarch64" => "arm64_v8a", | ||
| "i686" => "x86", | ||
| "x86_64" => "x86_64", | ||
| _ => bail!("Unsupported Android architecture: {}", arch), | ||
| }; | ||
| let api_level = find_android_api_level(target.target_triple(), &self.manifest_path)?; | ||
| format!("android_{}_{}", api_level, android_arch) | ||
| } else { | ||
| let mut platform_tags = platform_tags.to_vec(); | ||
| platform_tags.sort(); | ||
| let mut tags = vec![]; | ||
| for platform_tag in platform_tags { | ||
| tags.push(format!("{platform_tag}_{arch}")); | ||
| for alias in platform_tag.aliases() { | ||
| tags.push(format!("{alias}_{arch}")); | ||
| } | ||
| } | ||
| tags.join(".") | ||
| } | ||
| tags.join(".") | ||
| } | ||
| // macOS | ||
| (Os::Macos, Arch::X86_64) | (Os::Macos, Arch::Aarch64) => { | ||
|
|
@@ -1297,6 +1310,43 @@ fn emcc_version() -> Result<String> { | |
| Ok(trimmed.into()) | ||
| } | ||
|
|
||
| fn find_android_api_level(target_triple: &str, manifest_path: &Path) -> Result<String> { | ||
| if let Ok(val) = env::var("ANDROID_API_LEVEL") { | ||
| return Ok(val); | ||
| } | ||
|
|
||
| let mut clues = Vec::new(); | ||
|
|
||
| // 1. Linker from cargo-config2 | ||
| if let Some(manifest_dir) = manifest_path.parent() { | ||
| if let Ok(config) = cargo_config2::Config::load_with_cwd(manifest_dir) { | ||
| if let Ok(Some(linker)) = config.linker(target_triple) { | ||
| clues.push(linker.to_string_lossy().into_owned()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 2. CC env vars | ||
| if let Ok(cc) = env::var(format!("CC_{}", target_triple.replace('-', "_"))) { | ||
| clues.push(cc); | ||
| } | ||
| if let Ok(cc) = env::var("CC") { | ||
| clues.push(cc); | ||
| } | ||
|
|
||
| // Search for android(\d+) in clues | ||
| let re = Regex::new(r"android(\d+)")?; | ||
|
||
| for clue in clues { | ||
| if let Some(caps) = re.captures(&clue) { | ||
| return Ok(caps[1].to_string()); | ||
| } | ||
| } | ||
|
Comment on lines
+1318
to
+1343
|
||
|
|
||
| bail!( | ||
| "Failed to determine Android API level. Please set the ANDROID_API_LEVEL environment variable." | ||
| ); | ||
| } | ||
|
Comment on lines
+1313
to
+1348
|
||
|
|
||
| /// Returns a DateTime representing the value SOURCE_DATE_EPOCH environment variable | ||
| /// Note that the earliest timestamp a zip file can represent is 1980-01-01 | ||
| fn zip_mtime() -> DateTime { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Android platform tag generation logic lacks test coverage. The existing test module in this file includes tests for other platform tag generation (e.g.,
test_macosx_deployment_target,test_iphoneos_deployment_target). Consider adding similar tests for Android platform tags that verify: