Skip to content

Commit 3968551

Browse files
committed
Introduce hermetic MSVC+msbuild toolchain
1 parent f15fe9a commit 3968551

8 files changed

Lines changed: 684 additions & 14 deletions

File tree

.adms/bazel/adms.mirror.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ rewrite (ftp.osuosl.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
113113
rewrite (gnupg.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
114114
rewrite (kerberos.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
115115
rewrite (packages.microsoft.com)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
116+
rewrite (download.visualstudio.microsoft.com)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
116117
rewrite (www.freetds.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
117118
rewrite (www.lua.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
118119
rewrite (www.sqlite.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ common:windows --repo_env=PIP_CACHE_DIR # https://pip.pypa.io/en/stable/topics/c
8080
common:windows --repo_env=SYSTEMDRIVE # needed by vswhere to locate the VS installer instance database
8181
common:windows --repo_env=SYSTEMROOT # used by COM to load system DLLs, needed by vswhere
8282
common:windows --repo_env=USERPROFILE # used by MSYS2 bash to emulate HOME, needed by git to fetch repositories
83-
common:windows --repo_env=VSTUDIO_ROOT # visual_studio(path_variable) in MODULE.bazel
83+
common:windows --repo_env=VSTUDIO_ROOT # visual_studio(path_variable) in MODULE.bazel; MSBuild-only
84+
common:windows --repo_env=BAZEL_TOOLCHAINS_MSVC_ACCEPT_MICROSOFT_VISUAL_STUDIO_BUILDTOOLS_EULA=1 # @toolchains_msvc
8485
common:windows --run_env=__COMPAT_LAYER=RunAsInvoker # install*.exe may otherwise fail claiming unneeded admin elevation
8586
common:windows --test_env=__COMPAT_LAYER=RunAsInvoker # same, for bazel test
8687
common:windows --shell_executable=C:/tools/msys64/usr/bin/bash.exe

MODULE.bazel

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bazel_dep(name = "rules_rust_prost", version = "0.73.0")
8181
bazel_dep(name = "rules_shell", version = "0.8.0")
8282
bazel_dep(name = "toml.bzl", version = "0.4.1")
8383
bazel_dep(name = "toolchains_llvm", version = "1.8.0")
84+
bazel_dep(name = "toolchains_msvc", version = "0.1.0")
8485

8586
bazel_dep(name = "rules_testing", version = "0.9.0", dev_dependency = True)
8687

@@ -261,6 +262,16 @@ use_repo(linux_headers_ext, "linux_headers", "linux_headers_aarch64", "linux_hea
261262
## Compilers and toolchains ##
262263
####################################
263264

265+
git_override(
266+
module_name = "toolchains_msvc",
267+
commit = "8e2aa4624bbb5a53a94f135e90995f307875d1ad",
268+
patch_strip = 1,
269+
# Adds MSBuild + the VC project system, and whole-tree filegroups, so MSBuild-driven
270+
# builds (CPython) can run against the same hermetic toolchain as rules_cc.
271+
patches = ["//bazel/patches:toolchains_msvc/0001-hermetic-msbuild-and-toolchain-trees.patch"],
272+
remote = "https://github.com/Dragnalith/toolchains_msvc",
273+
)
274+
264275
archive_override(
265276
module_name = "gcc_toolchain",
266277
patch_args = ["-p1"],
@@ -361,20 +372,35 @@ winlibs_mingw_repository(
361372
url = "https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-19.1.7-12.0.0-msvcrt-r3/winlibs-x86_64-posix-seh-gcc-14.2.0-mingw-w64msvcrt-12.0.0-r3.zip",
362373
)
363374

375+
# Hermetic MSVC + Windows SDK for rules_cc (cl/link), and MSBuild for CPython
376+
# (see deps/cpython/build_python.bat). MinGW stays the default Windows cc_toolchain.
377+
msvc_toolchain = use_extension("@toolchains_msvc//:extensions.bzl", "toolchain")
378+
msvc_toolchain.toolchain_set(
379+
name = "default",
380+
# MSVC toolset version, not VS product version: VS 2022 17.14.x → 14.44
381+
# (see https://learn.microsoft.com/en-us/cpp/overview/compiler-versions).
382+
# toolchains_msvc only accepts 14.xx here, not 17.14.
383+
msvc_versions = ["14.44"],
384+
# Win11 SDK 10.0.26100; toolchains_msvc uses the trailing build number only.
385+
winsdk_versions = ["26100"],
386+
)
387+
use_repo(msvc_toolchain, "msvc_toolchains")
388+
364389
# TODO{agent-build}: Find a way to register platform-specific toolchains dynamically
365390
register_toolchains(
366391
"@gcc_toolchain_x86_64//:cc_toolchain",
367392
"@gcc_toolchain_aarch64//:cc_toolchain",
368393
"@gcc_toolchain_armv7//:cc_toolchain",
369394
"@winlibs_mingw64//:mingw_cc_toolchain",
395+
"@msvc_toolchains//:all",
370396
"@llvm_toolchain//:all", # last to avoid taking precedence over GCC toolchains
371397
)
372398

373-
# Visual Studio / MSBuild tooling, taken from the local installation
399+
# Host MSBuild for the DatadogInterop vcxproj only; CPython uses the hermetic
400+
# @msvc_toolchains//msbuild instead.
374401
visual_studio(
375402
name = "visual_studio",
376403
path_variable = "VSTUDIO_ROOT",
377-
version = "17.14.36717.8", # 18.4.11612.150
378404
)
379405

380406
# =========================================

MODULE.bazel.lock

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)