Skip to content

Commit

Permalink
Remove rules_java_builtin in WORKSPACE prefix
Browse files Browse the repository at this point in the history
Benefits:
- Less hack in WORKSPACE
- Smaller Bazel binary size since we no longer embed rules_java

Costs:
- WORKSPACE users have to always fetch rules_java.
- WORKSPACE users have to ensure a compatible rules_java is defined.

Closes #23773.

PiperOrigin-RevId: 679558506
Change-Id: I0fd2672b1d9178100d4010156dfbbe2bcf7006da
  • Loading branch information
meteorcloudy authored and copybara-github committed Sep 27, 2024
1 parent 55eb334 commit 7506690
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 119 deletions.
15 changes: 1 addition & 14 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ filegroup(
srcs = [
"//src/main/java/com/google/devtools/build/lib/bazel/rules:builtins_bzl.zip",
"//src/main/java/com/google/devtools/build/lib/bazel/rules:coverage.WORKSPACE",
"//src/main/java/com/google/devtools/build/lib/bazel/rules:rules_license.WORKSPACE",
"//src/main/java/com/google/devtools/build/lib/bazel/rules:rules_suffix.WORKSPACE",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp:cc_configure.WORKSPACE",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/java:jdk.WORKSPACE",
],
)

Expand Down Expand Up @@ -198,17 +197,6 @@ pkg_tar(
visibility = ["//:__subpackages__"],
)

pkg_tar(
name = "rules_java-srcs",
srcs = ["@rules_java//:distribution"],
remap_paths = {
"external/": "",
"../": "",
},
strip_prefix = ".",
visibility = ["//:__subpackages__"],
)

write_file(
name = "gen_maven_repo_name",
out = "MAVEN_CANONICAL_REPO_NAME",
Expand Down Expand Up @@ -263,7 +251,6 @@ genrule(
":bazel-srcs",
":bootstrap-jars",
":platforms-srcs",
":rules_java-srcs",
":maven-srcs",
"//src:derived_java_srcs",
"@bootstrap_repo_cache//:archives.tar",
Expand Down
2 changes: 0 additions & 2 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ md5_cmd = "set -e -o pipefail && %s $(SRCS) | %s | %s > $@"
"//src/main/tools:linux-sandbox",
"//tools/osx:xcode-locator",
"//:platforms-srcs",
"//:rules_java-srcs",
] + select({
"//src/conditions:windows": [],
"//conditions:default": [
Expand Down Expand Up @@ -248,7 +247,6 @@ genrule(
"//src/main/java/com/google/devtools/build/lib/bazel:BazelServer_deploy.jar",
"install_base_key" + suffix,
"//:platforms-srcs",
"//:rules_java-srcs",
# Non-ordered items follow:
"//src/main/java/net/starlark/java/eval:cpu_profiler",
"//src/main/tools:build-runfiles",
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ java_library(
"xcode_configure.WORKSPACE",
":builtins_bzl_zip",
":coverage.WORKSPACE",
":rules_license.WORKSPACE",
":rules_suffix.WORKSPACE",
],
deps = [
"//src/main/java/com/google/devtools/build/lib:runtime",
Expand Down Expand Up @@ -132,13 +132,25 @@ gen_workspace_stanza(
)

gen_workspace_stanza(
name = "rules_license",
out = "rules_license.WORKSPACE",
name = "rules_suffix",
out = "rules_suffix.WORKSPACE",
postamble = """
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()
""",
preamble = """
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
""",
repos = ["rules_license"],
repos = [
"bazel_skylib", # Dependency of other rules
"rules_java", # For auto-load java rules symbols
"rules_cc", # For auto-load cc rules symbols
"rules_python", # For auto-load python rules symbols
"rules_license", # for license attestations
"rules_proto",
],
use_maybe = 1,
visibility = ["//:__pkg__"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,8 @@ public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
ResourceFileLoader.loadResource(BazelRulesModule.class, "xcode_configure.WORKSPACE"));
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(BazelShRuleClasses.class, "sh_configure.WORKSPACE"));

// Load rules_license, which is needed for license attestations for many rules, including
// things in @bazel_tools
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(BazelRulesModule.class, "rules_license.WORKSPACE"));
ResourceFileLoader.loadResource(BazelRulesModule.class, "rules_suffix.WORKSPACE"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
EXPERIMENTAL_JAVA_LIBRARY_EXPORT, Starlark.NONE));

try {
builder.addWorkspaceFilePrefix(
ResourceFileLoader.loadResource(
BazelJavaRuleClasses.class, "rules_java_builtin.WORKSPACE"));
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(BazelJavaRuleClasses.class, "jdk.WORKSPACE"));
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(JavaRules.class, "coverage.WORKSPACE"));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//:workspace_deps.bzl", "gen_workspace_stanza")

package(
default_applicable_licenses = ["//:license"],
Expand All @@ -24,10 +23,7 @@ java_library(
[
"*.txt",
],
) + [
":jdk.WORKSPACE",
":rules_java_builtin.WORKSPACE",
],
),
deps = [
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
Expand Down Expand Up @@ -67,23 +63,3 @@ java_library(
"//third_party:jsr305",
],
)

gen_workspace_stanza(
name = "workspace_with_java_toolchains",
out = "jdk.WORKSPACE",
repo_clause = """
name = "{repo}",
sha256 = "{sha256}",
strip_prefix = {strip_prefix},
urls = {urls},
""",
repos = [
"bazel_skylib",
"rules_cc",
"rules_java",
"rules_proto",
"rules_python",
],
template = "jdk.WORKSPACE.tmpl",
visibility = ["//:__pkg__"],
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local_repository(
name = "bazel_tools",
path = __embedded_dir__ + "/embedded_tools",
repo_mapping = {"@rules_java" : "@rules_java_builtin"}
)

bind(
Expand Down
13 changes: 0 additions & 13 deletions src/package-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ EMBEDDED_TOOLS=$1; shift
DEPLOY_JAR=$1; shift
INSTALL_BASE_KEY=$1; shift
PLATFORMS_ARCHIVE=$1; shift
RULES_JAVA_ARCHIVE=$1; shift

if [[ "$OUT" == *jdk_allmodules.zip ]]; then
DEV_BUILD=1
Expand Down Expand Up @@ -79,18 +78,6 @@ fi
# "platforms" is a well-known module, so no need to tamper with anything here.
)

(
cd $PACKAGE_DIR
tar -xf $WORKDIR/$RULES_JAVA_ARCHIVE -C .
# Rename "rules_java~" or "rules_java+" to "rules_java".
if [[ -d rules_java~ ]]; then
mv rules_java~ rules_java
fi
if [[ -d rules_java+ ]]; then
mv rules_java+ rules_java
fi
)

# Make a list of the files in the order we want them inside the final zip.
(
cd $PACKAGE_DIR
Expand Down

0 comments on commit 7506690

Please sign in to comment.