Skip to content

Commit 1c56fb0

Browse files
author
nixo
committed
timefuncs: support SOURCE_DATE_EPOCH for reproducible builds
1 parent b9c1c1d commit 1c56fb0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/support/timefuncs.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ JL_DLLEXPORT int jl_gettimeofday(struct jl_timeval *jtv)
3636
jtv->sec = tb.time;
3737
jtv->usec = tb.millitm * 1000;
3838
#else
39-
struct timeval tv;
40-
int code = gettimeofday(&tv, NULL);
41-
jtv->sec = tv.tv_sec;
42-
jtv->usec = tv.tv_usec;
39+
int code = 0; // success
40+
// Allow reproducible build by using the environment variable SOURCE_DATE_EPOCH
41+
// https://reproducible-builds.org/docs/source-date-epoch/
42+
time_t now;
43+
char *source_date_epoch;
44+
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
45+
(now = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0) {
46+
struct timeval tv;
47+
code = gettimeofday(&tv, NULL);
48+
jtv->sec = tv.tv_sec;
49+
jtv->usec = tv.tv_usec;
50+
} else {
51+
jtv->sec = now;
52+
jtv->usec = 0;
53+
}
4354
#endif
4455
return code;
4556
}

0 commit comments

Comments
 (0)