From 5c6382b3d81beae78c64499440847f210570a987 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Fri, 28 Oct 2022 14:47:54 +0100 Subject: [PATCH] Add support for NDK version 21 (#2728) Co-authored-by: Marces Engel --- .circleci/config.yml | 6 +++--- .../toolchain/ndk/impl/NdkCxxPlatforms.java | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d35dc09f932..4a2d5a82167 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -197,7 +197,7 @@ macos_environment: &macos_environment TERM: "dumb" BUCK_NUM_THREADS: 3 BUCK_PEX_LOCATION: "./new_buck.pex" - JAVA_HOME: "/usr/local/Cellar/openjdk@8/1.8.0+322" + JAVA_HOME: "/usr/local/Cellar/openjdk@8/1.8.0+345" windows_environment: &windows_environment PLATFORM: "windows" @@ -1004,7 +1004,7 @@ jobs: export PATH="${ANDROID_SDK}/tools/bin:${PATH}" export PATH="$(pyenv root)/shims:${PATH}" export GROOVY_HOME="$HOME/.sdkman/candidates/groovy/current" - export JAVA_HOME="/usr/local/Cellar/openjdk@8/1.8.0+322" + export JAVA_HOME="/usr/local/Cellar/openjdk@8/1.8.0+345" export PATH="${JAVA_HOME}/bin:${PATH}" source ~/dlang/dmd-2.091.0/activate export PATH="${HOME}/.cargo/bin:${PATH}" @@ -1062,7 +1062,7 @@ jobs: command: | export NDK_HOME="${HOME}/android-ndk-${PLATFORM}" export ANDROID_HOME="${ANDROID_SDK}" - export JAVA_HOME="/usr/local/Cellar/openjdk@8/1.8.0+322" + export JAVA_HOME="/usr/local/Cellar/openjdk@8/1.8.0+345" export PATH="${JAVA_HOME}/bin:${PATH}" source ~/dlang/dmd-2.091.0/activate export PATH="${HOME}/.cargo/bin:${PATH}" diff --git a/src/com/facebook/buck/android/toolchain/ndk/impl/NdkCxxPlatforms.java b/src/com/facebook/buck/android/toolchain/ndk/impl/NdkCxxPlatforms.java index f45d41427d0..4f65a7de9f4 100644 --- a/src/com/facebook/buck/android/toolchain/ndk/impl/NdkCxxPlatforms.java +++ b/src/com/facebook/buck/android/toolchain/ndk/impl/NdkCxxPlatforms.java @@ -150,6 +150,7 @@ public class NdkCxxPlatforms { "-Wl,--as-needed"); private static final Pattern NDK_MAJOR_VERSION_PATTERN = Pattern.compile("^[rR]?(\\d+).*"); + private static final Pattern NDK_MINOR_VERSION_PATTERN = Pattern.compile("^[rR]?\\d+\\.(\\d+).*"); // Utility class, do not instantiate. private NdkCxxPlatforms() {} @@ -158,6 +159,15 @@ static int getNdkMajorVersion(String ndkVersion) { return Integer.parseInt(NDK_MAJOR_VERSION_PATTERN.matcher(ndkVersion).replaceAll("$1")); } + static int getNdkMinorVersion(String ndkVersion) { + String minorVersion = NDK_MINOR_VERSION_PATTERN.matcher(ndkVersion).replaceAll("$1"); + if (minorVersion.startsWith("r") || minorVersion.startsWith("R")) { + // Failed to find a minor version, 0 is a safe fallback. + return 0; + } + return Integer.parseInt(minorVersion); + } + public static NdkCompilerType getDefaultCompilerTypeForNdk(String ndkVersion) { return getNdkMajorVersion(ndkVersion) < 18 ? NdkCompilerType.GCC : NdkCompilerType.CLANG; } @@ -172,6 +182,8 @@ public static String getDefaultGccVersionForNdk(String ndkVersion) { public static String getDefaultClangVersionForNdk(String ndkVersion) { int ndkMajorVersion = getNdkMajorVersion(ndkVersion); + int ndkMinorVersion = getNdkMinorVersion(ndkVersion); + if (ndkMajorVersion < 11) { return "3.5"; } else if (ndkMajorVersion < 15) { @@ -186,8 +198,10 @@ public static String getDefaultClangVersionForNdk(String ndkVersion) { return "8.0.2"; } else if (ndkMajorVersion < 21) { return "8.0.7"; - } else { + } else if (ndkMajorVersion == 21 && ndkMinorVersion <= 3) { return "9.0.8"; + } else { + return "9.0.9"; } }