I'm writing this with the assumption that each CGO-generated wrapper for each C function is stored in its own C file.
Editing and compiling a CGO package can take a minute or 2, even for one little change.
It should be possible to cache the generated .o files and only recompile them if the code for that function changes.
When linking the CGO wrappers, Go should avoid linking unused wrappers to reduce size.
The text was updated successfully, but these errors were encountered:
Maybe we could only run the C compiler when the package is actually being compiled in order to get the values of C constants and make sure C functions are called properly.
Then, at link time, the Go linker linkes the entire program instead of using the C linker. We could probably use syscall to call C functions at runtime from CGO Go code wrappers.
This would have several benefits. Faster linking speed since no C linker is being invoked, the Go linker probably wouldn't need to spend time building a C linker compatible object file, dead code elimination could probably be done even for statically linked C code (at least on a per object file basis), and cross compiling might be supported if you have static libraries for other platforms. The Go package "github.com/veandco/go-sdl2/sdl" provides static libraries for all the platforms SDL2 runs on.
The linker would need support for reading a few different formats of object files though.
We run the C linker, rather than using only the Go linker, because the Go linker doesn't support C++ global constructors or C++ exception handling or a few other cases that the C linker handles. We could support those things in the Go linker, but it's not trivial.