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

Conversation

hevrard
Copy link
Contributor

@hevrard hevrard commented Jun 11, 2020

This makes sure we refuse to build with an invalid NDK version.

Bug: b/158669059

This makes sure we refuse to build with an invalid NDK version.

Bug: b/158669059
Comment on lines 41 to 51
# Mock the correct NDK version.
# Our Bazel scripts check that the correct NDK version is installed: rather
# than downloading the 1+GB NDK just to have a matching version to pass this
# presubmit test, we "mock" the version by overwriting it manually.
export ANDROID_NDK_HOME=/opt/android-ndk-r16b
cat > $ANDROID_NDK_HOME/source.properties <<EOF
Pkg.Desc = Android NDK
Pkg.Revision = 21.0.6113669
EOF

# Setup environment.
Copy link
Member

Choose a reason for hiding this comment

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

What's going on here? if we are ok with an older ndk, why are we adding a check, and then by-passing it? FYI, we're already downloading the NDK on the build bots for the other OSes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only for kokoro/presubmit, where we don't really "build" anything. This avoids a 1GB download for the NDK on each presubmit, only to check the NDK version.

I agree this is hacky. Note that we did not download an up-to-date NDK on presubmit before this PR.

@pmuetschard do you think it is better to download 1GB on every presubmit for the sake of passing the version check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pascal and I chatted offline: Pascal is keen on having this rule being called only when we need to compile anything using the NDK.

@pmuetschard , this NDK check needs Bazel's repository_ctx.read() to check the content of the source.properties file, and I guess this is only accessible in a repository rule?

If that is so, I think you told me it's possible to pass a flag to Bazel to set the android argument of gapid_dependencies() to false?

Copy link
Member

Choose a reason for hiding this comment

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

Bazel has multiple phases of execution. I'm asking for the error failure to happen in a later phase. Alternatively, make it a warning rather than a failure.

You are already generating a dummy rule that we'll depend on. So, change the repository init code to create different dummies depending on whether it should fail or not. If it should fail, the dummy will then fail. That way it will only fail when the dummy is actually invoked.

@hevrard hevrard requested a review from pmuetschard June 12, 2020 07:02
@hevrard hevrard force-pushed the force-ndk-version branch from d062494 to ab68cff Compare June 16, 2020 11:52
@hevrard hevrard force-pushed the force-ndk-version branch from ab68cff to 651192c Compare June 16, 2020 12:30
@@ -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.

Comment on lines 41 to 51
# Mock the correct NDK version.
# Our Bazel scripts check that the correct NDK version is installed: rather
# than downloading the 1+GB NDK just to have a matching version to pass this
# presubmit test, we "mock" the version by overwriting it manually.
export ANDROID_NDK_HOME=/opt/android-ndk-r16b
cat > $ANDROID_NDK_HOME/source.properties <<EOF
Pkg.Desc = Android NDK
Pkg.Revision = 21.0.6113669
EOF

# Setup environment.
Copy link
Member

Choose a reason for hiding this comment

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

Bazel has multiple phases of execution. I'm asking for the error failure to happen in a later phase. Alternatively, make it a warning rather than a failure.

You are already generating a dummy rule that we'll depend on. So, change the repository init code to create different dummies depending on whether it should fail or not. If it should fail, the dummy will then fail. That way it will only fail when the dummy is actually invoked.

@hevrard hevrard force-pushed the force-ndk-version branch from ca62425 to c64542a Compare July 3, 2020 20:00
@hevrard
Copy link
Contributor Author

hevrard commented Jul 3, 2020

@pmuetschard thanks for the Bazel guidance, I think I reached the setup you described.

@hevrard hevrard requested a review from pmuetschard July 3, 2020 20:03
@hevrard hevrard mentioned this pull request Jul 8, 2020
@hevrard
Copy link
Contributor Author

hevrard commented Jul 8, 2020

@pmuetschard a friendly ping on this one

@pmuetschard
Copy link
Member

Make sure to squash.

@pmuetschard
Copy link
Member

FYI, our current version of bazel doesn't support 21 yet. I'm building with NDK 20 just fine, so I'm not sure why we think we need 21?

@hevrard
Copy link
Contributor Author

hevrard commented Jul 9, 2020

Thanks, we need NDK r21 in order to have access to the unified validation layer, it's documented in https://github.com/google/agi/blob/master/BUILDING.md. Bazel does not officially support NDK > r20, we asked for this support with bazelbuild/bazel#10811.

@hevrard hevrard merged commit 8579ae9 into google:master Jul 9, 2020
@hevrard hevrard deleted the force-ndk-version branch July 9, 2020 07:48
@pmuetschard
Copy link
Member

we need NDK r21

As I pointed out, it builds fine for me on 20, so I'm not sure why you say we need it.

@hevrard
Copy link
Contributor Author

hevrard commented Jul 9, 2020

It wasn't clear from my message: the unified Khronos verification layer ships only from NDK r21, and if you build with NDK < r21, you don't get it, and things go wrong when you run a report replay -- this is the scenario that prompter to file b/158669059, and hence this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants