This is an automated email from the ASF dual-hosted git repository.

leginee pushed a commit to branch bazel-migration
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/bazel-migration by this push:
     new b008b262a7 build: register arch-neutral host JDK runtime toolchain
b008b262a7 is described below

commit b008b262a76dcef6fe1effc5d5dc6445d8bf44a7
Author: Peter Kovacs <[email protected]>
AuthorDate: Sat Jul 25 15:20:52 2026 +0200

    build: register arch-neutral host JDK runtime toolchain
    
    The default (x86) build failed analysis with:
    
      No matching toolchains found for types:
        @@bazel_tools//tools/jdk:runtime_toolchain_type
    
    jar_from_directory (build/rules/java_pipeline.bzl) needs a java
    runtime_toolchain_type to locate jar.exe.  rules_java only auto-registers
    runtime toolchains cpu-pinned to the downloaded JDK's platform (windows +
    x86_64).  Before the win64 branch the x86 toolchain was mislabelled target
    x86_64 (and no --platforms pin), so the x64 JDK matched by accident.  Once
    the x86 toolchain was corrected to target @platforms//cpu:x86_32 and the
    default build pinned --platforms=//build/platforms:winXP-x86, the 
x86_64-only
    JDK toolchain no longer matched the x86_32 target.
    
    The java runtime here is only ever a HOST BUILD TOOL (jar.exe zipping
    arch-neutral .class files; javamaker runs as a native exec cc_binary, not
    through this toolchain), so a single host JDK serves every target arch.
    Register ONE arch-neutral runtime toolchain (@local_jdk, os:windows, no cpu
    constraint) in the root module so it outranks rules_java's cpu-pinned
    remotejdk and matches every windows target platform present or future
    (x86_32, x86_64, arm64/riscv as the matrix grows) with zero new java
    toolchains.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
 MODULE.bazel                     | 13 +++++++++++++
 build/toolchain/java/BUILD.bazel | 42 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/MODULE.bazel b/MODULE.bazel
index c0619fbf17..dce9a9da85 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -52,6 +52,13 @@ bazel_dep(name = "mdds",                   version = "0.3.1")
 bazel_dep(name = "coinmp",                 version = "1.7.6")
 bazel_dep(name = "gtest",                  version = "1.7.0")  # GoogleTest — 
C++ unit-test foundation (//main/test)
 
+# Host JDK.  Expose the machine's local JDK so we can register an ARCH-NEUTRAL 
java
+# RUNTIME toolchain (see //build/toolchain/java).  rules_java only 
auto-registers
+# cpu-pinned (windows + x86_64) runtime toolchains, which stop resolving the 
moment
+# the TARGET cpu isn't x86_64 — x86_32 today, arm64/riscv as the matrix grows.
+java_toolchains = use_extension("@rules_java//java:extensions.bzl", 
"toolchains")
+use_repo(java_toolchains, "local_jdk")
+
 # --------------- build-time tools (not linked, not in registry) 
---------------
 http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", 
"http_file")
 vs_config_repo_rule = use_repo_rule("//build:vs_config_repo.bzl", 
"vs_config_repo")
@@ -70,6 +77,12 @@ http_file(
 register_toolchains("//build/toolchain:cc_toolchain_x86_vs2008_def")
 register_toolchains("//build/toolchain:cc_toolchain_x64_vs2008_def")
 
+# Arch-neutral host JDK RUNTIME toolchain.  Registered in the root module so it
+# outranks rules_java's cpu-pinned remote-JDK runtime toolchains; it matches 
EVERY
+# windows target platform (x86_32, x86_64, future arm64/riscv) so the 
jar-packaging
+# host step (java_pipeline.bzl) resolves regardless of the product's target 
arch.
+register_toolchains("//build/toolchain/java:host_jdk_runtime_toolchain")
+
 # Execution platforms.  ORDER MATTERS — register_execution_platforms prepends, 
so the
 # FIRST entry is the highest-priority exec platform.
 #   winXP-x64 (x86_64) MUST be first: it becomes the exec platform for all 
build
diff --git a/build/toolchain/java/BUILD.bazel b/build/toolchain/java/BUILD.bazel
new file mode 100644
index 0000000000..bfd627b4f3
--- /dev/null
+++ b/build/toolchain/java/BUILD.bazel
@@ -0,0 +1,42 @@
+# Arch-neutral host JDK **runtime** toolchain.
+#
+# Why this exists
+# ---------------
+# Target platforms in this build are chosen by TARGET cpu — winXP-x86 (x86_32),
+# winXP-x64 (x86_64), and the matrix is expected to grow (arm64, riscv, …).
+# rules_java, however, only auto-registers java RUNTIME toolchains that are
+# cpu-pinned to the downloaded JDK's own platform (windows + x86_64).  The 
moment
+# the target cpu isn't x86_64 that toolchain no longer resolves:
+#
+#     No matching toolchains found for types:
+#       @@bazel_tools//tools/jdk:runtime_toolchain_type
+#
+# which is exactly what broke the default (x86_32) build once the x86 toolchain
+# was corrected to target @platforms//cpu:x86_32 (before that, the x86 build 
was
+# mislabelled x86_64 and accidentally matched the x64 JDK).
+#
+# The fix — and why it is arch-neutral
+# ------------------------------------
+# This runtime toolchain is only ever used as a HOST BUILD TOOL: jar.exe 
zipping
+# arch-neutral .class files (see build/rules/java_pipeline.bzl 
jar_from_directory).
+# javamaker itself runs as a native exec-cfg cc_binary, NOT through this 
toolchain.
+# So a single host JDK serves EVERY target arch.  We therefore register ONE 
runtime
+# toolchain with no cpu constraint; it matches any windows target platform, 
present
+# or future, and the matrix expands without adding a java toolchain per arch.
+#
+# It is registered in the ROOT module (MODULE.bazel), so it outranks 
rules_java's
+# cpu-pinned remote-JDK runtime toolchains and is selected for both x86 and 
x64.
+
+toolchain(
+    name = "host_jdk_runtime_toolchain",
+    # The machine's local JDK (JAVA_HOME), wired via the rules_java 
`toolchains`
+    # module extension in MODULE.bazel.  It runs natively on the x64 build host
+    # regardless of the TARGET arch of the product being built.
+    toolchain = "@local_jdk//:jdk",
+    toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
+    # No cpu constraint: arch-neutral by design (see header).  os:windows only,
+    # so it matches every windows target platform in the matrix.
+    target_compatible_with = ["@platforms//os:windows"],
+    exec_compatible_with = ["@platforms//os:windows"],
+    visibility = ["//visibility:public"],
+)

Reply via email to