Skip to content

Commit 86af390

Browse files
feat: add WORKSPACE backwards compatibility
1 parent 83e819d commit 86af390

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

toolchain/defs.bzl

+25-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ After commenting on the issue, `rm -fr {cache_prefix}` and re-run your command.
5757
"""
5858

5959
def toolchains(
60-
exec_os,
61-
exec_arch,
6260
version = VERSION,
6361
url_formats = [],
6462
host_platform_sha256 = HOST_PLATFORM_SHA256,
65-
host_platform_ext = _HOST_PLATFORM_EXT):
63+
host_platform_ext = _HOST_PLATFORM_EXT,
64+
exec_os = "HOST",
65+
exec_arch = "HOST"):
6666
"""
6767
Download zig toolchain and declare bazel toolchains.
6868
The platforms are not registered automatically, that should be done by
@@ -75,9 +75,22 @@ def toolchains(
7575
original_format = URL_FORMAT_NIGHTLY
7676
else:
7777
original_format = URL_FORMAT_RELEASE
78-
79-
mirror_format = original_format.replace("https://ziglang.org/", "https://mirror.bazel.build/ziglang.org/")
80-
url_formats = [mirror_format, original_format]
78+
mirror_format = original_format.replace("https://ziglang.org/", "https://mirror.bazel.build/ziglang.org/")
79+
url_formats = [mirror_format, original_format]
80+
81+
# If these are not specified by user in WORKSPACE, fall back to the old
82+
# behavior of assuming HOST is the only supported platform.
83+
if exec_os == "HOST" and exec_arch == "HOST":
84+
zig_repository(
85+
name = "zig_sdk",
86+
version = version,
87+
url_formats = url_formats,
88+
host_platform_sha256 = host_platform_sha256,
89+
host_platform_ext = host_platform_ext,
90+
exec_os = exec_os,
91+
exec_arch = exec_arch,
92+
)
93+
return
8194

8295
zig_repository(
8396
name = "zig_sdk-{}-{}".format(exec_os, exec_arch),
@@ -97,6 +110,12 @@ def _zig_repository_impl(repository_ctx):
97110
exec_arch = repository_ctx.attr.exec_arch
98111
host_os = repository_ctx.os.name
99112
host_arch = repository_ctx.os.arch
113+
114+
if exec_os == "HOST":
115+
exec_os = host_os
116+
if exec_arch == "HOST":
117+
exec_arch = host_arch
118+
100119
if exec_arch == "amd64":
101120
exec_arch = "x86_64"
102121
if host_arch == "amd64":

0 commit comments

Comments
 (0)