tinygo
tinygo copied to clipboard
Shared object / DLL support
gc compiler has -buildmode=c-shared. With LLVM, this should be possible, no?
Yes, this is certainly possible. It's just that no one has asked for it yet.
It will need the extra -buildmode
flag and some extra hooks, like an extra -static
flag to the linker and an extra hook to let the compiler emit PIC code instead of static code:
https://github.com/tinygo-org/tinygo/blob/5569cd1b6b3aff8f52052d5ff1028d9bb87fba24/compiler/compiler.go#L105
This would be a great addition. I am calling a Go library from Rust and would love to see it compiled with TinyGo instead.
Looking forward to this implementation :)
Yes, this is certainly possible. It's just that no one has asked for it yet. It will need the extra
-buildmode
flag and some extra hooks, like an extra-static
flag to the linker and an extra hook to let the compiler emit PIC code instead of static code:https://github.com/tinygo-org/tinygo/blob/5569cd1b6b3aff8f52052d5ff1028d9bb87fba24/compiler/compiler.go#L105
Is adding this really all that needs to be done? Seems like there would be more to do...
It's likely some more plumbing needs to be done but that's the essence of it I think.
I'm using go with c-shared for building a small plugin .so, that basically only calls a rest API. So it mainly uses the http client and json parser. Because of the runtime, it's quite big. I think it would be very useful to compile this with tinygo instead.
We have an existing C-codebase running bare-metal on 32-bit ARM and would like to make use of the -buildmode=c-archive
flag to build a static Go library callable from C. Would this be possible if this feature is implemented?
It's almost 2023, how is going to support generate .dll or .lib
I am also interested in this feature.
I am using a go .dll / .lib, called from C++; and the DLL is 13MB
, while the C++ code is only 1.5MB.
The Go c-shared
support doesn't allow dlclose
(or FreeLibrary
on Windows), which makes it not ideal for plugins that need to be reloaded. I don't see any reason it'd be easier to support this with TinyGo than Go, but maybe this scenario has more value here? Go issue about this:
- https://github.com/golang/go/issues/11100