Open diamondburned opened 2 years ago
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:
# github.com/diamondburned/gotk4/pkg/atk
pkg/atk/atkcomponent.go:142:7: could not determine kind of name for C.AtkRectangle
// 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 var b [n]byte
and use unsafe.Add(&b[0])
. Go will allocate b
on the Go heap for us.
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?
@mgord9518
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?)
@mgord9518
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 https://github.com/ebitengine/purego/issues/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. glib
and gobject-introspection
), and then link to everything else during runtime.
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 4-libgirepository
branch at this point? And if so, does it require any special build flags? (I tried just replacing the regular version with that branch but build times were about the same.)
I don't think the runtime linking mode was ever completed or even reached a runnable state. I believe all changes from 4-libgirepository
should've already been merged into 4
guarded behind an environment variable.
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 manner