From 3807cae594d85ecd8522fc7608d4f4d0723cbcb3 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Mon, 4 Mar 2024 11:43:23 -0800 Subject: [PATCH] Fix arm-android compile-ui tests --- src/lib.rs | 5 ++++- tests/test.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6999d148a..023896184 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1894,7 +1894,10 @@ impl Build { // Target flags match cmd.family { ToolFamily::Clang => { - if !(target.contains("android") && cmd.has_internal_target_arg) { + if !cmd.has_internal_target_arg + && !(target.contains("android") + && android_clang_compiler_uses_target_arg_internally(&cmd.path)) + { if target.contains("darwin") { if let Some(arch) = map_darwin_target_from_rust_to_compiler_architecture(target) diff --git a/tests/test.rs b/tests/test.rs index f8c950d38..f48e05d95 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -617,3 +617,33 @@ fn compile_intermediates() { assert!(intermediates[1].display().to_string().contains("x86_64")); assert!(intermediates[2].display().to_string().contains("x86_64")); } + +#[test] +fn clang_android() { + let target = "arm-linux-androideabi"; + + // On Windows, we don't use the Android NDK shims for Clang, so verify that + // we use "clang" and set the target correctly. + #[cfg(windows)] + { + let test = Test::new(); + test.shim("clang").shim("llvm-ar"); + test.gcc() + .target(target) + .host("x86_64-pc-windows-msvc") + .file("foo.c") + .compile("foo"); + test.cmd(0).must_have("--target=arm-linux-androideabi"); + } + + // On non-Windows, we do use the shims, so make sure that we use the shim + // and don't set the target. + #[cfg(not(windows))] + { + let test = Test::new(); + test.shim("arm-linux-androideabi-clang") + .shim("arm-linux-androideabi-ar"); + test.gcc().target(target).file("foo.c").compile("foo"); + test.cmd(0).must_not_have("--target=arm-linux-androideabi"); + } +}