Skip to content

Commit a33f852

Browse files
committed
bazel/sqlite3: link mattn/go-sqlite3 against the shared libsqlite3
Stop compiling the bundled SQLite amalgamation that ships with github.com/mattn/go-sqlite3 and link the binding against //deps:sqlite3 instead. Removes one full SQLite C compile from every build, keeps a single .so in the runtime artifacts (already shared by cpython, rpm, openscap). - .bazelrc: enable the libsqlite3 Go build tag globally so sqlite3_libsqlite3.go compiles and defines USE_LIBSQLITE3, which makes the bundled sqlite3-binding.c a no-op TU and switches the cgo preamble to #include <sqlite3.h>. - deps/go.MODULE.bazel: add a gazelle_override on github.com/mattn/go-sqlite3 that (a) passes -build_tags=libsqlite3 so Gazelle picks the right sources in srcs, and (b) maps go_library to the go_sqlite3_library wrapper added in the previous commit, which injects cgo = True and the libsqlite3_dynamic cdep so #include <sqlite3.h> and -lsqlite3 resolve against //deps:sqlite3. Verified by building //pkg/security/resolvers/sbom/collectorv2:collectorv2_test and confirming via ldd that the binary dynamically links against the @sqlite3//:sqlite3 shared library (single agent-owned libsqlite3.so) and go-sqlite3's GoCompilePkg runs in ~0s (no amalgamation recompile).
1 parent 953ab4a commit a33f852

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ common:adms --config=dd-internal
1313
startup --max_idle_secs=28800 # Keep the server alive for at most 8 hours of inactivity
1414

1515
# Common options -------------------------------------------------------------------------------------------------------
16+
common --@rules_go//go/config:tags=libsqlite3 # Link mattn/go-sqlite3 against //deps:sqlite3 instead of compiling its bundled amalgamation
1617
common --@rules_python//python/config_settings:bootstrap_impl=script # https://github.com/bazel-contrib/rules_python/blob/main/BZLMOD_SUPPORT.md
1718
common --check_direct_dependencies=error # Escalate any bypassed `bazel_dep` to a resolution failure
1819
common --enable_platform_specific_config # Supported OS identifiers are linux, macos, windows, freebsd, and openbsd

deps/go.MODULE.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ go_deps.gazelle_override(
5353
build_extra_args = ["-build_tags=requirefips"],
5454
path = "go.opentelemetry.io/collector/config/configtls",
5555
)
56+
57+
# Link go-sqlite3 against the shared libsqlite3 from //deps:sqlite3 rather than
58+
# compiling the bundled amalgamation. The libsqlite3 build tag is enabled
59+
# globally in .bazelrc. The map_kind directive redirects Gazelle to emit our
60+
# go_sqlite3_library wrapper, which sets cgo = True and injects the
61+
# @sqlite3//:libsqlite3_dynamic cdep so the binding's #include <sqlite3.h> and
62+
# -lsqlite3 directives resolve.
63+
go_deps.gazelle_override(
64+
build_extra_args = ["-build_tags=libsqlite3"],
65+
directives = [
66+
"gazelle:map_kind go_library go_sqlite3_library @@//bazel/rules/go_sqlite3:go_sqlite3_library.bzl",
67+
],
68+
path = "github.com/mattn/go-sqlite3",
69+
)
5670
use_repo(
5771
go_deps,
5872
"cat_dario_mergo",

0 commit comments

Comments
 (0)