Add build tags to leave out redis and lua - #615
Open
folbricht wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
noredisrediscache backendnolualuagroupsSizes with
-trimpath -ldflags="-s -w", as the release builds use: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:
RedisBackendOptionsused to embedredis.Options, which meantcmd/routednsimported the client and kept it linked no matter what the library did. Its connection settings are now plain fields that the backend translates, andNewRedisBackendreturns aCacheBackendand an error rather than the unexported*redisBackend. Both option structs live in untagged files so there is only one definition of each.TestBackendsAgeIdenticallymoved fromcache-age_test.gotocache-redis_test.go, since it goes through the Redis codec and cannot build without it. The rest ofcache-age_test.gois backend independent and stays where it is.Release artifacts
A
minimalgoreleaser build producesroutedns-minimal-linux-{armv6,armv7,arm64,mips,mipsle}. Existing artifact names and the deb/rpm/apk/archlinux packages are untouched. Verified withgoreleaser checkand a fullrelease --snapshot.CI builds and runs the test suite with both tags set, otherwise the stubs would drift out of sync unnoticed.