tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Shared object / DLL support

Open seadra opened this issue 5 years ago • 9 comments

gc compiler has -buildmode=c-shared. With LLVM, this should be possible, no?

seadra avatar Apr 02 '19 14:04 seadra

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

aykevl avatar Apr 02 '19 17:04 aykevl

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 :)

JasonWeise avatar May 28 '19 05:05 JasonWeise

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...

sowelipililimute avatar Jan 13 '21 08:01 sowelipililimute

It's likely some more plumbing needs to be done but that's the essence of it I think.

aykevl avatar Jan 13 '21 17:01 aykevl

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.

ansiwen avatar Feb 11 '22 09:02 ansiwen

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?

riaan-dau avatar Sep 25 '22 07:09 riaan-dau

It's almost 2023, how is going to support generate .dll or .lib

Jimmy2099 avatar Dec 31 '22 05:12 Jimmy2099

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.

wayneforrest avatar Oct 11 '23 02:10 wayneforrest

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

31 avatar Jan 01 '24 23:01 31