Skip to content

go:wasmexport: unsupported parameter type #185

Open

Description

@elewis787

Work is being done in Go 1.24 to support go:wasmexport.

However, there are a handful of unsupported parameter types. The following test shows the supported and unsupported types https://go-review.googlesource.com/c/go/+/611315

*string, and *uint8 are examples I have run into with the current wit-bindgen-go bindings.

Is it a possible solution to use unsafe.Pointer and convert the parameters to their necessary types?

I.e

Breaking

//go:wasmexport count
//export count
func wasmexport_Count(s0 *uint8, s1 uint32, sub0 *uint8, sub1 uint32) (result0 uint32) {
	s := cm.LiftString[string]((*uint8)(s0), (uint32)(s1))
	sub := cm.LiftString[string]((*uint8)(sub0), (uint32)(sub1))
	result := Exports.Count(s, sub)
	result0 = (uint32)(result)
	return
}

Possible workaround

//go:wasmexport count
//export count
func wasmexport_Count(s0 unsafe.Pointer, s1 uint32, sub0 unsafe.Pointer, sub1 uint32) (result0 uint32) {
	s := cm.LiftString[string]((*uint8)(s0), (uint32)(s1))
	sub := cm.LiftString[string]((*uint8)(sub0), (uint32)(sub1))
	result := Exports.Count(s, sub)
	result0 = (uint32)(result)
	return
}

I am still working through a test to ensure this functionality works. I am currently working through the reactor host setup to call the exported function.

Activity

  1. ydnar commented on Oct 1, 2024

    @ydnar
    Collaborator

    golang/go#66984 fixes this

  2. elewis787 commented on Oct 1, 2024

    @elewis787
    Author

    golang/go#66984 fixes this

    Thanks, I have not seen this yet. I will read through it and follow up. Regardless, would you prefer I close this issue or leave it open until we can confirm the behavior outlined has been implemented/validated?

  3. ydnar commented on Oct 2, 2024

    @ydnar
    Collaborator

    Sure, let's leave this open to track.

  4. prep commented on Oct 27, 2024

    @prep

    According to the proposal:

    Strings are not allowed as result parameters as Wasm practically does not allow more than 1 result parameter.

    But when I generate from this:

    world test {
        export upper: func(input: string) -> string;
    }
    

    It generates this:

    //go:wasmexport upper
    //export upper
    func wasmexport_Upper(input0 *uint8, input1 uint32) (result *string) {

    Would it be fair to say this would be in error, even after the proposal is integrated?

  5. ydnar commented on Oct 27, 2024

    @ydnar
    Collaborator

    A pointer to a string is a single i32, so it is valid as a return value.

  6. ydnar commented on Dec 8, 2024

    @ydnar
    Collaborator

    Is this issue still valid?

  7. therayquaza commented on May 13, 2026

    @therayquaza

    I am having similar issues with go 1.26, any updates on this ?
    My current workaround is the same as the one mentioned above (passing all unsupported types to unsafe pointers) but this is really messy ...

  8. elee1766 commented on Jul 10, 2026

    @elee1766

    i think this issue is still valid yes. #66984 was closed but it only works for the wasm32 case.

    would be there any interest in a pr for the unsafe pointer workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions