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

Wasm-based codepath to run without cgo #103

Open
anuraaga opened this issue Dec 1, 2023 · 3 comments
Open

Wasm-based codepath to run without cgo #103

anuraaga opened this issue Dec 1, 2023 · 3 comments

Comments

@anuraaga
Copy link
Contributor

anuraaga commented Dec 1, 2023

I have developed a version of pgquery for Go that uses WebAssembly and wazero

https://github.com/wasilibs/go-pgquery

This means that it enable the library to be used without cgo, notably meaning no warnings when building after a MacOS upgrade and full windows support. I have been able to use it to remove platform constraints from sqlc

sqlc-dev/sqlc#3027

I wanted to check if there is any interest in upstreaming that technique into this repository, in which case I would be happy to archive that project. WebAssembly is quite gnarly, so I don't know if I particularly recommend it and run into possible maintenance issues, though I'd be happy to help when needed. More practical may be to keep that separate and make sure the types are compatible to allow easy switching. I have verified that with #102 I can switch go-pgquery to return the proto from this package in its public API without issue.

I wanted to share the idea and provide context on recent changes and happy to hear any thoughts on what could work well for this project.

Thank you.

@lfittl
Copy link
Member

lfittl commented Dec 2, 2023

I have developed a version of pgquery for Go that uses WebAssembly and wazero

https://github.com/wasilibs/go-pgquery

This means that it enable the library to be used without cgo, notably meaning no warnings when building after a MacOS upgrade and full windows support. I have been able to use it to remove platform constraints from sqlc

sqlc-dev/sqlc#3027

I wanted to check if there is any interest in upstreaming that technique into this repository, in which case I would be happy to archive that project. WebAssembly is quite gnarly, so I don't know if I particularly recommend it and run into possible maintenance issues, though I'd be happy to help when needed.

Thanks for sharing!

I think its potentially interesting to offer this upstream as part of libpg_query, but we'd need to understand better what the right runtime would be across different languages (ideally this could also be used to solve e.g. Node.js porting issues, as described in pganalyze/libpg_query#44).

However we are also revisiting whether we can support Windows directly in libpg_query, which then may not make the effort of maintaining a wasm port worthwhile.

All that said, I'd suggest we keep this separate in the short term (and hopefully with #102 merged it should work better I assume), and medium term (i.e. some time next year) revisit and see which direction makes sense.

mostafa added a commit to gatewayd-io/gatewayd-plugin-sdk that referenced this issue Dec 3, 2023
…platforms

This is a workaround using WebAssembly introduced in pganalyze/pg_query_go#103
@anuraaga
Copy link
Contributor Author

anuraaga commented Dec 4, 2023

Thanks @lfittl - yeah, the runtime aspect is definitely tricky, I found postgres requires threads and exceptions to compile, neither of which supported by officially released Wasm yet so runtime support is poor.

Agree that revisiting later after getting more clarity on those other options sounds great. The options to look at then would probably be

  1. Maintain a wasm that can be shared among languages
  2. Only use wasm for pg_query_go
  3. Don't use wasm

The reason I separate out 2) is that my impression is that out of all languages, Go tends to have the most issues and least appetite toward C bindings so it could be worth supporting CGO_ENABLED=0 apps which are common. Just something to keep in mind, looking at the PR links to this issue, my library got used outside of sqlc much sooner than I was expecting 😂

@karlhorky
Copy link

cc @gregnr, since you have been working on a WebAssembly version of node-libpg-query over here:

Wonder if the WebAssembly efforts can be combined to have Windows support before full libpg_query native Windows support happens...

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

No branches or pull requests

3 participants