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

Migrate remote JDK / Java tools and add Bzlmod support #45

Merged
merged 15 commits into from
Nov 16, 2021

Conversation

meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Nov 10, 2021

Important changes in this PR:

  • Migrated remote JDK and java tools definitions from @bazel_tools//tools/jdk to rules_java.
  • Added support for detecting java home in local_java_repository rule so that we don't need Bazel to export DEFAULT_SYSTEM_JAVABASE
  • Added Bzlmod support to load remote JDK/ java tools dependencies and register toolchains.
  • Also added toolchain registration support in old fashion WORKSPACE way. However, the java tools are not loaded for now because it's not compatible with Bazel 4.2.1, it would feasible with Bazel 5.0.
  • Enabled CI tests for Bzlmod.

In Bzlmod, users automatically get all remote jdk dependencies and toolchains registered by depending on rules_java.
In old WORKSPACE way, users can do that by

load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()

If everyone migrate to this, we no longer need to append jdk.WORKSPACE as default workspace suffix.

After this, we only reference toolchain type targets under @bazel_tools//tools/jdk
- @bazel_tools//tools/jdk:toolchain_type
- @bazel_tools//tools/jdk:runtime_toolchain_type
@meteorcloudy
Copy link
Member Author

meteorcloudy commented Nov 10, 2021

FYI @Wyverald , to make Bzlmod support work, we need to export DEFAULT_SYSTEM_JAVABASE to module extension evaluation, can you help with that?

Update:

Hmm, looks like the evaluation env of bzl file in WORKSPACE also doesn't have DEFAULT_SYSTEM_JAVABASE, it's only available in WORKSPACE, maybe we can also only make it available in MODULE.bazel?

@meteorcloudy
Copy link
Member Author

@comius This PR is a bit huge, it's better to review each commit. ;)

@meteorcloudy
Copy link
Member Author

@comius Do we still need the federation stuff in the WORKSPACE file? I need to pass DEFAULT_SYSTEM_JAVABASE to rules_java_toolchains, and the federation repo seems to block me from doing that.

@comius
Copy link
Collaborator

comius commented Nov 10, 2021

Do we still need the federation stuff in the WORKSPACE file?

I think you should drop it if it's used anywhere. I don't think it serves any purpose.

@meteorcloudy
Copy link
Member Author

@comius I re-organized the commits to make them easier for review, also updated the PR description. PTAL~

.bazelci/presubmit.yml Show resolved Hide resolved
examples/hello-world/HelloWorld.java Outdated Show resolved Hide resolved
.bazelrc Outdated Show resolved Hide resolved
toolchains/local_java_repository.bzl Show resolved Hide resolved
toolchains/BUILD Show resolved Hide resolved
MODULE.bazel Show resolved Hide resolved
java/repositories.bzl Outdated Show resolved Hide resolved
java/repositories.bzl Outdated Show resolved Hide resolved
],
)

def remote_jdk8_repos():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps keep JDK8 remote repos. This is the only location where they are still defined.

And I was advertising on rules_appengine (which needs JDK8), this is the way to use it without installing JDK8 locally.

But we could also say we don't support JDK8 anymore.

Also, I was advertising that calling for example remote_jdk8_repos() from the WORKSPACE will have the JDK8 toolchain ready - defined and registered. Perhaps the code needs to be reorganised a bit to keep this true in the no-bzlmod world.

The user base that's using rules_java and calls in repositories.bzl, is probably really small, though. So I'm not sure, how much is worth spending time on this reorganisation + JDK8.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I added remote_jdk8_repos back, also added toolchain registration in it, but I'm not invoking it by default in rules_java_dependencies. PTAL~.

java/repositories.bzl Outdated Show resolved Hide resolved
comius
comius previously approved these changes Nov 16, 2021
MODULE.bazel Show resolved Hide resolved
java/repositories.bzl Outdated Show resolved Hide resolved
toolchains/BUILD Outdated Show resolved Hide resolved
toolchains/BUILD Outdated Show resolved Hide resolved
comius
comius previously approved these changes Nov 16, 2021
examples/hello-world/HelloWorld.java Outdated Show resolved Hide resolved
@meteorcloudy
Copy link
Member Author

@comius When is the next release for rules_java?

@comius
Copy link
Collaborator

comius commented Nov 16, 2021

@comius When is the next release for rules_java?

I don't think they were ever released :)

And also copybara looks broken - I know it wasn't a year ago.

@meteorcloudy
Copy link
Member Author

meteorcloudy commented Nov 16, 2021

I don't think they were ever released :)

OK 😂, but can you tag a 4.1.0 or 5.0.0 version after merging this? So I don't have to cherry-pick those change into the Bazel Central Registry.

And also copybara looks broken - I know it wasn't a year ago.

Should I send the changes via internal CL?

Update: OK, I see, it's imported, will fix the presubmit issue.

@comius
Copy link
Collaborator

comius commented Nov 16, 2021

I don't think they were ever released :)

OK 😂, but can you tag a 4.1.0 or 5.0.0 version after merging this? So I don't have to cherry-pick those change into the Bazel Central Registry.

Of course. I'll tag it 5.0.0.

And also copybara looks broken - I know it wasn't a year ago.

Should I send the changes via internal CL?

Update: OK, I see, it's imported, will fix the presubmit issue.

Thanks!

@bazel-io bazel-io merged commit 7a3c520 into bazelbuild:master Nov 16, 2021
@meteorcloudy
Copy link
Member Author

Ping @comius for tagging a 5.0.0 version ;)

@comius
Copy link
Collaborator

comius commented Nov 23, 2021

Ping @comius for tagging a 5.0.0 version ;)

Sorry, done.

@meteorcloudy
Copy link
Member Author

Thanks! 🎉

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