From aa49216c38bad1e8f9c08b3793c9aef902c11068 Mon Sep 17 00:00:00 2001
From: Philipp Stephani
Date: Mon, 30 Mar 2026 02:37:26 +0200
Subject: [PATCH] Use toolchains instead of aliases for platform selection
Following https://bazel.build/extending/toolchains#toolchain-definitions, we
should use separate toolchains for each supported combination of operating
system and processor architecture.
---
MODULE.bazel | 9 +++--
check.ps1 | 8 +++--
elisp/BUILD | 44 ++++++++++++++++++++++--
elisp/private/emacs_repository.bzl | 3 +-
elisp/private/tools/emacs.BUILD.template | 7 ++--
5 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/MODULE.bazel b/MODULE.bazel
index d3170a830..a2e1ec9d6 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -112,8 +112,13 @@ junit_xsd(
dev_dependency = True,
)
-# Local toolchains
-register_toolchains("//elisp:hermetic_toolchain")
+# Local toolchains. We only register toolchains for the most recent Emacs
+# release, with binary builds coming first. Source builds will be selected as a
+# fallback in case none of the binary ones apply.
+register_toolchains(
+ "//elisp:emacs_30_windows_x86_64_toolchain",
+ "//elisp:emacs_30_toolchain",
+)
# C++-specific dependencies
bazel_dep(name = "gazelle_cc", version = "0.5.0", dev_dependency = True)
diff --git a/check.ps1 b/check.ps1
index 8a49e19d0..916f08e42 100755
--- a/check.ps1
+++ b/check.ps1
@@ -1,6 +1,6 @@
#!/usr/bin/env pwsh
-# Copyright 2021-2025 Google LLC
+# Copyright 2021-2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -54,7 +54,11 @@ Set-Location -Path $PSScriptRoot
Run-Tests
foreach ($version in $versions) {
- Run-Tests "--extra_toolchains=//elisp:emacs_${version}_toolchain"
+ $toolchains = @(
+ "//elisp:emacs_${version}_toolchain",
+ "//elisp:emacs_${version}_windows_x86_64_toolchain"
+ )
+ Run-Tests "--extra_toolchains=$($toolchains -join ',')"
}
Run-Bazel 'mod' 'graph' > $null
diff --git a/elisp/BUILD b/elisp/BUILD
index dd5d35efa..e787c8d83 100644
--- a/elisp/BUILD
+++ b/elisp/BUILD
@@ -1,4 +1,4 @@
-# Copyright 2020-2025 Google LLC
+# Copyright 2020-2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -42,12 +42,40 @@ toolchain(
toolchain_type = ":toolchain_type",
)
+toolchain(
+ name = "emacs_29_windows_x86_64_toolchain",
+ exec_compatible_with = [
+ "@platforms//os:windows",
+ "@platforms//cpu:x86_64",
+ ],
+ target_compatible_with = [
+ "@platforms//os:windows",
+ "@platforms//cpu:x86_64",
+ ],
+ toolchain = "emacs_29_windows_x86_64",
+ toolchain_type = ":toolchain_type",
+)
+
toolchain(
name = "emacs_30_toolchain",
toolchain = "emacs_30",
toolchain_type = ":toolchain_type",
)
+toolchain(
+ name = "emacs_30_windows_x86_64_toolchain",
+ exec_compatible_with = [
+ "@platforms//os:windows",
+ "@platforms//cpu:x86_64",
+ ],
+ target_compatible_with = [
+ "@platforms//os:windows",
+ "@platforms//cpu:x86_64",
+ ],
+ toolchain = "emacs_30_windows_x86_64",
+ toolchain_type = ":toolchain_type",
+)
+
toolchain(
name = "local_toolchain",
toolchain = ":local",
@@ -67,12 +95,22 @@ elisp_toolchain(
elisp_toolchain(
name = "emacs_29",
- emacs = "//emacs:emacs_29",
+ emacs = "@gnu_emacs_29//:emacs",
+)
+
+elisp_toolchain(
+ name = "emacs_29_windows_x86_64",
+ emacs = "@gnu_emacs_windows_29//:emacs",
)
elisp_toolchain(
name = "emacs_30",
- emacs = "//emacs:emacs_30",
+ emacs = "@gnu_emacs_30//:emacs",
+)
+
+elisp_toolchain(
+ name = "emacs_30_windows_x86_64",
+ emacs = "@gnu_emacs_windows_30//:emacs",
)
bzl_library(
diff --git a/elisp/private/emacs_repository.bzl b/elisp/private/emacs_repository.bzl
index d6b857762..292a4db3e 100644
--- a/elisp/private/emacs_repository.bzl
+++ b/elisp/private/emacs_repository.bzl
@@ -1,4 +1,4 @@
-# Copyright 2023-2025 Google LLC
+# Copyright 2023-2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ def _emacs_repository_impl(ctx):
{
'"[elisp_emacs_binary.bzl]"': repr(str(Label("//elisp/toolchains:elisp_emacs_binary.bzl"))),
'"[cc_library.bzl]"': repr(str(Label("@rules_cc//cc:cc_library.bzl"))),
+ '"[elisp_pkg]"': repr(str(Label("//elisp:__pkg__"))),
'"[emacs_pkg]"': repr(str(Label("//emacs:__pkg__"))),
'"[gazelle_pkg]"': repr(str(Label("//gazelle/elisp:__pkg__"))),
'"[type]"': repr(ctx.attr.type),
diff --git a/elisp/private/tools/emacs.BUILD.template b/elisp/private/tools/emacs.BUILD.template
index fbce54308..2569b3fe8 100644
--- a/elisp/private/tools/emacs.BUILD.template
+++ b/elisp/private/tools/emacs.BUILD.template
@@ -1,4 +1,4 @@
-# Copyright 2020-2022, 2024, 2025 Google LLC
+# Copyright 2020-2022, 2024-2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -38,7 +38,10 @@ elisp_emacs_binary(
module_header = "emacs-module.h",
readme = "README",
target_compatible_with = [[compatible_with]],
- visibility = ["[emacs_pkg]"],
+ visibility = [
+ "[elisp_pkg]",
+ "[emacs_pkg]",
+ ],
)
cc_library(