-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
User-accessible JavaInfo constructor doesn't allow changing module_flags_info #20033
Comments
I've made two PRs that implement approach 1 above:
|
@timothyg-stripe awesome! can you actually resubmit this one, timothyg-stripe#1 against the bazelbuild repo instead of your own, so that we can assign and review it? |
@iancha1992 Done – I refrained from doing that at first since there's a merge conflict between the two PRs, but I can fix up the conflict later when one of the two PRs gets merged. |
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency). Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection). Addresses half of #20033. Closes #20036. PiperOrigin-RevId: 580472097 Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x. Second half of #20033 Closes #20037. PiperOrigin-RevId: 582982387 Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
@iancha1992 Can we backport #20036 and #20037 to 7.0? |
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency). Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection). Addresses half of bazelbuild#20033. Closes bazelbuild#20036. PiperOrigin-RevId: 580472097 Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x. Second half of bazelbuild#20033 Closes bazelbuild#20037. PiperOrigin-RevId: 582982387 Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x. Second half of bazelbuild#20033 Closes bazelbuild#20037. PiperOrigin-RevId: 582982387 Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
Hi @timothyg-stripe would you mind just sending a PR against the release-7.0.0 branch with all the changes you need? Since we're cutting it very close to the final RC, this would save us the back and forth. |
@bazel-io fork 7.0.0 |
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency). Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection). Addresses half of bazelbuild#20033. Closes bazelbuild#20036. PiperOrigin-RevId: 580472097 Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x. Second half of bazelbuild#20033 Closes bazelbuild#20037. PiperOrigin-RevId: 582982387 Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x. Second half of bazelbuild#20033 Closes bazelbuild#20037. PiperOrigin-RevId: 582982387 Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
A fix for this issue has been included in Bazel 7.0.0 RC5. Please test out the release candidate and report any issues as soon as possible. Thanks! |
Description of the feature request:
The user-accessible
JavaInfo
constructor runs_javainfo_init
, which does not allow customizingmodule_flags_info
. This means that it's impossible to replicate some of the semantics ofjava_info_for_compilation
that would be useful for third party rulesets (like rules_scala), like:add_exports
andadd_opens
attributes for a third-party ruleruntime_deps
'add_exports
andadd_opens
, since_javainfo_init
only merges the module flags fordeps
andexports
.A few ways to resolve this are:
JavaInfo
constructor, likeadd_exports
andadd_opens
(for "direct" rule attributes).JavaInfo
constructor so thatadd_exports
andadd_opens
are merged forruntime_deps
in addition to justdeps
&exports
. This is IMO the right thing to do anyway, and reduces the delta betweenJavaInfo
andjava_info_for_compilation
, though it changes some user-visible behavior and probably requires an--[no]incompatible_
flag.JavaInfo
that simply wraps amodule_flags_info
. Then, users can calljava_common.merge([JavaInfo(…), java_common.wrap_module_flags_info(…)])
.java_common.merge
input validation to allowJavaInfo
-lookalikes rather than strictlyJavaInfo
objects. Then we can create a fakeJavaInfo
withmodule_flags_info
set correctly, and calljava_common.merge
to legitimize it._java_common_internal.wrap_java_info
to users so that they can legitimize theirJavaInfo
lookalikes.I'm happy to provide a patch. Please let me know which approach seems the most reasonable.
cc @hvadehra @cushon
Which category does this issue belong to?
Java Rules, Rules API
What underlying problem are you trying to solve with this feature?
No response
Which operating system are you running Bazel on?
No response
What is the output of
bazel info release
?No response
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: