Skip to content

Commit

Permalink
Allow to override build date with SOURCE_DATE_EPOCH (dotnet#46311)
Browse files Browse the repository at this point in the history
Allow to override build date with `SOURCE_DATE_EPOCH`
in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.

This date call works with different variants of the date command.

Also use UTC to be independent of timezone.

This helps a bit towards deterministic mono builds = issue mono/mono#20172

This PR was done while working on reproducible builds for openSUSE.

Co-authored-by: bmwiedemann <[email protected]>
  • Loading branch information
monojenkins and bmwiedemann authored Dec 22, 2020
1 parent 218ef0f commit e1354f1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mono/mono/mini/Makefile.am.in
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,18 @@ AM_CPPFLAGS = $(LIBGC_CPPFLAGS)
mono_sgen_SOURCES =
mono_sgen_CFLAGS = $(AM_CFLAGS) @CXX_REMOVE_CFLAGS@

BUILD_DATE = $(shell SOURCE_DATE_EPOCH="$${SOURCE_DATE_EPOCH:-$$(date +%s)}" ;date -u -d "@$$SOURCE_DATE_EPOCH" 2>/dev/null || date -u -r "$$SOURCE_DATE_EPOCH" 2>/dev/null || date -u)

# We build this after libmono was built so it contains the date when the final
# link was done
if SUPPORT_BOEHM
buildver-boehm.h: libmini.la $(monodir)/mono/metadata/libmonoruntime.la
@echo "const char *build_date = \"`date`\";" > buildver-boehm.h
@echo "const char *build_date = \"$(BUILD_DATE)\";" > buildver-boehm.h
libmain_a-main.$(OBJEXT): buildver-boehm.h
endif

buildver-sgen.h: libmini.la $(monodir)/mono/metadata/libmonoruntimesgen.la $(monodir)/mono/sgen/libmonosgen.la
@echo "const char *build_date = \"`date`\";" > buildver-sgen.h
@echo "const char *build_date = \"$(BUILD_DATE)\";" > buildver-sgen.h

libmain_a-main-sgen.$(OBJEXT): buildver-sgen.h

Expand Down

0 comments on commit e1354f1

Please sign in to comment.