Skip to content

Commit 550ae1b

Browse files
committed
feat: implement WASI SDK download strategy for CI
- Switch from system to download strategy for WASI SDK - Fix URL patterns to match actual WASI SDK 25 release format: - Use wasi-sdk-25.0-{arch}-{os}.tar.gz format - Correct platform mappings (darwin_arm64 -> arm64-macos) - Fix stripPrefix to match actual archive structure - Update BUILD file generation to use direct paths - Remove wasi-sdk symlink to avoid Bazel subpackage issues This ensures CI environments automatically download WASI SDK 25 instead of requiring pre-installed system packages.
1 parent 1a47da7 commit 550ae1b

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ register_toolchains("@wasm_tools_toolchains//:all")
5454
wasi_sdk = use_extension("//wasm:extensions.bzl", "wasi_sdk")
5555
wasi_sdk.register(
5656
name = "wasi",
57-
strategy = "system",
57+
strategy = "download",
5858
version = "25",
5959
)
6060
use_repo(wasi_sdk, "wasi_sdk")

MODULE.bazel.lock

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

toolchains/wasi_sdk_toolchain.bzl

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,37 @@ def _setup_downloaded_wasi_sdk(repository_ctx):
140140
# Download WASI SDK
141141
url = repository_ctx.attr.url
142142
if not url:
143-
# Example URL format - needs to be updated with actual WASI SDK URLs
143+
# WASI SDK URL format: wasi-sdk-{VERSION.0}-{ARCH}-{OS}.tar.gz
144+
# Convert platform format from "darwin_arm64" to "arm64-macos"
145+
platform_mapping = {
146+
"darwin_amd64": "x86_64-macos",
147+
"darwin_arm64": "arm64-macos",
148+
"linux_amd64": "x86_64-linux",
149+
"linux_arm64": "arm64-linux",
150+
"windows_amd64": "x86_64-mingw",
151+
}
152+
153+
if platform not in platform_mapping:
154+
fail("Unsupported platform: {}. Supported: {}".format(platform, platform_mapping.keys()))
155+
156+
platform_suffix = platform_mapping[platform]
157+
full_version = version + ".0" if "." not in version else version
158+
144159
url = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-{}/wasi-sdk-{}-{}.tar.gz".format(
145160
version,
146-
version,
147-
platform,
161+
full_version,
162+
platform_suffix,
148163
)
149164

165+
# The archive contains the full version and platform in the prefix
166+
strip_prefix = "wasi-sdk-{}-{}".format(full_version, platform_suffix)
167+
150168
repository_ctx.download_and_extract(
151169
url = url,
152-
stripPrefix = "wasi-sdk-{}".format(version),
170+
stripPrefix = strip_prefix,
153171
)
172+
173+
# No need for symlink, use direct paths in BUILD file
154174

155175
def _create_wasi_sdk_build_file(repository_ctx):
156176
"""Create BUILD file for WASI SDK"""
@@ -163,42 +183,42 @@ package(default_visibility = ["//visibility:public"])
163183
# File targets for WASI SDK tools
164184
filegroup(
165185
name = "clang",
166-
srcs = ["wasi-sdk/bin/clang"],
186+
srcs = ["bin/clang"],
167187
)
168188
169189
filegroup(
170190
name = "ar",
171-
srcs = ["wasi-sdk/bin/ar"],
191+
srcs = ["bin/ar"],
172192
)
173193
174194
filegroup(
175195
name = "wasm_ld",
176-
srcs = ["wasi-sdk/bin/wasm-ld"],
196+
srcs = ["bin/wasm-ld"],
177197
)
178198
179199
filegroup(
180200
name = "llvm_nm",
181-
srcs = ["wasi-sdk/bin/llvm-nm"],
201+
srcs = ["bin/llvm-nm"],
182202
)
183203
184204
filegroup(
185205
name = "llvm_objdump",
186-
srcs = ["wasi-sdk/bin/llvm-objdump"],
206+
srcs = ["bin/llvm-objdump"],
187207
)
188208
189209
filegroup(
190210
name = "llvm_strip",
191-
srcs = ["wasi-sdk/bin/llvm-strip"],
211+
srcs = ["bin/llvm-strip"],
192212
)
193213
194214
filegroup(
195215
name = "sysroot",
196-
srcs = glob(["wasi-sdk/share/wasi-sysroot/**"], allow_empty = True),
216+
srcs = glob(["share/wasi-sysroot/**"], allow_empty = True),
197217
)
198218
199219
filegroup(
200220
name = "clang_includes",
201-
srcs = glob(["wasi-sdk/lib/clang/*/include/**"], allow_empty = True),
221+
srcs = glob(["lib/clang/*/include/**"], allow_empty = True),
202222
)
203223
204224
# WASI SDK toolchain
@@ -211,7 +231,7 @@ wasi_sdk_toolchain(
211231
nm = ":llvm_nm",
212232
objdump = ":llvm_objdump",
213233
strip = ":llvm_strip",
214-
sysroot = "wasi-sdk/share/wasi-sysroot",
234+
sysroot = "share/wasi-sysroot",
215235
clang_version = "19",
216236
)
217237

0 commit comments

Comments
 (0)