Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check NDK version in Bazel #331

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ To fetch the required packages, using a console type:

```
cd <sdk-path>
tools\bin\sdkmanager.bat "platforms;android-26" "build-tools;29.0.2" ndk-bundle
tools\bin\sdkmanager.bat "platforms;android-26" "build-tools;29.0.2"
```

Note: this will install the latest NDK in `<sdk-path>\ndk-bundle`. The recommended version of the NDK is **r21**.

If you do not have adb installed you can do so with:
```
cd <sdk-path>
tools\bin\sdkmanager.bat platform-tools
```

Unzip the
[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-windows-x86_64.zip)
into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment
variable to point to this directory.

### Configure the environment

Either do this globally or in your shell every time.
Expand Down Expand Up @@ -132,17 +135,24 @@ To fetch the required packages, using a console type:

```
cd <sdk-path>
tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ndk-bundle
tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2"
```

Note: this will install the latest NDK in `<sdk-path>/ndk-bundle`. The recommended version of the NDK is **r21**.

If you do not have adb installed you can do so with:
```
cd <sdk-path>
tools/bin/sdkmanager platform-tools
```

Unzip the
[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-darwin-x86_64.zip)
into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment
variable to point to this directory:

```
export ANDROID_NDK_HOME=<ndk-path>
```

### Install the XCode command line tools

After installing, ensure the XCode license is signed with:
Expand Down Expand Up @@ -199,17 +209,24 @@ To fetch the required packages, using a console type:

```
cd <sdk-path>
tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ndk-bundle
tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2"
```

Note: this will install the latest NDK in `<sdk-path>/ndk-bundle`. The recommended version of the NDK is **r21**.

If you do not have adb installed you can do so with:
```
cd <sdk-path>
tools/bin/sdkmanager platform-tools
```

Unzip the
[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip)
into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment
variable to point to this directory:

```
export ANDROID_NDK_HOME=<ndk-path>
```

### Install other libraries

```
Expand Down
2 changes: 1 addition & 1 deletion gapidapk/android/apk/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def gapid_apk(name = "", abi = "", pkg = "", libs = {}, bins = {}):
"//conditions:default": [],
}),
deps = select({
"//tools/build:android-" + name: ["@ndk_vk_validation_layer//:" + abi],
"//tools/build:android-" + name: ["@ndk_version_check//:ndk_version_check", "@ndk_vk_validation_layer//:" + abi],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the formatting here. Don't have multiple list items on a signle line.

"//conditions:default": [],
}),
)
Expand Down
12 changes: 11 additions & 1 deletion kokoro/presubmit/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ curl -L -k -s https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y clang-format-6.0

# Fake NDK with the expected version.
# Our Bazel scripts check that a specific NDK version is installed: rather
# than downloading the 1GB+ NDK just to have a matching version, we manually
# create a fake NDK with only a version file.
export ANDROID_NDK_HOME=${PWD}/android-ndk-fake
mkdir -p ${ANDROID_NDK_HOME}
cat > ${ANDROID_NDK_HOME}/source.properties <<EOF
Pkg.Desc = Android NDK
Pkg.Revision = 21.0.6113669
EOF

# Setup environment.
export ANDROID_NDK_HOME=/opt/android-ndk-r16b
export BAZEL=$BUILD_ROOT/bazel/bin/bazel
export BUILDIFIER=$BUILD_ROOT/tools/bin/buildifier
export BUILDOZER=$BUILD_ROOT/tools/bin/buildozer
Expand Down
27 changes: 27 additions & 0 deletions tools/build/rules/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,30 @@ ndk_vk_validation_layer = repository_rule(
"ANDROID_NDK_HOME",
],
)

# Enforce NDK version by checking $ANDROID_NDK_HOME/source.properties
def _ndk_version_check(repository_ctx):
# This should be updated in sync with BUILDING.md documentation
version = "21.0.6113669"
hevrard marked this conversation as resolved.
Show resolved Hide resolved
sourcePropFile = repository_ctx.os.environ["ANDROID_NDK_HOME"] + "/source.properties"
sourceProp = repository_ctx.read(sourcePropFile)
if not ("Pkg.Revision = " + version) in sourceProp:
fail("NDK version mismatch: expected version " + version + " in file " + sourcePropFile)

build = """
# Dummy rule
cc_import(
name = "ndk_version_check",
visibility = ["//visibility:public"],
)
"""

repository_ctx.file("BUILD", build)

ndk_version_check = repository_rule(
implementation = _ndk_version_check,
local = True,
environ = [
"ANDROID_NDK_HOME",
]
)
8 changes: 7 additions & 1 deletion tools/build/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# dependencies and toolchains.

load("@gapid//tools/build:cc_toolchain.bzl", "cc_configure")
load("@gapid//tools/build/rules:android.bzl", "android_native_app_glue", "ndk_vk_validation_layer")
load("@gapid//tools/build/rules:android.bzl", "android_native_app_glue", "ndk_vk_validation_layer", "ndk_version_check")
load("@gapid//tools/build/rules:repository.bzl", "github_repository", "maybe_repository")
load("@gapid//tools/build/third_party:breakpad.bzl", "breakpad")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
Expand Down Expand Up @@ -324,6 +324,12 @@ def gapid_dependencies(android = True, mingw = True, locals = {}):
locals = locals,
)

maybe_repository(
ndk_version_check,
name = "ndk_version_check",
locals = locals,
)

# Use the LLVM libc++ Android toolchain.
native.bind(
name = "android/crosstool",
Expand Down