From 6d8160261ff3aee3b6eaacc37ac96cafff530980 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 3 Nov 2022 15:01:39 +0100 Subject: [PATCH] set correct default value for cc and cxx on android --- src/bootstrap/cc_detect.rs | 40 +++++++++++++++++++++----------------- src/bootstrap/config.rs | 9 +++++++-- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index 7795bebaed55f..65c882fb801e5 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -168,23 +168,7 @@ fn set_compiler( // compiler already takes into account the triple in question. t if t.contains("android") => { if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { - let mut triple_iter = target.triple.split("-"); - let triple_translated = if let Some(arch) = triple_iter.next() { - let arch_new = match arch { - "arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a", - other => other, - }; - std::iter::once(arch_new).chain(triple_iter).collect::>().join("-") - } else { - target.triple.to_string() - }; - - // API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support - // begins at API level 21. - let api_level = - if t.contains("aarch64") || t.contains("x86_64") { "21" } else { "19" }; - let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang()); - cfg.compiler(ndk.join("bin").join(compiler)); + cfg.compiler(ndk_compiler(compiler, &*target.triple, ndk)); } } @@ -236,8 +220,28 @@ fn set_compiler( } } +pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf { + let mut triple_iter = triple.split("-"); + let triple_translated = if let Some(arch) = triple_iter.next() { + let arch_new = match arch { + "arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a", + other => other, + }; + std::iter::once(arch_new).chain(triple_iter).collect::>().join("-") + } else { + triple.to_string() + }; + + // API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support + // begins at API level 21. + let api_level = + if triple.contains("aarch64") || triple.contains("x86_64") { "21" } else { "19" }; + let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang()); + ndk.join("bin").join(compiler) +} + /// The target programming language for a native compiler. -enum Language { +pub(crate) enum Language { /// The compiler is targeting C. C, /// The compiler is targeting C++. diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index af004aa509854..a1d0dac7e98a0 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -16,6 +16,7 @@ use std::str::FromStr; use crate::builder::TaskPath; use crate::cache::{Interned, INTERNER}; use crate::channel::{self, GitInfo}; +use crate::cc_detect::{ndk_compiler, Language}; pub use crate::flags::Subcommand; use crate::flags::{Color, Flags}; use crate::util::{exe, output, t}; @@ -1237,8 +1238,12 @@ impl Config { if let Some(s) = cfg.no_std { target.no_std = s; } - target.cc = cfg.cc.map(PathBuf::from); - target.cxx = cfg.cxx.map(PathBuf::from); + target.cc = cfg.cc.map(PathBuf::from).or_else(|| { + target.ndk.as_ref().map(|ndk| ndk_compiler(Language::C, &triple, ndk)) + }); + target.cxx = cfg.cxx.map(PathBuf::from).or_else(|| { + target.ndk.as_ref().map(|ndk| ndk_compiler(Language::CPlusPlus, &triple, ndk)) + }); target.ar = cfg.ar.map(PathBuf::from); target.ranlib = cfg.ranlib.map(PathBuf::from); target.linker = cfg.linker.map(PathBuf::from);