A recent post on the front page of HN made a comparison between different SQLite packages for Go. Some bundled the official C implementation, while ot

Building SQLite with CGo for (almost) every OS

submited by
Style Pass
2022-05-13 18:00:17

A recent post on the front page of HN made a comparison between different SQLite packages for Go. Some bundled the official C implementation, while others offered a pure Go implementation.

The C implementation was twice as fast as the Go one, but it saves you from having to deal with CGo. Is the tradeoff worth it? I would say no.

Firstly, SQLite is famous for being tested extremely thoroughly and, while the Go version is the result of machine translation of the original code, I would trust the original code over any reimplementation.

In this post I'm going to show all the good and bad of compiling for different OSs mattn/go-sqlite3, the package that relies on CGo to compile the original SQLite source file.

Each build will consist of the test suite that the package comes with. Normally you would just run go test, but in my case I'll add -c to make Go produce the test executable without running it, allowing me to move the executable on the correct machine.

Of course I will be using zig cc as the C compiler. If you want to follow along, get yourself a copy of Zig (v0.9 or above), a copy of Go (v1.8 or above) and clone the repo in question.

Leave a Comment