Skip to content

Add build tags to leave out redis and lua - #615

Open
folbricht wants to merge 1 commit into
masterfrom
build-tags
Open

Add build tags to leave out redis and lua#615
folbricht wants to merge 1 commit into
masterfrom
build-tags

Conversation

@folbricht

Copy link
Copy Markdown
Owner

Addresses #609.

The binary is almost entirely dependencies, and the two largest optional ones are the Redis client and the Lua interpreter. Two build tags leave them out:

Tag Leaves out
noredis The redis cache backend
nolua lua groups

Sizes with -trimpath -ldflags="-s -w", as the release builds use:

Target Current Both tags
linux/mipsle, softfloat 23.5MB 17.0MB
linux/armv6 20.6MB 14.9MB
linux/arm64 20.4MB 14.6MB
linux/amd64 22.2MB 15.9MB

Redis accounts for most of it. It contributes 2.75MB of text but takes 5.4MB off the binary because of its transitive tree. Lua is worth about 1MB.

One caveat on what this buys in practice: OpenWrt stores its root filesystem on squashfs and package payloads are compressed, so the number that matters there is the compressed size. For linux/mipsle that goes from 4.51MB to 3.74MB under xz, a 17% saving rather than the 28% the raw sizes suggest. Still useful on a 16MB device, but less dramatic.

Approach

Configuration is unchanged in both builds. The config layer parses every option either way, and the stubs replacing the two features return an error naming the missing one, so a config asking for a feature the binary lacks fails at startup instead of being silently ignored:

$ routedns-minimal config.toml
Error: this build does not support the redis cache backend

RedisBackendOptions used to embed redis.Options, which meant cmd/routedns imported the client and kept it linked no matter what the library did. Its connection settings are now plain fields that the backend translates, and NewRedisBackend returns a CacheBackend and an error rather than the unexported *redisBackend. Both option structs live in untagged files so there is only one definition of each.

TestBackendsAgeIdentically moved from cache-age_test.go to cache-redis_test.go, since it goes through the Redis codec and cannot build without it. The rest of cache-age_test.go is backend independent and stays where it is.

Release artifacts

A minimal goreleaser build produces routedns-minimal-linux-{armv6,armv7,arm64,mips,mipsle}. Existing artifact names and the deb/rpm/apk/archlinux packages are untouched. Verified with goreleaser check and a full release --snapshot.

CI builds and runs the test suite with both tags set, otherwise the stubs would drift out of sync unnoticed.

The binary is almost entirely dependencies, and the two largest optional
ones are the Redis client and the Lua interpreter. Neither is likely to
be used on a router with 16MB of flash, where the binary competes with
the rest of the system for space.

Two tags leave them out:

  noredis   the redis cache backend
  nolua     lua groups

A linux/mipsle build goes from 23.5MB to 17.0MB with both, linux/arm64
from 20.4MB to 14.6MB. Releases now carry routedns-minimal-linux-*
binaries built with both tags for arm, arm64, mips and mipsle.

Configuration is unchanged either way. The config layer still parses
every option, and the stubs that replace the two features return an
error naming the missing feature, so a config that asks for one fails
at startup rather than being silently ignored.

RedisBackendOptions no longer embeds redis.Options, which would have
kept the client linked into cmd/routedns regardless of the tag. Its
connection settings are now plain fields that the backend translates,
and NewRedisBackend returns a CacheBackend and an error instead of an
unexported type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant