Skip to content

Commit 6d81602

Browse files
committed
set correct default value for cc and cxx on android
1 parent 09340e3 commit 6d81602

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/bootstrap/cc_detect.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,7 @@ fn set_compiler(
168168
// compiler already takes into account the triple in question.
169169
t if t.contains("android") => {
170170
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
171-
let mut triple_iter = target.triple.split("-");
172-
let triple_translated = if let Some(arch) = triple_iter.next() {
173-
let arch_new = match arch {
174-
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a",
175-
other => other,
176-
};
177-
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
178-
} else {
179-
target.triple.to_string()
180-
};
181-
182-
// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
183-
// begins at API level 21.
184-
let api_level =
185-
if t.contains("aarch64") || t.contains("x86_64") { "21" } else { "19" };
186-
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
187-
cfg.compiler(ndk.join("bin").join(compiler));
171+
cfg.compiler(ndk_compiler(compiler, &*target.triple, ndk));
188172
}
189173
}
190174

@@ -236,8 +220,28 @@ fn set_compiler(
236220
}
237221
}
238222

223+
pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf {
224+
let mut triple_iter = triple.split("-");
225+
let triple_translated = if let Some(arch) = triple_iter.next() {
226+
let arch_new = match arch {
227+
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a",
228+
other => other,
229+
};
230+
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
231+
} else {
232+
triple.to_string()
233+
};
234+
235+
// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
236+
// begins at API level 21.
237+
let api_level =
238+
if triple.contains("aarch64") || triple.contains("x86_64") { "21" } else { "19" };
239+
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
240+
ndk.join("bin").join(compiler)
241+
}
242+
239243
/// The target programming language for a native compiler.
240-
enum Language {
244+
pub(crate) enum Language {
241245
/// The compiler is targeting C.
242246
C,
243247
/// The compiler is targeting C++.

src/bootstrap/config.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::str::FromStr;
1616
use crate::builder::TaskPath;
1717
use crate::cache::{Interned, INTERNER};
1818
use crate::channel::{self, GitInfo};
19+
use crate::cc_detect::{ndk_compiler, Language};
1920
pub use crate::flags::Subcommand;
2021
use crate::flags::{Color, Flags};
2122
use crate::util::{exe, output, t};
@@ -1237,8 +1238,12 @@ impl Config {
12371238
if let Some(s) = cfg.no_std {
12381239
target.no_std = s;
12391240
}
1240-
target.cc = cfg.cc.map(PathBuf::from);
1241-
target.cxx = cfg.cxx.map(PathBuf::from);
1241+
target.cc = cfg.cc.map(PathBuf::from).or_else(|| {
1242+
target.ndk.as_ref().map(|ndk| ndk_compiler(Language::C, &triple, ndk))
1243+
});
1244+
target.cxx = cfg.cxx.map(PathBuf::from).or_else(|| {
1245+
target.ndk.as_ref().map(|ndk| ndk_compiler(Language::CPlusPlus, &triple, ndk))
1246+
});
12421247
target.ar = cfg.ar.map(PathBuf::from);
12431248
target.ranlib = cfg.ranlib.map(PathBuf::from);
12441249
target.linker = cfg.linker.map(PathBuf::from);

0 commit comments

Comments
 (0)