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 1695372c6b058ea4ff1d31b25bcf6981c9d17f61 Author: Peter Kovacs <[email protected]> AuthorDate: Tue Jul 21 12:14:06 2026 +0200 build/win64: add x64 (VC9 cross) toolchain, platforms, and arch selection [P1] Adds a Windows x86-64 build alongside the existing x86 build; x86 stays the default and is unchanged. - windows_cc_toolchain_config.bzl: parameterize the shared MSVC config on arch via three new attrs — masm_flags (x64 ml64 takes /c only; x86 keeps /c /coff /Cx), pdb_link_flags (x64 drops the x86-only /SAFESEH:NO), and arch_defines (per-arch CPU defines injected globally into default_compile_flags_list). - toolchain/BUILD.bazel: add the x64 cc_toolchain(+config+toolchain) using the x86_amd64 cross cl/ml64/link, VC\bin\amd64\lib.exe, SDK\lib\x64 + VC\LIB\amd64, /MACHINE:X64. Inject arch_defines: x86 -> _X86_=1/INTEL, x64 -> _AMD64_=1/X86_64 (WIN32 stays on both; the compiler auto-defines _WIN64). Fix the latent constraint bug: the x86 toolchain now targets @platforms//cpu:x86_32 (was wrongly x86_64); x64 targets x86_64. - vs_config_repo.bzl: parameterize modern-linker discovery on target arch and expose PDB_LINK_X64 (Host*\x64) for the x64 generate_pdb path. - build/platforms: windows_x86 (cpu:x86_32) / windows_x64 (cpu:x86_64). - build/BUILD.bazel: //build:arch_x86 / //build:arch_x64 config_settings. - .bazelrc: --config=x86 (default) / --config=x64, each pinning --platforms + a distinct --platform_suffix + --symlink_prefix so both output trees coexist. - MODULE.bazel: register the x64 toolchain; register windows_x64 then windows_x86 as execution platforms (x64 host runs x86_32 via WOW64) so x86 test targets resolve a test toolchain while cc/exec-tool actions stay on x64. Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit cfc239c90d48d85d0707693b2adfa1612cfe1241) --- .bazelrc | 21 +++- MODULE.bazel | 20 ++++ build/BUILD.bazel | 17 +++ build/platforms/BUILD.bazel | 26 +++++ build/toolchain/BUILD.bazel | 138 +++++++++++++++++++++++- build/toolchain/windows_cc_toolchain_config.bzl | 26 ++++- build/vs_config_repo.bzl | 14 ++- 7 files changed, 252 insertions(+), 10 deletions(-) diff --git a/.bazelrc b/.bazelrc index fb189cb300..6c308e625c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -7,4 +7,23 @@ common --enable_bzlmod common --check_direct_dependencies=off common --registry="file:///%workspace%/ext_libraries" -common --registry=https://bcr.bazel.build \ No newline at end of file +common --registry=https://bcr.bazel.build + +# ---------------------------- Architecture (x86 / x64) ---------------------------- +# x86 is the DEFAULT build (a plain `bazel build` = 32-bit). Now that the x86 +# toolchain correctly targets @platforms//cpu:x86_32, the target platform must be +# pinned explicitly (the auto host platform is x86_64 and would not resolve it). +# Each arch pins --platforms + a distinct --platform_suffix (separate bazel-out +# trees, no clobber) + --symlink_prefix (both convenience symlinks coexist). +# --config=x64 overrides these x86 defaults (all three are last-value-wins). +build --platforms=//build/platforms:windows_x86 +build --platform_suffix=x86 +build --symlink_prefix=bazel-x86- + +build:x86 --platforms=//build/platforms:windows_x86 +build:x86 --platform_suffix=x86 +build:x86 --symlink_prefix=bazel-x86- + +build:x64 --platforms=//build/platforms:windows_x64 +build:x64 --platform_suffix=x64 +build:x64 --symlink_prefix=bazel-x64- \ No newline at end of file diff --git a/MODULE.bazel b/MODULE.bazel index c88ab6f9b4..68d76092fa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -68,6 +68,26 @@ http_file( ) register_toolchains("//build/toolchain:cc_toolchain_x86_vs2008_def") +register_toolchains("//build/toolchain:cc_toolchain_x64_vs2008_def") + +# Execution platforms. ORDER MATTERS — register_execution_platforms prepends, so the +# FIRST entry is the highest-priority exec platform. +# windows_x64 (x86_64) MUST be first: it becomes the exec platform for all build +# actions and cfg="exec" tools (idlc/regmerge/cppumaker/rsc/…), so those tools are +# built x64 and run natively on this x64 host (matching the amd64 CRT staging). +# A target that requires no cc toolchain (e.g. idl_library, which just runs the +# staged tools) picks the first exec platform outright — if windows_x86 were first, +# those tools would be built x86_32 (breaking the x64 regmerge/idlc link + CRT). +# windows_x86 (x86_32) is the fallback: this x64 host also runs 32-bit binaries via +# WOW64, so x86 TEST targets (target cpu:x86_32) resolve their test toolchain here +# (Bazel runs tests on an exec platform matching the target's constraints; without +# this, x86 `bazel test` fails "no matching default_test_toolchain_type"). Only the +# test-run action lands here — cc/exec-tool actions need a cc toolchain, which is +# exec_compatible_with x86_64 only, so they never select windows_x86. +register_execution_platforms( + "//build/platforms:windows_x64", + "//build/platforms:windows_x86", +) # Use preinstalled pkg-config instead of building it from source (building it # from source requires gettext_runtime whose BUILD uses a removed cc_import builtin). register_toolchains("@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain") diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 2f89f3de29..ae582df585 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -19,6 +19,23 @@ config_setting( visibility = ["//visibility:public"], ) +# Architecture config_settings for select() in module BUILD files (Win64 Phase 2). +# Resolved from the target platform's cpu constraint (--config=x86 / --config=x64). +# The common arch defines (_X86_/INTEL vs _AMD64_/X86_64) are injected by the +# toolchain, not here; these are for the residual per-module arch conditionals +# (bridge sources, .def decoration, x64-only libs, etc.). +config_setting( + name = "arch_x86", + constraint_values = ["@platforms//cpu:x86_32"], + visibility = ["//visibility:public"], +) + +config_setting( + name = "arch_x64", + constraint_values = ["@platforms//cpu:x86_64"], + visibility = ["//visibility:public"], +) + # Debug-info staging flag — when True, flat_install also copies .pdb files. # Complement with --compilation_mode=dbg (or --features=generate_pdb_file) so # the toolchain actually produces PDB files; without that flag the .pdb output diff --git a/build/platforms/BUILD.bazel b/build/platforms/BUILD.bazel new file mode 100644 index 0000000000..1d9a9b88ae --- /dev/null +++ b/build/platforms/BUILD.bazel @@ -0,0 +1,26 @@ +# Target platforms for the dual-arch Windows build. +# Selected via --platforms (wired to --config=x86 / --config=x64 in .bazelrc); +# the target cpu constraint picks which //build/toolchain cc_toolchain resolves. +# +# windows_x86 → @platforms//cpu:x86_32 → cc_toolchain_x86_vs2008 (default build) +# windows_x64 → @platforms//cpu:x86_64 → cc_toolchain_x64_vs2008 (Win64 build) +# +# The exec (host) platform stays Bazel's auto-detected x64 Windows host for both. + +platform( + name = "windows_x86", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_32", + ], + visibility = ["//visibility:public"], +) + +platform( + name = "windows_x64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], + visibility = ["//visibility:public"], +) diff --git a/build/toolchain/BUILD.bazel b/build/toolchain/BUILD.bazel index 5a244540d0..76c8cd8601 100644 --- a/build/toolchain/BUILD.bazel +++ b/build/toolchain/BUILD.bazel @@ -1,8 +1,17 @@ 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", _LINK_WRAPPER = "LINK_WRAPPER", _PDB_LINK = "PDB_LINK") +load("@vs_config//:paths.bzl", _VS = "VS", _VC = "VC", _SDK = "SDK", _MSVC_TMP = "MSVC_TMP", _LINK_WRAPPER = "LINK_WRAPPER", _PDB_LINK = "PDB_LINK", _PDB_LINK_X64 = "PDB_LINK_X64") -# VS2008 x86 toolchain for Apache OpenOffice on Windows +# VS2008 toolchains for Apache OpenOffice on Windows. +# Two targets share one windows_cc_toolchain_config.bzl, parameterized by arch: +# * x86 (cc_toolchain_x86_vs2008) — the default build, VC\bin\{cl,ml,link}.exe, +# SDK\lib + VC\LIB, /MACHINE:X86, ml /coff /Cx. Targets @platforms//cpu:x86_32. +# * x64 (cc_toolchain_x64_vs2008) — the Win64 build, VC\bin\x86_amd64 cross tools +# (cl/ml64/link) + VC\bin\amd64\lib.exe, SDK\lib\x64 + VC\LIB\amd64, +# /MACHINE:X64, ml64 /c only. Targets @platforms//cpu:x86_64. +# The exec platform for both is this x64 Windows host (@platforms//cpu:x86_64); +# --platforms=//build/platforms:windows_{x86,x64} (via --config=x86/x64) picks the +# target arch and thus which toolchain resolves. # Paths are configured via --repo_env=VS_PATH / --repo_env=SDK_PATH in user.bazelrc. filegroup(name = "empty", srcs = []) @@ -70,6 +79,9 @@ cc_toolchain_config( }, archiver_flags = ["/MACHINE:X86"], default_link_flags = ["/MACHINE:X86"], + # Per-arch CPU defines injected globally (Win64 Phase 2) so no module BUILD + # carries an arch flag. x86 → _X86_=1, INTEL. WIN32 stays in the modules. + arch_defines = ["_X86_=1", "INTEL"], 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, @@ -97,13 +109,133 @@ cc_toolchain( toolchain( name = "cc_toolchain_x86_vs2008_def", exec_compatible_with = [ + # Exec = this x64 Windows host. "@platforms//cpu:x86_64", "@platforms//os:windows", ], target_compatible_with = [ - "@platforms//cpu:x86_64", + # FIX: the x86 toolchain builds 32-bit binaries, so its TARGET cpu is + # x86_32 — not x86_64 as it wrongly declared before. Resolved against + # //build/platforms:windows_x86 (--config=x86, the default). + "@platforms//cpu:x86_32", "@platforms//os:windows", ], toolchain = ":cc_toolchain_x86_vs2008", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) + +# ============================ x64 (Win64) toolchain ============================ + +cc_toolchain_config( + name = "vs2008_x64_config", + cpu = "x64_windows", # MSVC toolchain-config selector (not the platform cpu) + compiler = "msvc-cl", + host_system_name = "local", + target_system_name = "local", + target_libc = "msvcrt", + abi_version = "local", + abi_libc_version = "local", + toolchain_identifier = "msvc_x64_vs2008", + msvc_env_tmp = _MSVC_TMP, + # PATH: the x86_amd64 CROSS cl/link (host-x86, target-x64) resolve their own + # c1/c2 DLLs from their dir, but mspdb/1033 live in VC\BIN — so both dirs are + # on PATH. amd64\ (native x64 tools, e.g. lib.exe) is also on PATH. + msvc_env_path = ( + _SDK + "\\bin;" + + _VS + "\\Common7\\IDE;" + + _VC + "\\BIN\\x86_amd64;" + + _VC + "\\BIN\\amd64;" + + _VC + "\\BIN;" + + _VS + "\\Common7\\Tools" + ), + # Headers are arch-neutral — same INCLUDE as x86. + msvc_env_include = ( + _SDK + "\\include;" + + _VC + "\\ATLMFC\\INCLUDE;" + + _VC + "\\INCLUDE" + ), + # LIB is the x64 variant: SDK\lib\x64 + VC\...\amd64. + msvc_env_lib = ( + _SDK + "\\lib\\x64;" + + _VC + "\\ATLMFC\\LIB\\amd64;" + + _VC + "\\LIB\\amd64" + ), + tool_bin_path = _VC + "\\bin\\x86_amd64", + msvc_cl_path = _VC + "\\bin\\x86_amd64\\cl.exe", + msvc_ml_path = _VC + "\\bin\\x86_amd64\\ml64.exe", + # x64 generate_pdb path uses an x64-target modern link.exe (Host*\x64). + pdb_link_path = _PDB_LINK_X64, + # Default (non-PDB) links use the x86_amd64 cross link.exe directly. The + # mspdbsrv-endpoint wrapper (LINK_WRAPPER) is x86-link-specific and only + # matters for parallel /DEBUG PDB writes, which the default /Z7-embed build + # does not do — so x64 skips it. (If x64 debug PDB builds later hit LNK1318, + # generate an x64 wrapper in vs_config_repo.bzl and point this there.) + msvc_link_path = _VC + "\\bin\\x86_amd64\\link.exe", + # x86_amd64\ has no lib.exe; use the native amd64 archiver (runs on this x64 host). + msvc_lib_path = _VC + "\\bin\\amd64\\lib.exe", + cxx_builtin_include_directories = [ + _SDK + "\\include", + _VC + "\\ATLMFC\\INCLUDE", + _VC + "\\INCLUDE", + ], + tool_paths = { + "ar": _VC + "\\bin\\amd64\\lib.exe", + "cpp": _VC + "\\bin\\x86_amd64\\cl.exe", + "gcc": _VC + "\\bin\\x86_amd64\\cl.exe", + "gcov": "wrapper/bin/msvc_nop.bat", + # Forward slashes required (rules_foreign_cc paths.dirname only splits '/'). + "ld": (_VC + "\\bin\\x86_amd64\\link.exe").replace("\\", "/"), + "ml": _VC + "\\bin\\x86_amd64\\ml64.exe", + "nm": "wrapper/bin/msvc_nop.bat", + "objcopy": "wrapper/bin/msvc_nop.bat", + "objdump": "wrapper/bin/msvc_nop.bat", + "strip": "wrapper/bin/msvc_nop.bat", + }, + archiver_flags = ["/MACHINE:X64"], + default_link_flags = ["/MACHINE:X64"], + # Per-arch CPU defines injected globally (Win64 Phase 2). x64 → _AMD64_=1, + # X86_64. WIN32 stays in the modules; the x64 compiler auto-defines _WIN64. + arch_defines = ["_AMD64_=1", "X86_64"], + # ml64 rejects the x86 /coff and /Cx flags — assemble with /c only. + masm_flags = ["/c"], + # x64 has no SafeSEH — drop /SAFESEH:NO from the generate_pdb link. + pdb_link_flags = ["/DEBUG:FASTLINK"], + dbg_mode_debug_flag = "", + fastbuild_mode_debug_flag = "", + supports_parse_showincludes = False, + all_compile_flags = [], + conly_flags = [], + cxx_flags = [], + link_flags = [], +) + +cc_toolchain( + name = "cc_toolchain_x64_vs2008", + toolchain_identifier = "msvc_x64_vs2008", + toolchain_config = ":vs2008_x64_config", + all_files = ":empty", + ar_files = ":empty", + as_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, +) + +toolchain( + name = "cc_toolchain_x64_vs2008_def", + exec_compatible_with = [ + # Exec = this x64 Windows host. + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + target_compatible_with = [ + # Target = Win64. Resolved against //build/platforms:windows_x64 (--config=x64). + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + toolchain = ":cc_toolchain_x64_vs2008", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/build/toolchain/windows_cc_toolchain_config.bzl b/build/toolchain/windows_cc_toolchain_config.bzl index 9f17165cb6..abf9eda0f5 100644 --- a/build/toolchain/windows_cc_toolchain_config.bzl +++ b/build/toolchain/windows_cc_toolchain_config.bzl @@ -837,6 +837,20 @@ def _impl(ctx): if ctx.attr.win32_winnt_flag: default_compile_flags_list.append(ctx.attr.win32_winnt_flag) + # Per-arch CPU defines, injected globally like _HAS_ITERATOR_DEBUGGING=0 + # above so no per-module BUILD file carries an arch flag (Win64 Phase 2). + # x86 → _X86_=1, INTEL x64 → _AMD64_=1, X86_64 + # (WIN32/WNT/GUI stay in the module BUILDs — they're arch-neutral on Windows; + # the x64 compiler auto-defines _WIN64, so WIN64 is NOT defined here.) + # Values verified against origin/windows-amd64 (settings.mk -D$(CPUNAME) + + # wntmsci11.mk/wntmscx.mk), which keeps WIN32 on both arches. + for arch_def in ctx.attr.arch_defines: + default_compile_flags_list.append("/D" + arch_def) + + # MASM flags differ by arch: the x86 ml.exe takes /c /coff /Cx (/Cx keeps + # PUBLIC symbol case, /coff emits COFF). The x64 ml64.exe REJECTS both + # /coff and /Cx (it only emits COFF and preserves case), so the x64 + # toolchain passes just ["/c"]. Driven by the masm_flags attr. masm_flags_feature = feature( name = "masm_flags", flag_sets = [ @@ -845,7 +859,7 @@ def _impl(ctx): ACTION_NAMES.assemble, ACTION_NAMES.preprocess_assemble, ], - flag_groups = [flag_group(flags = ["/c", "/coff", "/Cx"])], + flag_groups = [flag_group(flags = ctx.attr.masm_flags)], ), ], ) @@ -1400,7 +1414,9 @@ def _impl(ctx): # table (e.g. ICU's icudt49_dat.obj). SafeSEH is a ship-time # mitigation and these are non-distributed debug binaries, so # disabling it here is harmless and only affects the generate_pdb path. - flag_groups = [flag_group(flags = ["/DEBUG:FASTLINK", "/SAFESEH:NO"])], + # SafeSEH is an x86-only concept; the x64 linker rejects /SAFESEH, + # so the x64 toolchain drops it via the pdb_link_flags attr. + flag_groups = [flag_group(flags = ctx.attr.pdb_link_flags)], ), ], ) @@ -1820,6 +1836,7 @@ cc_toolchain_config = rule( attrs = { "abi_libc_version": attr.string(), "abi_version": attr.string(), + "arch_defines": attr.string_list(default = []), "archiver_flags": attr.string_list(default = []), "all_compile_flags": attr.string_list(), "compiler": attr.string(), @@ -1851,6 +1868,8 @@ This is only offered as a migration bridge for projects transitioning to rule-ba "fastbuild_mode_debug_flag": attr.string(default = ""), "host_system_name": attr.string(), "link_flags": attr.string_list(), + # MASM flags: x86 ml.exe = /c /coff /Cx; x64 ml64.exe = /c only (rejects /coff, /Cx). + "masm_flags": attr.string_list(default = ["/c", "/coff", "/Cx"]), "msvc_cl_path": attr.string(default = "vc_installation_error.bat"), "msvc_env_include": attr.string(default = "msvc_not_found"), "msvc_env_lib": attr.string(default = "msvc_not_found"), @@ -1860,6 +1879,9 @@ This is only offered as a migration bridge for projects transitioning to rule-ba "msvc_link_path": attr.string(default = "vc_installation_error.bat"), "msvc_ml_path": attr.string(default = "vc_installation_error.bat"), "pdb_link_path": attr.string(default = "vc_installation_error.bat"), + # generate_pdb linker flags: x86 needs /SAFESEH:NO (modern linker enforces + # safeseh on x86); x64 drops it (safeseh is x86-only, x64 link rejects it). + "pdb_link_flags": attr.string_list(default = ["/DEBUG:FASTLINK", "/SAFESEH:NO"]), "shorten_virtual_includes": attr.bool(default = False), "supports_parse_showincludes": attr.bool(), "target_libc": attr.string(), diff --git a/build/vs_config_repo.bzl b/build/vs_config_repo.bzl index df0fb7dbc8..93ff14d308 100644 --- a/build/vs_config_repo.bzl +++ b/build/vs_config_repo.bzl @@ -48,14 +48,18 @@ _DEFAULT_PERL = "C:\\msys64\\usr\\bin\\perl.exe" # link.exe for the generate_pdb path (see _find_modern_link / PDB_LINK below). _DEFAULT_VS_MODERN = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools" -def _find_modern_link(rctx, vs_modern): - """Locate the newest VS2017+ x86-target link.exe under a BuildTools/VS root. +def _find_modern_link(rctx, vs_modern, target = "x86"): + """Locate the newest VS2017+ link.exe (for the given target arch) under a + BuildTools/VS root. The VC9 link.exe cannot write PDBs in parallel (single mspdbsrv, no /FS, the LNK1318 bug); LLVM lld-link cannot write PDBs from VC9-era CodeView at all ("Stream too short"). A modern MSVC link.exe reads the VC9 /Z7 objects natively and its mspdbsrv handles parallel PDB writes, so the generate_pdb link path uses it. Returns a placeholder if none is found (only breaks generate_pdb builds). + + target = "x86" or "x64" selects the bin\\Host*\\<target>\\link.exe leaf so the + x64 toolchain gets an x64-target modern linker for its own generate_pdb path. """ tools = rctx.path(vs_modern + "\\VC\\Tools\\MSVC") if not tools.exists: @@ -63,7 +67,7 @@ def _find_modern_link(rctx, vs_modern): best = None for ver in tools.readdir(): for host in ["Hostx64", "Hostx86"]: - link = ver.get_child("bin").get_child(host).get_child("x86").get_child("link.exe") + link = ver.get_child("bin").get_child(host).get_child(target).get_child("link.exe") if link.exists: if best == None or ver.basename > best[0]: best = (ver.basename, str(link)) @@ -79,7 +83,8 @@ def _vs_config_impl(rctx): perl = rctx.os.environ.get("PERL_PATH", _DEFAULT_PERL) vs_modern = rctx.os.environ.get("VS_MODERN_PATH", _DEFAULT_VS_MODERN) vc = vs + "\\VC" - pdb_link = _find_modern_link(rctx, vs_modern) + pdb_link = _find_modern_link(rctx, vs_modern, "x86") + pdb_link_x64 = _find_modern_link(rctx, vs_modern, "x64") debug_crt = vc + "\\redist\\Debug_NonRedist\\x86\\Microsoft.VC90.DebugCRT" def q(p): @@ -150,6 +155,7 @@ def _vs_config_impl(rctx): 'DEBUG_CRT_DIR = "{}"'.format(q(debug_crt)), 'LINK_WRAPPER = "{}"'.format(q(link_wrapper)), 'PDB_LINK = "{}"'.format(q(pdb_link)), + 'PDB_LINK_X64 = "{}"'.format(q(pdb_link_x64)), "", ]) rctx.file("paths.bzl", content)
