From 5bf4d104789abf7b3d7e50edca00d02662280b86 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sun, 24 Sep 2023 02:22:17 +0900 Subject: [PATCH] separated section for gcc or clang-only flags --- src/lib.rs | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ca8c9b8a5..5e755179c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1750,28 +1750,34 @@ impl Build { } } ToolFamily::Gnu | ToolFamily::Clang => { - // arm-linux-androideabi-gcc 4.8 shipped with Android NDK does - // not support '-Oz' - if opt_level == "z" && cmd.family != ToolFamily::Clang { - cmd.push_opt_unless_duplicate("-Os".into()); - } else { - cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into()); - } - - if cmd.family == ToolFamily::Clang && target.contains("windows") { - // Disambiguate mingw and msvc on Windows. Problem is that - // depending on the origin clang can default to a mismatchig - // run-time. - cmd.push_cc_arg(format!("--target={}", target).into()); - } + match cmd.family { + ToolFamily::Gnu => { + // arm-linux-androideabi-gcc 4.8 shipped with Android NDK does + // not support '-Oz' + if opt_level == "z" { + cmd.push_opt_unless_duplicate("-Os".into()); + } else { + cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into()); + } + } + ToolFamily::Clang => { + if target.contains("windows") { + // Disambiguate mingw and msvc on Windows. Problem is that + // depending on the origin clang can default to a mismatchig + // run-time. + cmd.push_cc_arg(format!("--target={}", target).into()); + } - if cmd.family == ToolFamily::Clang && target.contains("android") { - // For compatibility with code that doesn't use pre-defined `__ANDROID__` macro. - // If compiler used via ndk-build or cmake (officially supported build methods) - // this macros is defined. - // See https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/cmake/android.toolchain.cmake#456 - // https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/core/build-binary.mk#141 - cmd.push_opt_unless_duplicate("-DANDROID".into()); + if target.contains("android") { + // For compatibility with code that doesn't use pre-defined `__ANDROID__` macro. + // If compiler used via ndk-build or cmake (officially supported build methods) + // this macros is defined. + // See https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/cmake/android.toolchain.cmake#456 + // https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/core/build-binary.mk#141 + cmd.push_opt_unless_duplicate("-DANDROID".into()); + } + } + _ => unreachable!("MSVC never reaches here."), } if !target.contains("apple-ios")