Skip to content

Commit

Permalink
separated section for gcc or clang-only flags
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Sep 23, 2023
1 parent ffdf356 commit 5bf4d10
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5bf4d10

Please sign in to comment.