Vendor LZ4 as a git submodule and link statically#3
Conversation
Add the LZ4 C library as a git submodule (vendor/lz4, pinned to v1.10.0) and link against the statically compiled liblz4.a instead of a system-installed shared library. This removes the runtime dependency on liblz4 and makes builds reproducible. - Add vendor/lz4 submodule pinned to v1.10.0 - Link statically via @[Link(ldflags: ".../vendor/lz4/lib/liblz4.a")] - Bump VERSION_* constants to 1.10.0 to match the vendored library - Add postinstall script to init the submodule and build liblz4.a - Add Makefile for local builds - Document the vendored/static approach in the README Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tradeoff note: downsides of vendoring + static linking vs. the system shared libraryFor the record, the downsides we're accepting with this change (roughly in order of how much they matter for this shard): 1. We own security updates now. With the system 2. Build now needs a C toolchain + the submodule present. Previously a consumer just needed
3. No shared-library deduplication. Each binary embeds its own copy of LZ4, and multiple processes can't share one mapped 4. Risk of a double copy of LZ4. If the consuming application links LZ4 through some other path too, the final binary can end up with two copies / duplicate symbols. Unlikely, but vendoring makes it possible. 5. We forgo distro hardening. Packaged Overall: the calculus is mostly favorable for this shard — LZ4 is small and stable, and static linking buys reproducible builds and zero runtime dependency. The one to keep an eye on is #1. If we'd rather not own that, supporting both (system link by default, vendored static as an opt-in build flag) is a middle ground, but it adds complexity that probably isn't worth it unless someone needs it. |
Summary
Vendor the LZ4 C library as a git submodule and link against a statically compiled
liblz4.ainstead of a system-installed shared library. This removes the runtime dependency onliblz4and makes builds reproducible across machines and CI.Changes
vendor/lz4— added as a git submodule, pinned to the v1.10.0 release tag.src/lz4/lib.cr— replaced@[Link("lz4")](dynamic system link) with@[Link(ldflags: "#{__DIR__}/../../vendor/lz4/lib/liblz4.a")]for static linking; bumpedVERSION_*constants to 1.10.0 to match the vendored source.shard.yml— added apostinstallscript that checks out the submodule and builds the static archive (git submodule update --init --recursive && make -C vendor/lz4/lib liblz4.a) when installed as a dependency.Makefile— root-level targets for local builds (make,make spec,make clean).README.md— documents the vendored/static approach and the build step.Verification
crystal spec→ 11 examples, 0 failures.LZ4_versionString=1.10.0(the vendored copy) andlddshows noliblz4.sodependency — confirming static linkage with no runtime shared-library requirement.🤖 Generated with Claude Code