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

Remove deploy jar Java runtime dependency for non-executable targets #19140

Closed
wants to merge 2 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Aug 1, 2023

This allows deploy jars for java_binary targets with create_executable = False to compile for target platforms for which no standalone Java runtime is available (e.g. Android).

Along the way, this removes a redundant check (runtime.hermetic_files is never None) and ensures that files coming from the hermetic runtime are only added if hermetic is set to True.

Work towards #17085

@fmeum fmeum force-pushed the remove-deploy-jar-runtime-dep branch from bc09e22 to 09ca59f Compare August 1, 2023 10:41
@fmeum
Copy link
Collaborator Author

fmeum commented Aug 1, 2023

@hvadehra In case it's public, could you perhaps provide a bit more context on what is part of the hermetic runtime feature? I find it tricky to propose changes to the Java rules without (roughly) knowing how this is supposed to work.

For example, depending on how this feature works, it could make more sense to guard the runtime dependency behind the value of create_executable.

@fmeum fmeum marked this pull request as ready for review August 1, 2023 11:03
@fmeum fmeum requested a review from hvadehra August 1, 2023 11:03
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Aug 1, 2023
@hvadehra
Copy link
Member

hvadehra commented Aug 1, 2023

In case it's public, could you perhaps provide a bit more context on what is part of the hermetic runtime feature?

cc @cushon @jianglizhou

@fmeum
Copy link
Collaborator Author

fmeum commented Aug 1, 2023

I just checked that with this and bazelbuild/rules_java#114 and bazelbuild/rules_kotlin#1000, I can now build android_binary targets involving Java, Kotlin and deploy JARs with --java_runtime_version=remotejdk_17 (instead of local_jdk).

@cushon
Copy link
Contributor

cushon commented Aug 1, 2023

@hvadehra In case it's public, could you perhaps provide a bit more context on what is part of the hermetic runtime feature? I find it tricky to propose changes to the Java rules without (roughly) knowing how this is supposed to work.

For example, depending on how this feature works, it could make more sense to guard the runtime dependency behind the value of create_executable.

There's some background on the hermetic runtime feature here: https://mail.openjdk.org/pipermail/leyden-dev/2023-February/000107.html

For the Java rules support, it's basically bundling a JDK into the _deploy.jar when an executable is created

@fmeum
Copy link
Collaborator Author

fmeum commented Aug 1, 2023

@cushon Thanks for the pointer.

What I find surprising is that the logic at https://github.com/bazelbuild/bazel/pull/19140/files#diff-ed65b74742411654fece564fdcfdb107625e42d1383d58b73ba32d0334896dcbL212 seems to run regardless of whether the java_binary has create_executable = True. If I understood it correctly, your last statement would indicate that that's not true.

@cushon
Copy link
Contributor

cushon commented Aug 1, 2023

It should be fine to disable that logic if create_executable = False.

The internal java_binary wrapper guarantees that hermetic is only ever enabled if create_executable is also enabled:

    if not ctx.attr.create_executable and ctx.attr.hermetic:
        fail("hermetic specified but create_executable is false")

@fmeum
Copy link
Collaborator Author

fmeum commented Aug 1, 2023

@cushon Thanks for the confirmation.

I am slightly worried about this line as it isn't conditional on hemertic: https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl;l=212

I will push a new version that removes the runtime dependency if create_executable = False.

@cushon
Copy link
Contributor

cushon commented Aug 1, 2023

@cushon Thanks for the confirmation.

I am slightly worried about this line as it isn't conditional on hemertic: https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl;l=212

Good catch, I am preparing a fix for that

I will push a new version that removes the runtime dependency if create_executable = False.

👍

@sgowroji sgowroji added the team-Rules-Java Issues for Java rules label Aug 2, 2023
@fmeum fmeum force-pushed the remove-deploy-jar-runtime-dep branch from 09ca59f to f3de0ea Compare August 2, 2023 08:32
@fmeum fmeum changed the title Remove unused Java runtime dependency of Bazel deploy jar rule Remove deploy jar Java runtime dependency for non-executable targets Aug 2, 2023
@fmeum
Copy link
Collaborator Author

fmeum commented Aug 2, 2023

I pushed the new version.

@fmeum fmeum force-pushed the remove-deploy-jar-runtime-dep branch from f3de0ea to 93f5856 Compare August 2, 2023 08:35
copybara-service bot pushed a commit that referenced this pull request Aug 2, 2023
…bled

As noticed by fmeum in #19140 (comment)

PiperOrigin-RevId: 553198526
Change-Id: I47f0ae35c84508d4b64dc82f6f1058fe62c0d683
This allows deploy jars for `java_binary` targets with
`create_executable = False` to compile for target platforms for which no
standalone Java runtime is available (e.g. Android).

Along the way, this removes a redundant check: `runtime.hermetic_files`
is never `None`.
@fmeum fmeum force-pushed the remove-deploy-jar-runtime-dep branch from 93f5856 to 0b3131e Compare August 3, 2023 07:11
@fmeum
Copy link
Collaborator Author

fmeum commented Aug 3, 2023

@cushon I rebased onto your commit and simplified the implementation by using that hermetic implies create_executable.

@fmeum fmeum requested a review from hvadehra August 3, 2023 11:34
@hvadehra hvadehra added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Aug 3, 2023
@copybara-service copybara-service bot closed this in 132d249 Aug 4, 2023
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Aug 4, 2023
@fmeum fmeum deleted the remove-deploy-jar-runtime-dep branch August 4, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants