Skip to content

Commit 5bf4d10

Browse files
committed
separated section for gcc or clang-only flags
1 parent ffdf356 commit 5bf4d10

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/lib.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,28 +1750,34 @@ impl Build {
17501750
}
17511751
}
17521752
ToolFamily::Gnu | ToolFamily::Clang => {
1753-
// arm-linux-androideabi-gcc 4.8 shipped with Android NDK does
1754-
// not support '-Oz'
1755-
if opt_level == "z" && cmd.family != ToolFamily::Clang {
1756-
cmd.push_opt_unless_duplicate("-Os".into());
1757-
} else {
1758-
cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into());
1759-
}
1760-
1761-
if cmd.family == ToolFamily::Clang && target.contains("windows") {
1762-
// Disambiguate mingw and msvc on Windows. Problem is that
1763-
// depending on the origin clang can default to a mismatchig
1764-
// run-time.
1765-
cmd.push_cc_arg(format!("--target={}", target).into());
1766-
}
1753+
match cmd.family {
1754+
ToolFamily::Gnu => {
1755+
// arm-linux-androideabi-gcc 4.8 shipped with Android NDK does
1756+
// not support '-Oz'
1757+
if opt_level == "z" {
1758+
cmd.push_opt_unless_duplicate("-Os".into());
1759+
} else {
1760+
cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into());
1761+
}
1762+
}
1763+
ToolFamily::Clang => {
1764+
if target.contains("windows") {
1765+
// Disambiguate mingw and msvc on Windows. Problem is that
1766+
// depending on the origin clang can default to a mismatchig
1767+
// run-time.
1768+
cmd.push_cc_arg(format!("--target={}", target).into());
1769+
}
17671770

1768-
if cmd.family == ToolFamily::Clang && target.contains("android") {
1769-
// For compatibility with code that doesn't use pre-defined `__ANDROID__` macro.
1770-
// If compiler used via ndk-build or cmake (officially supported build methods)
1771-
// this macros is defined.
1772-
// See https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/cmake/android.toolchain.cmake#456
1773-
// https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/core/build-binary.mk#141
1774-
cmd.push_opt_unless_duplicate("-DANDROID".into());
1771+
if target.contains("android") {
1772+
// For compatibility with code that doesn't use pre-defined `__ANDROID__` macro.
1773+
// If compiler used via ndk-build or cmake (officially supported build methods)
1774+
// this macros is defined.
1775+
// See https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/cmake/android.toolchain.cmake#456
1776+
// https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/build/core/build-binary.mk#141
1777+
cmd.push_opt_unless_duplicate("-DANDROID".into());
1778+
}
1779+
}
1780+
_ => unreachable!("MSVC never reaches here."),
17751781
}
17761782

17771783
if !target.contains("apple-ios")

0 commit comments

Comments
 (0)