Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Go SDK to use wit-bindgen 0.9 #1630

Closed
wants to merge 4 commits into from
Closed

Move Go SDK to use wit-bindgen 0.9 #1630

wants to merge 4 commits into from

Conversation

rylev
Copy link
Collaborator

@rylev rylev commented Jul 4, 2023

Resolves spinframework/spin-go-sdk#2 This is a not quite working move of the internals of the Go SDK to use wit-bindgen 0.8

Overall the move greatly simplifies things as we can stop using the C generator and move to direct tinygo support.

@Mossaka Here are a few bugs and usability issues I've found:

sdk/go/generated/reactor.c:1404:22: error: assigning to 'fermyon_spin_redis_error_t' (aka 'unsigned char') from incompatible type 'fermyon_spin_key_value_error_t'
      result.val.err = variant;
                     ^ ~~~~~~~
  • The Result and Option types are not the most helpful. Our SDK usually has return types of value, error and having to translate the Result and Option types to the (arguably more idiomatic) version is tedious. What speaks against the generated code following the value, error pattern more closely?
  • Error types can't easily be turned into strings. Would it be possible to have some behavior like the Rust code generator which generates Display impls for error types?

I don't have time today to investigate the errors today, but I'll try to do so tomorrow. Let me know if you'd like to take a look together!

Signed-off-by: Ryan Levick <me@ryanlevick.com>
@rylev rylev requested review from dicej and adamreese July 4, 2023 14:40
@Mossaka
Copy link
Contributor

Mossaka commented Jul 4, 2023

Thank you @rylev for using the the go-bindgen in Spin's Go SDK! These findings are great and insightful. It seems to me that the first two points are bugs, and the last two points are feature requests. I will raise each of them as an issue on the wit-bindgen repo and start working on fixing the bugs and improving the Result and Option type and the Error to String experience.

@adamreese
Copy link
Contributor

Thanks for getting this work going. I too have found the Result and Option difficult to work with.

@rylev rylev marked this pull request as draft July 4, 2023 17:03
@rylev
Copy link
Collaborator Author

rylev commented Jul 11, 2023

@Mossaka FYI: the other bug I'm seeing has been reproduced and logged as an issue here: bytecodealliance/wit-bindgen#607

rylev added 3 commits July 17, 2023 18:02
Signed-off-by: Ryan Levick <me@ryanlevick.com>
Signed-off-by: Ryan Levick <me@ryanlevick.com>
Signed-off-by: Ryan Levick <me@ryanlevick.com>
@rylev rylev changed the title Move Go SDK to use wit-bindgen 0.8 Move Go SDK to use wit-bindgen 0.9 Jul 17, 2023
@rylev
Copy link
Collaborator Author

rylev commented Jul 18, 2023

This is blocked on one final issue: bytecodealliance/wit-bindgen#617. Once that issue is solved, this should be fine to merge.

@Mossaka
Copy link
Contributor

Mossaka commented Jul 18, 2023

Thank you, @rylev !!

@Mossaka
Copy link
Contributor

Mossaka commented Sep 14, 2023

This is blocked on one final issue: bytecodealliance/wit-bindgen#617.

Hey @rylev, could you please elaborate more about how this particular issue is blocking this PR?

@rylev
Copy link
Collaborator Author

rylev commented Sep 14, 2023

Concretely, bytecodealliance/wit-bindgen#617 is about adding wit information including the metadata (e.g., the module "producer") to the component model so that tooling knows what the wit would the component targets. In spin-componentize (which is used to turn the plain core WebAssembly module the user builds into a WebAssembly component), we use the information encoded in this custom section to determine how to process the module.

If the module is produced with newer tooling, we know that we can just use the normal wit-component::ComponentEncoder to turn the module into a component. However, if older tooling was used we have to perform a bit of surgery to get the module into the right shape.

One thing I want to try now is to see can we just try to use the wit-component::ComponentEncoder to encode all modules and if it fails fallback to the hacks? I'm unsure if this will work, but it might?

@rylev
Copy link
Collaborator Author

rylev commented Oct 10, 2023

Going to close this for now. We still want to resolve spinframework/spin-go-sdk#2, but things have evolved sufficiently from the wit-bindgen 0.9 days that this PR is not going to get merged without starting over.

@rylev rylev closed this Oct 10, 2023
@rylev rylev deleted the go-wit-bindgen-08 branch October 10, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use go.bytecodealliance.org/cmd/wit-bindgen-go to generate go bindings given WIT interfaces
3 participants