Pulling a zig isn't going to solve all problems, as the zig cross compiler itself runs into problems fairly often. I already use CC='zig cc -target x86_64-linux-musl' (or whatever the target is) with cgo to cross-compile mattn/go-sqlite3, and relatively recently it simply stopped working[1] and a workaround had to do be added to about every single project of mine using SQLite through cgo.
I also once tried to figure out a way to cross compile mattn/go-sqlite3 to 32bit Windows with zig, and failed.
The best way to make cross compiling painless is to not use cgo at all. Which is why I use modernc/sqlite whenever possible now.
Btw, bundling a C compiler is also much harder when you don't build on top of LLVM.
I’m going to add a counter argument to all the cgo views raised:
Personally I’ve had much more portability problems with a lot of the native Go ports of sqlite than I have with mattn’s cgo library.
I author a shell that targets most of the architectures and platforms supported by Go. At the request of some users, I added support for a Go native library because they didn’t want to install a C compilers as well as a Go compiler. I tried a few different sqlite ports (though off hand cannot recall which ones) and they all had massive limitations, like only compiling on Windows and Linux (in one example).
In the end, I gave up and reverted back to the cgo version with the option for other libraries hidden behind a compiler flag.
I found my build pipeline manages just fine with cross compiling and haven’t had any complaints (thus far) with the binaries bar one individual running an ancient version of CentOS.
Maybe I’ve been trying the wrong sqlite ports. But here lies the problem: with cgo I know I’m getting a stable, tested, library. With other ports it’s entirely a lottery with regards to how well maintained and tested it might be. For personal projects that’s a fine risk to take but for any larger open source (or even commercial) projects, that additional uncertainty is a risk that distracts me and the other contributors from working on the core part of the project. And thus defeats the connivance of using 3rd party libraries.
I can cross compile SQLite into all platforms that Go OOB compiles too, with the caveat that any that aren't linux/windows/darwin/freebsd/illumos (CPU architecture doesn't matter) need a build flag because of file locking:
https://github.com/ncruces/go-sqlite3/blob/main/vfs/README.m...
Anything that helps me test portability, or any feedback you might have on it, would be greatly appreciated.
My SQLite bindings should build/work fine for all your supported platforms, with the caveat that BSDs other than FreeBSD need a build tag, because my locking protocol is not compatible with SQLite's default (if you access your database concurrently with my wrapper and other SQLite processes, you may corrupt data).
Solaris and Plan9 don't have working file locking, so you can't use concurrency at all. This could be change if there was interest in it.
Here lies the problem. I now need to instruct users that different build flags are required for different platforms. Whereas that problem doesn’t exist with the cgo bindings.
Plus I also have the additional risk that I’m using someone’s hobby project that, and I say this with the greatest of respect for yourself, might get abandoned tomorrow for all I know.
Cgo might have its issues but for sqlite3 it offers far better assurances than anything else available for Go at this point in time.
Given that sqlite3 is a supporting library rather than the differentiator of my project, I want to spend as little time as I have to supporting it. At this point in time, only the cgo library seems to offer that convenience (though if anyone else wants to maintain a fork of my project using a different sqlite library then I’m more than happy with that).
Good luck with your project though. Hopefully the Go community can rally around one of these native solutions so it gains enough traction to become the new de facto standard.
I could easily build on all platforms without tags… I just want to avoid accidental data corruption if users unwittingly access databases without proper synchronization.
The MVCC-WAL-VFS I'm designing now may potentially fix this, as the brokenness of POSIX advisory locks is more manageable there.
I'll definitely keep an eye on this project. And likewise, if you feel you reach a new stable milestone that addresses my concerns, do feel free to raise an issue on my projects Github page for me to switch away from cgo :)
I also once tried to figure out a way to cross compile mattn/go-sqlite3 to 32bit Windows with zig, and failed.
The best way to make cross compiling painless is to not use cgo at all. Which is why I use modernc/sqlite whenever possible now.
Btw, bundling a C compiler is also much harder when you don't build on top of LLVM.
[1] https://github.com/mattn/go-sqlite3/issues/1164