listmonk icon indicating copy to clipboard operation
listmonk copied to clipboard

Respect SOURCE_DATE_EPOCH when building

Open toabctl opened this issue 1 month ago • 1 comments

To make the build reproducable (see [0]), respect the SOURCE_DATE_EPOCH variable and don't include a build timestammp in the binary when set.

[0] https://reproducible-builds.org/

toabctl avatar Dec 05 '25 07:12 toabctl

tested with:

❯ make dist     
CGO_ENABLED=0 go build -o listmonk -ldflags="-s -w -X 'main.buildString=v5.1.0 (#f8dee184 2025-12-05T07:48:45+0000)' -X 'main.versionString=v5.1.0'" cmd/*.go

vs.

❯ SOURCE_DATE_EPOCH=1 make dist 
CGO_ENABLED=0 go build -o listmonk -ldflags="-s -w -X 'main.buildString=v5.1.0 (#f8dee184)' -X 'main.versionString=v5.1.0'" cmd/*.go

toabctl avatar Dec 05 '25 07:12 toabctl

Hi @toabctl. If SOURCE_DATE_EPOCH is set, it should be used as the Unix timestamp offset and the date should be derived from that, otherwise, the system time. Here, if it's set, the date bit in the build string is completely eliminated, which isn't right.

knadh avatar Dec 12 '25 07:12 knadh