Skip to content

Commit

Permalink
Switch rules_java rule macro redirects from native.* to those def…
Browse files Browse the repository at this point in the history
…ined locally

Using the rules requires a bazel version that contains all the changes in bazelbuild/bazel#23591

PiperOrigin-RevId: 673847088
Change-Id: Iaaf824fbae4dced297baa6a336b2e7b8b6c3ccb5
  • Loading branch information
hvadehra authored and rules_java Copybara committed Sep 12, 2024
1 parent 421c655 commit 70970af
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 57 deletions.
74 changes: 40 additions & 34 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ test_targets: &test_targets
buildifier: latest

tasks:
# TODO: add config for 8.0.0 once released
# Bazel 7.x
# TODO: fix versions after 7.4.0
ubuntu2004:
name: "Bazel 7.x"
bazel: "9e3fa2a2e98db4aa10918a981325cfa9473e4ed8"
build_targets: *build_targets
test_targets: *test_targets
ubuntu2004_integration:
name: "Integration Tests"
name: "Bazel 7.x Integration"
bazel: "9e3fa2a2e98db4aa10918a981325cfa9473e4ed8"
platform: ubuntu2004
working_directory: "test/repo"
shell_commands:
Expand All @@ -35,14 +41,30 @@ tasks:
- "//:bin_deploy.jar"
- "@rules_java//java/..."
macos:
name: "Bazel 7.x"
bazel: "9e3fa2a2e98db4aa10918a981325cfa9473e4ed8"
build_targets: *build_targets
windows:
name: "Bazel 7.x"
bazel: "9e3fa2a2e98db4aa10918a981325cfa9473e4ed8"
build_targets: *build_targets
# Bazel@HEAD
ubuntu2004_head:
name: "Bazel@HEAD"
bazel: last_green
platform: ubuntu2004
build_targets: *build_targets
ubuntu2004_integration_head:
name: "Bazel@HEAD Integration"
bazel: last_green
platform: ubuntu2004
working_directory: "test/repo"
shell_commands:
- sh setup.sh
build_targets:
- "//..."
- "//:bin_deploy.jar"
- "@rules_java//java/..."
macos_head:
name: "Bazel@HEAD"
bazel: last_green
Expand All @@ -53,36 +75,20 @@ tasks:
bazel: last_green
platform: windows
build_targets: *build_targets
ubuntu2004_bzlmod:
name: "bzlmod"
platform: ubuntu2004
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
macos_bzlmod:
name: "bzlmod"
platform: macos
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
windows_bzlmod:
name: "bzlmod"
platform: windows
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
ubuntu2004_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: ubuntu2004
build_targets: *build_targets
macos_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: macos
build_targets: *build_targets
windows_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: windows
build_targets: *build_targets
# Bazel 6.x
# TODO: re-enable if possible to redirect to native rule impl
# ubuntu2004_bazel630:
# name: "Bazel 6.3.0"
# bazel: 6.3.0
# platform: ubuntu2004
# build_targets: *build_targets
# macos_bazel630:
# name: "Bazel 6.3.0"
# bazel: 6.3.0
# platform: macos
# build_targets: *build_targets
# windows_bazel630:
# name: "Bazel 6.3.0"
# bazel: 6.3.0
# platform: windows
# build_targets: *build_targets
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build:bzlmod --experimental_enable_bzlmod
common --incompatible_disallow_empty_glob
common --experimental_rule_extension_api

common --incompatible_disallow_empty_glob
# TODO: remove once https://github.com/bazelbuild/bazel/commit/384e381fa841537987691f170ed9408dcfeed2ea is available
common --experimental_google_legacy_api
10 changes: 9 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bazel_dep(name = "bazel_features", version = "1.11.0")
bazel_dep(name = "bazel_skylib", version = "1.6.1")

# Required by @remote_java_tools, which is loaded via module extension.
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "rules_license", version = "0.0.3")
bazel_dep(name = "abseil-cpp", version = "20230802.1", repo_name = "com_google_absl")

Expand Down Expand Up @@ -97,3 +97,11 @@ single_version_override(
module_name = "rules_python",
version = "0.24.0",
)

# TODO: drop this & update version from BCR above
archive_override(
module_name = "rules_cc",
integrity = "sha256-ZvxtrlaB2jZk56tUDasvs4b1ThcPMaEa64u+MZSwf1E=",
strip_prefix = "rules_cc-0.0.10-rc2",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.10-rc2/rules_cc-0.0.10-rc2.tar.gz"],
)
5 changes: 5 additions & 0 deletions java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ licenses(["notice"])
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//java/bazel:srcs",
"//java/bazel/common:srcs",
"//java/bazel/rules:srcs",
"//java/common:srcs",
"//java/private:srcs",
Expand Down Expand Up @@ -39,8 +41,10 @@ bzl_library(
],
visibility = ["//visibility:public"],
deps = [
"//java/bazel/common", # copybara-use-repo-external-label
"//java/bazel/rules", # copybara-use-repo-external-label
"//java/common",
"//java/common/rules:core_rules",
"//java/private",
],
)
Expand All @@ -66,6 +70,7 @@ filegroup(
":core_rules",
":java_single_jar",
":rules",
"//java/bazel:for_bazel_tests", # copybara-use-repo-external-label
"//java/bazel/rules:for_bazel_tests", # copybara-use-repo-external-label
"//java/common:for_bazel_tests",
"//java/private:for_bazel_tests",
Expand Down
6 changes: 6 additions & 0 deletions java/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ filegroup(
testonly = 1,
visibility = ["//java:__pkg__"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//java:__pkg__"],
)
7 changes: 7 additions & 0 deletions java/bazel/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(
name = "common",
srcs = glob(["*.bzl"]),
visibility = ["//java:__pkg__"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//java:__pkg__"],
)
4 changes: 2 additions & 2 deletions java/common/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ bzl_library(
deps = [
":android_lint_bzl",
":rule_util_bzl",
# TODO: re-enable after rules_cc release
# "@rules_cc//cc/common",
"//java/common",
"@bazel_skylib//lib:paths",
"@rules_cc//cc/common",
],
)

Expand All @@ -52,6 +51,7 @@ filegroup(
srcs = [
"BUILD",
":core_rules",
"//java/common/rules/impl:for_bazel_tests",
],
visibility = ["//java/common:__pkg__"],
)
18 changes: 18 additions & 0 deletions java/common/rules/impl/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//java/common/rules:__pkg__"],
)

bzl_library(
name = "impl",
srcs = glob(["*.bzl"]),
visibility = ["//java:__subpackages__"],
)

filegroup(
name = "for_bazel_tests",
testonly = 1,
srcs = [
"BUILD",
":impl",
],
visibility = ["//java/common/rules:__pkg__"],
)
2 changes: 1 addition & 1 deletion java/common/rules/impl/java_binary_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
load("//java/common:java_common.bzl", "java_common")
load("//java/common:java_info.bzl", "JavaInfo")
load("//java/common:java_semantics.bzl", "semantics")
load("//java/common/rules/impl:basic_java_library_impl.bzl", "basic_java_library", "collect_deps")
load("//third_party/protobuf/bazel/common:proto_info.bzl", "ProtoInfo")
load(":java_binary_deploy_jar.bzl", "create_deploy_archive")
load(":java_helper.bzl", "helper")

Expand Down
5 changes: 3 additions & 2 deletions java/java_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""java_binary rule"""

load("//java/bazel/rules:bazel_java_binary_wrapper.bzl", _java_binary = "java_binary")

def java_binary(**attrs):
"""Bazel java_binary rule.
Expand All @@ -22,5 +24,4 @@ def java_binary(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-java
native.java_binary(**attrs)
_java_binary(**attrs)
5 changes: 3 additions & 2 deletions java/java_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""java_import rule"""

load("//java/bazel/rules:bazel_java_import.bzl", _java_import = "java_import")

def java_import(**attrs):
"""Bazel java_import rule.
Expand All @@ -22,5 +24,4 @@ def java_import(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-java
native.java_import(**attrs)
_java_import(**attrs)
5 changes: 3 additions & 2 deletions java/java_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""java_library rule"""

load("//java/bazel/rules:bazel_java_library.bzl", _java_library = "java_library")

def java_library(**attrs):
"""Bazel java_library rule.
Expand All @@ -22,5 +24,4 @@ def java_library(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-java
native.java_library(**attrs)
_java_library(**attrs)
5 changes: 3 additions & 2 deletions java/java_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""java_plugin rule"""

load("//java/bazel/rules:bazel_java_plugin.bzl", _java_plugin = "java_plugin")

def java_plugin(**attrs):
"""Bazel java_plugin rule.
Expand All @@ -22,5 +24,4 @@ def java_plugin(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-java
native.java_plugin(**attrs)
_java_plugin(**attrs)
5 changes: 3 additions & 2 deletions java/java_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""java_test rule"""

load("//java/bazel/rules:bazel_java_test.bzl", _java_test = "java_test")

def java_test(**attrs):
"""Bazel java_test rule.
Expand All @@ -22,5 +24,4 @@ def java_test(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-java
native.java_test(**attrs)
_java_test(**attrs)
7 changes: 7 additions & 0 deletions test/repo/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build:bzlmod --experimental_enable_bzlmod

common --incompatible_disallow_empty_glob
common --experimental_rule_extension_api

# TODO: remove once https://github.com/bazelbuild/bazel/commit/384e381fa841537987691f170ed9408dcfeed2ea is available
common --experimental_google_legacy_api
8 changes: 6 additions & 2 deletions test/repo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_java//java:java_binary.bzl", "java_binary") # copybara-use-repo-external-label
load("@rules_java//java:java_library.bzl", "java_library") # copybara-use-repo-external-label
load("@rules_java//java:defs.bzl", "java_binary", "java_library") # copybara-use-repo-external-label
load("@rules_java//toolchains:default_java_toolchain.bzl", "default_java_toolchain") # copybara-use-repo-external-label

java_library(
name = "lib",
Expand All @@ -11,3 +11,7 @@ java_binary(
main_class = "Main",
runtime_deps = [":lib"],
)

default_java_toolchain(
name = "my_funky_toolchain",
)
39 changes: 39 additions & 0 deletions test/repo/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,42 @@ archive_override(
module_name = "rules_java",
urls = ["file:///tmp/rules_java-HEAD.tar.gz"],
)

java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(
java_toolchains,
"local_jdk",
"remote_java_tools",
"remote_java_tools_darwin_arm64",
"remote_java_tools_darwin_x86_64",
"remote_java_tools_linux",
"remote_java_tools_windows",
"remotejdk11_linux",
"remotejdk11_linux_aarch64",
"remotejdk11_linux_ppc64le",
"remotejdk11_linux_s390x",
"remotejdk11_macos",
"remotejdk11_macos_aarch64",
"remotejdk11_win",
"remotejdk11_win_arm64",
"remotejdk17_linux",
"remotejdk17_linux_s390x",
"remotejdk17_macos",
"remotejdk17_macos_aarch64",
"remotejdk17_win",
"remotejdk17_win_arm64",
"remotejdk21_linux",
"remotejdk21_macos",
"remotejdk21_macos_aarch64",
"remotejdk21_win",
)

# TODO: drop this & update version from BCR above
archive_override(
module_name = "rules_cc",
integrity = "sha256-ZvxtrlaB2jZk56tUDasvs4b1ThcPMaEa64u+MZSwf1E=",
strip_prefix = "rules_cc-0.0.10-rc2",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.10-rc2/rules_cc-0.0.10-rc2.tar.gz"],
)

register_toolchains("//:all")
5 changes: 0 additions & 5 deletions test/repo/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

rules_java_dependencies()

rules_java_toolchains()

0 comments on commit 70970af

Please sign in to comment.