Experience with building JS and Python bindings for a Go library

151 views
Skip to first unread message

Taco de Wolff

unread,
May 22, 2023, 8:35:13 PM5/22/23
to golang-nuts
I would like to know if anyone has experience with building bindings for JavaScript (NodeJS) and Python for a Go library. Who has worked on this, or does anybody know of libraries that have succeeded? In particular, I have successfully built working JS and Python bindings (see https://github.com/tdewolff/minify/tree/master/bindings), but I have two problems:

- How does the Go standard library (CGO) work in conjunction with forked/worker threads of JS/Python? See https://github.com/tdewolff/minify/issues/518#issuecomment-1256812343
- How can I prebuild binaries for Windows for a JS binding? In particular, node-gyp allows you to build addons which is working fine for Linux/MacOS, however they only permit using MSVC on WIndows and Go/CGO only can use GCC. I'm suspecting this is behind an error we have (Error: Module did not self-register)

I would love to hear about example or people with experience! Thanks in advance!

burak serdar

unread,
May 22, 2023, 8:41:13 PM5/22/23
to Taco de Wolff, golang-nuts
On Mon, May 22, 2023 at 6:35 PM Taco de Wolff <tacod...@gmail.com> wrote:
I would like to know if anyone has experience with building bindings for JavaScript (NodeJS) and Python for a Go library. Who has worked on this, or does anybody know of libraries that have succeeded?

I used the following two libraries for running JS from Go: 

There is a V8 binding using Cgo: https://github.com/rogchap/v8go
And there is a pure Go JS interpreter: https://github.com/robertkrimen/otto
 
In particular, I have successfully built working JS and Python bindings (see https://github.com/tdewolff/minify/tree/master/bindings), but I have two problems:

- How does the Go standard library (CGO) work in conjunction with forked/worker threads of JS/Python? See https://github.com/tdewolff/minify/issues/518#issuecomment-1256812343
- How can I prebuild binaries for Windows for a JS binding? In particular, node-gyp allows you to build addons which is working fine for Linux/MacOS, however they only permit using MSVC on WIndows and Go/CGO only can use GCC. I'm suspecting this is behind an error we have (Error: Module did not self-register)

I would love to hear about example or people with experience! Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7c18fb1e-1737-447c-9a86-04d52cf0b2f9n%40googlegroups.com.

Sebastien Binet

unread,
May 23, 2023, 1:56:34 AM5/23/23
to Taco de Wolff, golang-nuts
For CPython, there's github.com/go-python/gopy that tries to automatically wrap a Go package into a CPython module.

There's also go-python/gpython, a pure-Go Python3 interpreter (without all the batteries, though).

For JS, I guess there's GopherJS.

hth,
-s

May 23, 2023 02:35:15 Taco de Wolff <tacod...@gmail.com>:

--

Justin Israel

unread,
May 23, 2023, 10:44:18 PM5/23/23
to golang-nuts
For automatic python bindings I have used github.com/go-python/gopy
https://github.com/justinfx/pygo-plugin/blob/main/go_plugin/client.go

And for pure cpython bindings I have used:
Reply all
Reply to author
Forward
0 new messages