244 points · by cube2222 · 3y ago · 116 comments
https://words.filippo.io/easy-windows-and-linux-cross-compil...
I debated doing the pure-Go SQLite thing, but musl-cross worked just fine for me, and kept things simpler.
export GOARCH=arm64
export CC=zig cc -target aarch64-linux-musl
export CXX=zig cc -target aarch64-linux-musl CC="/path/to/cross/compiler" CGO_CFLAGS=—I/path/to/sdk/header/files/include" CGO_LDFLAGS="-L/path/to/sdk/obj/files/lib”
I suppose with .so files, you might have to specify "-Wl,-rpath" if the SDK libraries don’t reside under /usr/lib or /usr/local/lib on the target system. But I haven’t actually tried any of this yet, so I could be wrong. Are there any gotchas that I’m missing? GOOS= GOARCH= CGO_ENABLED=1 go build \
-tags osusergo,netgo,sqlite_omit_load_extension \
-ldflags="-extldflags=-static"
[0]: https://www.arp242.net/static-go.html1. https://github.com/ClickHouse/sysroot/
2. https://github.com/ClickHouse/ClickHouse/blob/master/cmake/f... and the `CMAKE_TOOLCHAIN_FILE` variable.
No one should touch servers directly, unless for down tracking stuff or remote development, in which case, they also don't need to cross compile.
No devs on production servers unless for tracking down issues, or servers configured for remote development.
Which in both cases, don't require cross compilation to start with.
Linux OEM vendors will appreciate it.
I look at it like a neat exercise but not really something to use in production. (I actually use it in tests though.)
Only the TCL and SQL Logic Test are publicly available; it's one of the ways that the SQLite developers get paid.
Pretty sure the lead dev said something along those lines when he did an episode of Corecursive?
it's got quirks but it's powerful and performs well
https://datastation.multiprocess.io/blog/2022-05-12-sqlite-i...
Linters and IDEs get slow when they check for errors, tests run slow, feedback drags, and all your workflows that took advantage of Go's fast compile times are now long enough that your flow and mental context disappear.
I'm way more lenient with other languages since the tooling and ecosystem are built around long build times. Your workflows compensate. But Go's tooling and ecosystem assume it compiles fast and treat things more like a scripting language. When that expectation is violated it hurts and everything feels like it's broken.
https://gitlab.com/cznic/libc/-/blob/v1.22.2/libc_openbsd_am...
Always seemed silly that one of the most popular storage technologies couldn't be accessed with pure Go.
I don't know why Google didn't pay someone to do this or do it themselves. Surely they use Go and sqlite together.
This is it. They have internal datastores that they use for nearly everything. They might be using SQLite somewhere for something, but I really doubt this would even land near the bottom of their priority list.
Your comment truly does SQLite a disservice. SQLite is probably one of the most impressive pieces of software to have ever graced this earth.
With this SQLite implementation I can stick it in my server (as a background, near real time mirror of memory state to disk) without worrying that the main loop will get clogged or my real time path will be hurt.
I use glabarez’ wrapper which makes it have an API like other Go databases: https://github.com/glebarez/sqlite/ and hey have been very responsive to issues I raised.
I have been running load tests against it for a few weeks, and it is quite solid.
That is why the go ecosystem tends to reimplement everything in go.
When I noticed the SHA3 extension was missing (https://gitlab.com/cznic/sqlite/-/issues/139) it was noted it could be very easily patched client-side which is handy, as well as adding functionality into the core library to handle it.
Performance wise I haven't done intensive benchmark tests yet, but from my local experiments last year it performed ~1.5-2x slower than the CGO version for some queries (it is especially noticeable with LIKE expressions on large string data), but as mentioned previously, for most use cases it is already good enough.
Here are the most recent benchmarks I could find (I think from one of the maintainers of the lib) comparing the CGO version and the pure Go port - https://docs.google.com/spreadsheets/d/1YOP1D_ZhuR-ednQhTH6S...
Using that for https://www.octobench.com/ and I'm very happy.
Every program needs to do syscalls at some point, so that’s built in. It is not “in fact worse”.
Rephrasing my question, why wouldn’t you just use the SQLite library from Go, instead of cross-compiling it from C to Go? It sounds like the non-enthusiast “reimplement everything in my favorite language” answer is that Go’s FFI is a pain, even for C.
I see a bunch of huge Go files with architecture names.
Edit: Look around the source for "ccgo". Like https://gitlab.com/cznic/sqlite/-/blob/master/doc.go#L202 and look for "ccgo" in the closed issues.