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
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 33 additions & 6 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
---
build_targets: &build_targets
- "//..."
# TODO: Look into broken targets in //toolchains
- "-//toolchains/..."

build_targets_bzlmod: &build_targets_bzlmod
- "//..."
- "-//toolchains/..."
meteorcloudy marked this conversation as resolved.
Show resolved Hide resolved
# TODO(pcloudy): pkg_tar doesn't work with Bzlmod due to https://github.com/bazelbuild/bazel/issues/14259
# Enable once the issue is fixed.
- "-//distro/..."

buildifier:
version: latest
warnings: "all"
tasks:
ubuntu2004:
build_targets:
- "//..."
build_targets: *build_targets
macos:
build_targets:
- "//..."
build_targets: *build_targets
windows:
build_targets:
- "//..."
build_targets: *build_targets
ubuntu2004_bzlmod:
bazel: last_green
platform: ubuntu2004
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
macos_bzlmod:
bazel: last_green
platform: macos
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
windows_bzlmod:
bazel: last_green
platform: windows
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:bzlmod --experimental_enable_bzlmod
# @local_config_cc and @local_config_xcode are no longer available as canonical repo name,
# therefore we have to override the default value of the following flags.
# TODO: Remove after fixing https://github.com/bazelbuild/bazel/issues/14279
build:bzlmod --crosstool_top=@rules_cc.0.0.1.cc_configure.local_config_cc//:toolchain
build:bzlmod --xcode_version_config=@rules_cc.0.0.1.cc_configure.local_config_xcode//:host_xcodes
45 changes: 45 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
JDK_VERSIONS = ["11", "15", "16", "17"]
PLATFORMS = ["linux", "macos", "macos_aarch64", "win"]

# Remote JDK repos for those Linux platforms are only defined for JDK 11.
EXTRA_REMOTE_JDK11_REPOS = [
"remotejdk11_linux_aarch64",
"remotejdk11_linux_ppc64le",
"remotejdk11_linux_s390x",
]

REMOTE_JDK_REPOS = [("remotejdk" + version + "_" + platform) for version in JDK_VERSIONS for platform in PLATFORMS] + EXTRA_REMOTE_JDK11_REPOS

REMOTE_JAVA_TOOLCHAINS = [("@" + name + "_toolchain_config_repo//:toolchain") for name in REMOTE_JDK_REPOS]

module(
name = "rules_java",
version = "4.0.0",
compatibility_level = 1,
toolchains_to_register = [
"//toolchains:all",
"@local_jdk//:runtime_toolchain_definition",
] + REMOTE_JAVA_TOOLCHAINS,
)

bazel_dep(name = "platforms", version = "0.0.4")
bazel_dep(name = "rules_cc", version = "0.0.1")
# rules_proto is required by @remote_java_tools, which is loaded via module extension.
bazel_dep(name = "rules_proto", version = "4.0.0")
meteorcloudy marked this conversation as resolved.
Show resolved Hide resolved

toolchains = use_extension("//java:extensions.bzl", "toolchains")

# Declare remote java tools repos
use_repo(toolchains, "remote_java_tools")
use_repo(toolchains, "remote_java_tools_linux")
use_repo(toolchains, "remote_java_tools_windows")
use_repo(toolchains, "remote_java_tools_darwin")

# Declare local jdk repo
use_repo(toolchains, "local_jdk")

# Declare all remote jdk toolchain config repos
[use_repo(toolchains, repo + "_toolchain_config_repo") for repo in REMOTE_JDK_REPOS]

# Dev dependencies
bazel_dep(name = "rules_pkg", version = "0.5.1", dev_dependency = True)
2 changes: 2 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A completely empty WORKSPACE file to replace the original WORKSPACE content when enabling Bzlmod.
# No WORKSPACE prefix or suffix are added for this file.
7 changes: 7 additions & 0 deletions examples/hello_world/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("//java:defs.bzl", "java_binary")

java_binary(
name = "hello_world",
srcs = ["HelloWorld.java"],
main_class = "HelloWorld",
)
19 changes: 19 additions & 0 deletions examples/hello_world/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World!\n");
}
}
26 changes: 26 additions & 0 deletions java/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module extensions for rules_java."""

load("//java:repositories.bzl", "java_tools_repos", "local_jdk_repo", "remote_jdk11_repos", "remote_jdk15_repos", "remote_jdk16_repos", "remote_jdk17_repos")

def _toolchains_impl(ctx):
java_tools_repos()
local_jdk_repo()
remote_jdk11_repos()
remote_jdk15_repos()
remote_jdk16_repos()
remote_jdk17_repos()

toolchains = module_extension(implementation = _toolchains_impl)
Loading