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

commit 4f99b8780476fcdd5d9fd6f35973805d484a21f1
Author: Peter Kovacs <[email protected]>
AuthorDate: Sat Jun 20 23:48:32 2026 +0200

    bazel can now link in parallel, which should speed up rebuilds on debug 
builds
---
 build/toolchain/BUILD.bazel | 12 ++++++++----
 build/vs_config_repo.bzl    | 39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/build/toolchain/BUILD.bazel b/build/toolchain/BUILD.bazel
index daae59c9f4..ab0b8b16cf 100644
--- a/build/toolchain/BUILD.bazel
+++ b/build/toolchain/BUILD.bazel
@@ -1,6 +1,6 @@
 load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain")
 load(":windows_cc_toolchain_config.bzl", "cc_toolchain_config")
-load("@vs_config//:paths.bzl", _VS = "VS", _VC = "VC", _SDK = "SDK", _MSVC_TMP 
= "MSVC_TMP")
+load("@vs_config//:paths.bzl", _VS = "VS", _VC = "VC", _SDK = "SDK", _MSVC_TMP 
= "MSVC_TMP", _LINK_WRAPPER = "LINK_WRAPPER")
 
 # VS2008 x86 toolchain for Apache OpenOffice on Windows
 # Paths are configured via --repo_env=VS_PATH / --repo_env=SDK_PATH in 
user.bazelrc.
@@ -37,7 +37,11 @@ cc_toolchain_config(
     tool_bin_path  = _VC + "\\bin",
     msvc_cl_path   = _VC + "\\bin\\cl.exe",
     msvc_ml_path   = _VC + "\\bin\\ml.exe",
-    msvc_link_path = _VC + "\\bin\\link.exe",
+    # Native cc_library/cc_binary links go through the mspdbsrv-endpoint 
wrapper
+    # (see vs_config_repo.bzl) so debug (/DEBUG) builds run parallel without
+    # LNK1318.  rules_foreign_cc still uses raw link.exe via the "ld" tool_path
+    # below (external libs build without /DEBUG, so no mspdbsrv contention).
+    msvc_link_path = _LINK_WRAPPER,
     msvc_lib_path  = _VC + "\\bin\\lib.exe",
     cxx_builtin_include_directories = [
         _SDK + "\\include",
@@ -60,8 +64,8 @@ cc_toolchain_config(
     },
     archiver_flags         = ["/MACHINE:X86"],
     default_link_flags     = ["/MACHINE:X86"],
-    dbg_mode_debug_flag      = "",   # /Z7 embeds debug info in objects; no 
mspdbsrv.exe under parallel links
-    fastbuild_mode_debug_flag = "",  # same — /Z7 embeds, no linker PDB
+    dbg_mode_debug_flag      = "",   # /Z7 embeds debug info in objects at 
compile; linker PDB (/DEBUG via --features=generate_pdb) uses the per-action 
mspdbsrv wrapper above for parallel links
+    fastbuild_mode_debug_flag = "",  # same — /Z7 embeds, no compile-time PDB
     supports_parse_showincludes = False,
     all_compile_flags = [],
     conly_flags       = [],
diff --git a/build/vs_config_repo.bzl b/build/vs_config_repo.bzl
index dcc6bb6df3..e1f283af06 100644
--- a/build/vs_config_repo.bzl
+++ b/build/vs_config_repo.bzl
@@ -9,7 +9,16 @@ flag value so bazelrc doesn't strip backslashes):
   build --repo_env="PERL_PATH=C:/msys64/usr/bin/perl.exe"
 
 The generated @vs_config//:paths.bzl exposes VS, VC, SDK, MSVC_TMP,
-PERL, and DEBUG_CRT_DIR.
+PERL, DEBUG_CRT_DIR, and LINK_WRAPPER.
+
+LINK_WRAPPER is a generated batch file that wraps link.exe and gives every
+link action its own _MSPDBSRV_ENDPOINT_ (derived from the unique per-target
+linker param-file name).  This stops concurrent /DEBUG links from sharing one
+mspdbsrv.exe instance — the shared server falls over under parallelism with
+LNK1318 RPC_S_SERVER_UNAVAILABLE (0x6BA), which is the only reason debug builds
+ever needed --jobs=1.  Routing all links through the wrapper lets debug builds
+run fully parallel.  VS2008/VC9 has no /FS flag (added in VS2013), so the
+per-process endpoint is the only fix available here.
 """
 
 _DEFAULT_VS   = "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0"
@@ -28,6 +37,33 @@ def _vs_config_impl(rctx):
     def q(p):
         return p.replace("\\", "\\\\")
 
+    # link.exe wrapper: per-action _MSPDBSRV_ENDPOINT_ so concurrent /DEBUG 
links
+    # each get a private mspdbsrv.exe instead of sharing one (LNK1318 0x6BA).
+    # The endpoint is derived from the linker @param-file name (unique per 
target,
+    # always on the command line); falls back to %RANDOM% if no @file is 
present.
+    link_exe = vc + "\\bin\\link.exe"
+    bat = "\r\n".join([
+        "@echo off",
+        "setlocal enabledelayedexpansion",
+        "set \"ep=\"",
+        "for %%A in (%*) do (",
+        "  set \"arg=%%A\"",
+        "  if \"!arg:~0,1!\"==\"@\" set \"ep=!arg!\"",
+        ")",
+        "if not defined ep set \"ep=%RANDOM%%RANDOM%\"",
+        "set \"ep=!ep:@=!\"",
+        "set \"ep=!ep:\\=_!\"",
+        "set \"ep=!ep:/=_!\"",
+        "set \"ep=!ep:.=_!\"",
+        "set \"ep=!ep::=_!\"",
+        "set \"_MSPDBSRV_ENDPOINT_=bzl_!ep!\"",
+        "\"" + link_exe + "\" %*",
+        "exit /b !ERRORLEVEL!",
+        "",
+    ])
+    rctx.file("msvc_link.bat", bat)
+    link_wrapper = str(rctx.path("msvc_link.bat"))
+
     content = "\n".join([
         "# Auto-generated by //build:vs_config_repo.bzl — do not edit.",
         "# Set VS_PATH / SDK_PATH / MSVC_TMP / PERL_PATH via --repo_env in 
user.bazelrc.",
@@ -37,6 +73,7 @@ def _vs_config_impl(rctx):
         'MSVC_TMP = "{}"'.format(q(tmp)),
         'PERL     = "{}"'.format(q(perl)),
         'DEBUG_CRT_DIR = "{}"'.format(q(debug_crt)),
+        'LINK_WRAPPER = "{}"'.format(q(link_wrapper)),
         "",
     ])
     rctx.file("paths.bzl", content)

Reply via email to