Skip to content

Commit 6505cf2

Browse files
authoredDec 24, 2024··
Support Go 1.24's wasip1 reactors (#4201)
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** [Go 1.24](https://go.dev/doc/go1.24#wasm) added support for `GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared`; however, the rules_go starlark code contained validation against this. * Fixes validation error in newly supported go 1.24 wasip1-wasm tuple with -buildmode=c-shared. * Removes lib prefix for wasip1 -buildmode=c-shared * Adds `.wasm` suffix for wasi reactors built with `-buildmode=c-shared` **Which issues(s) does this PR fix?** Fixes #4200 **Other notes for review** It looks like this could use a test (as simple as adding a new go file under `tests/core/c_linkmodes/`); however, the support for features added in this PR requires Go 1.24, which is not out yet. Updating `go_register_toolchains(version = "1.24rc1")` does allow it to build, but then `nogo` fails due to lack of support in some of the linters for go 1.24. Signed-off-by: Matt Leon <[email protected]>
1 parent 6f7c705 commit 6505cf2

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed
 

‎go/private/actions/binary.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def emit_binary(
4343
archive = go.archive(go, source)
4444
if not executable:
4545
if go.mode.linkmode == LINKMODE_C_SHARED:
46-
name = "lib" + name # shared libraries need a "lib" prefix in their name
46+
if go.mode.goos != "wasip1":
47+
name = "lib" + name # shared libraries need a "lib" prefix in their name
4748
extension = goos_to_shared_extension(go.mode.goos)
4849
elif go.mode.linkmode == LINKMODE_C_ARCHIVE:
4950
extension = ARCHIVE_EXTENSION

‎go/private/common.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ def goos_to_extension(goos):
101101

102102
ARCHIVE_EXTENSION = ".a"
103103

104-
SHARED_LIB_EXTENSIONS = [".dll", ".dylib", ".so"]
104+
SHARED_LIB_EXTENSIONS = [".dll", ".dylib", ".so", ".wasm"]
105105

106106
def goos_to_shared_extension(goos):
107107
return {
108108
"windows": ".dll",
109109
"darwin": ".dylib",
110+
"wasip1": ".wasm",
110111
}.get(goos, ".so")
111112

112113
def has_shared_lib_extension(path):

‎go/private/mode.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def validate_mode(mode):
6565
fail("race instrumentation can't be enabled when cgo is disabled. Check that pure is not set to \"off\" and a C/C++ toolchain is configured.")
6666
if mode.msan:
6767
fail("msan instrumentation can't be enabled when cgo is disabled. Check that pure is not set to \"off\" and a C/C++ toolchain is configured.")
68-
if mode.linkmode in LINKMODES_REQUIRING_EXTERNAL_LINKING:
68+
if mode.linkmode in LINKMODES_REQUIRING_EXTERNAL_LINKING and mode.goos != "wasip1":
6969
fail(("linkmode '{}' can't be used when cgo is disabled. Check that pure is not set to \"off\" and that a C/C++ toolchain is configured for " +
7070
"your current platform. If you defined a custom platform, make sure that it has the @io_bazel_rules_go//go/toolchain:cgo_on constraint value.").format(mode.linkmode))
7171

0 commit comments

Comments
 (0)
Please sign in to comment.