Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ register_toolchains(

# wasm/wasi toolchains
"@zig_sdk//toolchain:wasip1_wasm",
"@zig_sdk//toolchain:none_wasm",

# zig toolchains
"@zig_sdk//toolchain:zig",
Expand Down
1 change: 1 addition & 0 deletions toolchain/platform/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def declare_platforms():

# We can support GOARCH=wasm32 after https://github.com/golang/go/issues/63131
declare_platform("wasm", "wasm32", "wasi", "wasip1")
declare_platform("wasm", "wasm32", "none", "none")

def declare_libc_aware_platforms():
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
Expand Down
32 changes: 32 additions & 0 deletions toolchain/private/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def target_structs():
for glibc in _GLIBCS:
ret.append(_target_linux_gnu(gocpu, zigcpu, glibc))
ret.append(_target_wasm())
ret.append(_target_wasm_no_wasi())
return ret

def _target_macos(gocpu, zigcpu):
Expand Down Expand Up @@ -235,6 +236,37 @@ def _target_wasm():
],
)

def _target_wasm_no_wasi():
return struct(
gotarget = "none_wasm",
zigtarget = "wasm32-freestanding-musl",
includes = [] + _INCLUDE_TAIL,
linkopts = [],
dynamic_library_linkopts = [],
supports_dynamic_linker = False,
copts = [],
libc = "musl",
bazel_target_cpu = "wasm32",
constraint_values = [
"@platforms//os:none",
"@platforms//cpu:wasm32",
],
ld_zig_subcmd = "wasm-ld",
# .wasm extension supported in bazel >= 6.4.0
artifact_name_patterns = [
{
"category_name": "dynamic_library",
"prefix": "",
"extension": ".wasm",
},
{
"category_name": "executable",
"prefix": "",
"extension": ".wasm",
},
],
)

def transform_os_name(os):
if os.startswith("mac os"):
return "macos"
Expand Down
2 changes: 1 addition & 1 deletion toolchain/zig-wrapper.zig
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn getRunMode(self_exe: []const u8, self_base_noexe: []const u8) error{BadParent
return error.BadParent;

const got_os = it.next() orelse return error.BadParent;
if (mem.indexOf(u8, "linux,macos,windows,wasi", got_os) == null)
if (mem.indexOf(u8, "linux,macos,windows,wasi,freestanding", got_os) == null)
return error.BadParent;

// ABI triple is too much of a moving target
Expand Down