Skip to content

Commit

Permalink
Fixes Android API level support in NDK crosstools.
Browse files Browse the repository at this point in the history
NDK r19 crosstools incorrectly reported that it supports API level 29.
NDK r21 crosstools was missing API level 30.

Fixes #13421.

PiperOrigin-RevId: 380800055
  • Loading branch information
ahumesky authored and copybara-github committed Jun 22, 2021
1 parent 640c3ef commit b4c637c
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r17.NdkMajorRevisionR17;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r18.NdkMajorRevisionR18;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r19.NdkMajorRevisionR19;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r20.NdkMajorRevisionR20;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r21.NdkMajorRevisionR21;
import com.google.devtools.build.lib.util.OS;
import java.util.Map;

Expand Down Expand Up @@ -52,8 +54,8 @@ private AndroidNdkCrosstools() {}
.put(17, new NdkMajorRevisionR17("6.0.2"))
.put(18, new NdkMajorRevisionR18("7.0.2"))
.put(19, new NdkMajorRevisionR19("8.0.2"))
.put(20, new NdkMajorRevisionR19("8.0.7")) // no changes relevant to Bazel
.put(21, new NdkMajorRevisionR19("9.0.8")) // no changes relevant to Bazel
.put(20, new NdkMajorRevisionR20("8.0.7"))
.put(21, new NdkMajorRevisionR21("9.0.8"))
.build();

public static final Map.Entry<Integer, NdkMajorRevision> LATEST_KNOWN_REVISION =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ filegroup(
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17:srcs",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r18:srcs",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19:srcs",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r20:srcs",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r21:srcs",
],
visibility = ["//src:__subpackages__"],
)
Expand All @@ -35,6 +37,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r18",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r20",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r21",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//third_party:guava",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;

/** Logic specific to Android NDK R17. */
/** Logic specific to Android NDK R18. */
public class NdkMajorRevisionR18 implements NdkMajorRevision {
private final String clangVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;

/** Generates a CrosstoolRelease proto for the Android NDK. */
final class AndroidNdkCrosstoolsR19 {
public final class AndroidNdkCrosstoolsR19 {

/**
* Creates a CrosstoolRelease proto for the Android NDK, given the API level to use and the
Expand All @@ -35,7 +35,7 @@ final class AndroidNdkCrosstoolsR19 {
*
* @return A CrosstoolRelease for the Android NDK.
*/
static CrosstoolRelease create(
public static CrosstoolRelease create(
NdkPaths ndkPaths, StlImpl stlImpl, String hostPlatform, String clangVersion) {
return CrosstoolRelease.newBuilder()
.setMajorVersion("android")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ final class ApiLevelR19 extends ApiLevel {
.putAll("26", "arm", "x86", "arm64", "x86_64")
.putAll("27", "arm", "x86", "arm64", "x86_64")
.putAll("28", "arm", "x86", "arm64", "x86_64")
.putAll("29", "arm", "x86", "arm64", "x86_64")
.build();

/** This map fill in the gaps of {@code API_LEVEL_TO_ARCHITECTURES}. */
Expand All @@ -54,7 +53,6 @@ final class ApiLevelR19 extends ApiLevel {
.put("26", "26")
.put("27", "27")
.put("28", "28")
.put("29", "29")
.build();

ApiLevelR19(EventHandler eventHandler, String repositoryName, String apiLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package(
default_visibility = ["//src:__subpackages__"],
)

licenses(["notice"])

filegroup(
name = "srcs",
srcs = glob(["*"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;

/** Logic specific to Android NDK R17. */
/** Logic specific to Android NDK R19. */
public class NdkMajorRevisionR19 implements NdkMajorRevision {
private final String clangVersion;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r20;

import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel;
import com.google.devtools.build.lib.events.EventHandler;

/** Class which encodes information from the Android NDK makefiles about API levels. */
final class ApiLevelR20 extends ApiLevel {
/** This is the contents of {@code platforms/android-*} */
private static final ImmutableListMultimap<String, String> API_LEVEL_TO_ARCHITECTURES =
ImmutableListMultimap.<String, String>builder()
.putAll("16", "arm", "x86")
.putAll("17", "arm", "x86")
.putAll("18", "arm", "x86")
.putAll("19", "arm", "x86")
.putAll("21", "arm", "x86", "arm64", "x86_64")
.putAll("22", "arm", "x86", "arm64", "x86_64")
.putAll("23", "arm", "x86", "arm64", "x86_64")
.putAll("24", "arm", "x86", "arm64", "x86_64")
.putAll("26", "arm", "x86", "arm64", "x86_64")
.putAll("27", "arm", "x86", "arm64", "x86_64")
.putAll("28", "arm", "x86", "arm64", "x86_64")
.putAll("29", "arm", "x86", "arm64", "x86_64")
.build();

/** This map fill in the gaps of {@code API_LEVEL_TO_ARCHITECTURES}. */
private static final ImmutableMap<String, String> API_EQUIVALENCIES =
ImmutableMap.<String, String>builder()
.put("16", "16")
.put("17", "16")
.put("18", "18")
.put("19", "19")
.put("20", "19")
.put("21", "21")
.put("22", "22")
.put("23", "23")
.put("24", "24")
.put("25", "24")
.put("26", "26")
.put("27", "27")
.put("28", "28")
.put("29", "29")
.build();

ApiLevelR20(EventHandler eventHandler, String repositoryName, String apiLevel) {
super(API_LEVEL_TO_ARCHITECTURES, API_EQUIVALENCIES, eventHandler, repositoryName, apiLevel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_visibility = ["//src:__subpackages__"],
)

licenses(["notice"])

filegroup(
name = "srcs",
srcs = glob(["*"]),
visibility = ["//src:__subpackages__"],
)

java_library(
name = "r20",
srcs = glob(["*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/protobuf:crosstool_config_java_proto",
"//third_party:guava",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r20;

import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkMajorRevision;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkPaths;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.StlImpl;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r19.AndroidNdkCrosstoolsR19;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;

/** Logic specific to Android NDK R20. */
public class NdkMajorRevisionR20 implements NdkMajorRevision {
private final String clangVersion;

public NdkMajorRevisionR20(String clangVersion) {
this.clangVersion = clangVersion;
}

@Override
public CrosstoolRelease crosstoolRelease(
NdkPaths ndkPaths, StlImpl stlImpl, String hostPlatform) {
// NDK r20 is the same as r19 for bazel, other than API level differences below.
return AndroidNdkCrosstoolsR19.create(ndkPaths, stlImpl, hostPlatform, clangVersion);
}

@Override
public ApiLevel apiLevel(EventHandler eventHandler, String name, String apiLevel) {
return new ApiLevelR20(eventHandler, name, apiLevel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r21;

import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel;
import com.google.devtools.build.lib.events.EventHandler;

/** Class which encodes information from the Android NDK makefiles about API levels. */
final class ApiLevelR21 extends ApiLevel {
/** This is the contents of {@code platforms/android-*} */
private static final ImmutableListMultimap<String, String> API_LEVEL_TO_ARCHITECTURES =
ImmutableListMultimap.<String, String>builder()
.putAll("16", "arm", "x86")
.putAll("17", "arm", "x86")
.putAll("18", "arm", "x86")
.putAll("19", "arm", "x86")
.putAll("21", "arm", "x86", "arm64", "x86_64")
.putAll("22", "arm", "x86", "arm64", "x86_64")
.putAll("23", "arm", "x86", "arm64", "x86_64")
.putAll("24", "arm", "x86", "arm64", "x86_64")
.putAll("26", "arm", "x86", "arm64", "x86_64")
.putAll("27", "arm", "x86", "arm64", "x86_64")
.putAll("28", "arm", "x86", "arm64", "x86_64")
.putAll("29", "arm", "x86", "arm64", "x86_64")
.putAll("30", "arm", "x86", "arm64", "x86_64")
.build();

/** This map fill in the gaps of {@code API_LEVEL_TO_ARCHITECTURES}. */
private static final ImmutableMap<String, String> API_EQUIVALENCIES =
ImmutableMap.<String, String>builder()
.put("16", "16")
.put("17", "16")
.put("18", "18")
.put("19", "19")
.put("20", "19")
.put("21", "21")
.put("22", "22")
.put("23", "23")
.put("24", "24")
.put("25", "24")
.put("26", "26")
.put("27", "27")
.put("28", "28")
.put("29", "29")
.put("30", "30")
.build();

ApiLevelR21(EventHandler eventHandler, String repositoryName, String apiLevel) {
super(API_LEVEL_TO_ARCHITECTURES, API_EQUIVALENCIES, eventHandler, repositoryName, apiLevel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_visibility = ["//src:__subpackages__"],
)

licenses(["notice"])

filegroup(
name = "srcs",
srcs = glob(["*"]),
visibility = ["//src:__subpackages__"],
)

java_library(
name = "r21",
srcs = glob(["*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/protobuf:crosstool_config_java_proto",
"//third_party:guava",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r21;

import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkMajorRevision;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkPaths;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.StlImpl;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r19.AndroidNdkCrosstoolsR19;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;

/** Logic specific to Android NDK R21. */
public class NdkMajorRevisionR21 implements NdkMajorRevision {
private final String clangVersion;

public NdkMajorRevisionR21(String clangVersion) {
this.clangVersion = clangVersion;
}

@Override
public CrosstoolRelease crosstoolRelease(
NdkPaths ndkPaths, StlImpl stlImpl, String hostPlatform) {
// NDK r21 is the same as r19 for bazel, other than API level differences below.
return AndroidNdkCrosstoolsR19.create(ndkPaths, stlImpl, hostPlatform, clangVersion);
}

@Override
public ApiLevel apiLevel(EventHandler eventHandler, String name, String apiLevel) {
return new ApiLevelR21(eventHandler, name, apiLevel);
}
}

0 comments on commit b4c637c

Please sign in to comment.