Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Makefile] Support reproducible builds #406

Merged
merged 1 commit into from Feb 17, 2020

Conversation

Foxboron
Copy link
Contributor

It's bad form to embed timestamps in binaries as it prevents
reproducible builds of the resulting binary.

The Reproducible Builds project defines SOURCE_DATE_EPOCH to help
reproduce binaries by allowing the date format to be overridden. This
patch adds support for this for GNU and BSD date.

Go 1.13 introduces -trimpath which strips build paths from all
compiled binaries. This enables people to reproduce the distributed cli
binary without having to recreate the build path.

https://reproducible-builds.org/specs/source-date-epoch/
https://reproducible-builds.org/docs/build-path/

Signed-off-by: Morten Linderud morten@linderud.pw

It's bad form to embed timestamps in binaries as it prevents
reproducible builds of the resulting binary.

The Reproducible Builds project defines SOURCE_DATE_EPOCH to help
reproduce binaries by allowing the date format to be overridden. This
patch adds support for this for GNU and BSD date.

Go 1.13 introduces `-trimpath` which strips build paths from all
compiled binaries. This enables people to reproduce the distributed cli
binary without having to recreate the build path.

https://reproducible-builds.org/specs/source-date-epoch/
https://reproducible-builds.org/docs/build-path/

Signed-off-by: Morten Linderud <morten@linderud.pw>
@vilmibm
Copy link
Contributor

vilmibm commented Feb 14, 2020

thanks!

I like this but it's my first time looking at the reproducible build stuff. Is it the case using SOURCE_DATE_EPOCH is only useful when paired with it being present in the env at build time? In other words, merging this will not lead to reproducible builds until we also tweak our automated build process?

@Foxboron
Copy link
Contributor Author

The idea behind SOURCE_DATE_EPOCH is to replay the build time and override it correctly in a standardized way if we want to reproduce the binary. It doesn't need to be set, but for the CI I'd set it and print it for the sake of people interested in reproducing it.

Currently distribution package managers and reproduction toolchains record and replay SOURCE_DATE_EPOCH when building.

If you are interested how this work downstream I did write a little about it in November for Arch Linux; https://linderud.dev/blog/reproducible-arch-linux-packages/

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks good, but I have a minor comment

@@ -2,15 +2,21 @@ BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)

GH_VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
DATE_FMT = +%Y-%m-%d
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the final date -u "$(DATE_FMT)" fallback, which doesn't seem to respect SOURCE_DATE_EPOCH?

Copy link
Contributor Author

@Foxboron Foxboron Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's taken verbatim from the reproducible builds efforts; https://reproducible-builds.org/docs/source-date-epoch/

My guess it's a guard regarding a future date regressions. I can go ask the community for a better detail or dig up some change logs if that desirable.

EDIT: Heh. I realized that it is indeed noted on the webpage 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking that up!

@mislav mislav merged commit 9dd9b8c into cli:master Feb 17, 2020
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.

None yet

3 participants