-
Notifications
You must be signed in to change notification settings - Fork 20
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
Proposal: Runtime dynamic linking #74
Comments
Further Thoughts
|
WIP branch at https://github.com/diamondburned/gotk4-libgirepository. I'm unsure if gio should be runtime-linked or compile-time-linked. It takes ~1 minute to build it with cmd/cgo. |
Error log:
// NewRectangle creates a new Rectangle instance from the given
// fields. Beware that this function allocates on the Go heap; be careful
// when using it!
func NewRectangle(x, y, width, height int) Rectangle {
var f0 C.gint // out
f0 = C.gint(x)
var f1 C.gint // out
f1 = C.gint(y)
var f2 C.gint // out
f2 = C.gint(width)
var f3 C.gint // out
f3 = C.gint(height)
v := C.AtkRectangle{
x: f0,
y: f1,
width: f2,
height: f3,
}
return *(*Rectangle)(gextras.NewStructNative(unsafe.Pointer(&v)))
} Fix is to do Alternative solutionFix is to have Go generate a Go struct like so: type rectangleNative struct {
x C.gint
y C.gint
width C.gint
height C.gint
} Then we can generate Cons:
|
Sorry for the noise, but maybe https://github.com/ebitengine/purego could in theory be used for dynamic linking? They have some dlfcn stuff, hopefully that helps |
Would this make it possible to have fully static binaries? |
I don't think so. The binaries wouldn't need to link to libgtk and friends anymore, but they'd still need to link to libdl. (Perhaps that's avoidable with https://github.com/ebitengine/purego though?) |
With purego it's also complicated ebitengine/purego#132 |
This proposal doesn't aim to produce fully static binaries, FWIW. My goal was to link to some very basic core libraries (i.e. This proposal has less to do with producing a pure Go binary or a static binary and a lot more to do with optimizing for build times. Implementing this proposal would allow some of the much larger packages (e.g. GTK4) to be in pure Go (linking to already-compiled Cgo packages), speeding up compile times significantly. |
Sorry for the noob question but is there anything to try out in the |
I don't think the runtime linking mode was ever completed or even reached a runnable state. I believe all changes from |
Reasoning
Approaches
GModule
dlfcn.h
/syscall
, packagepkg/core/dlsym
maybe?Implementation
libgirepository
https://gi.readthedocs.io/en/latest/writingbindings/libgirepository.html
GModule
dlfcn
Considerations
func_NAME uintptr
atomic.CompareAndSwapUintptr
to properly do this in a thread-safe mannerThe text was updated successfully, but these errors were encountered: