fbc icon indicating copy to clipboard operation
fbc copied to clipboard

Support for SOURCE_DATE_EPOCH

Open OPNA2608 opened this issue 3 years ago • 3 comments

SOURCE_DATE_EPOCH is an environment variable that provides the seconds since the Unix epoch that should be used for any build time/date macros and functions. It's a functionality that helps with build result reproducibility and has found adoption in projects like Debian and GCC.

It would be great if fbc could support SOURCE_DATE_EPOCH for both its own date in fbc --version and any other code that uses its affected date and time macros/functions.

OPNA2608 avatar Jul 30 '22 10:07 OPNA2608

Support for SOURCE_DATE_EPOCH looks like a reasonable addition. At the very least cosmetically this would be handy for building the many packages for binary releases, which sometimes will have different date stamps depending on the platform and the order that the builds were compiled.

We have something similar we could possibly follow; the repository commit hash can be baked in to the build: https://github.com/freebasic/fbc/blob/70741db519941ff5209a28d8d6f2f4f6d2f62194/makefile#L545 we can either set the hash explicitly or grab it automatically from the current repository.

I would expect that SOURCE_DATE_EPOCH is externally managed by the builder/maintainer, because trying to commit meta data in to the repository that itself needs to reference the repository's meta data would be convoluted, I think.

Simplest starting approach would be to check for SOURCE_DATE_EPOCH already set and compute a BUILD_DATE by the host to pass in to the build.

jayrm avatar Aug 07 '22 18:08 jayrm

SOURCE_DATE_EPOCH is handled externally by the build / package environment setup yep.

https://github.com/NixOS/nixpkgs/blob/350fd0044447ae8712392c6b212a18bdf2433e71/pkgs/stdenv/generic/setup.sh#L258-L264 https://github.com/NixOS/nixpkgs/blob/350fd0044447ae8712392c6b212a18bdf2433e71/pkgs/build-support/setup-hooks/set-source-date-epoch-to-latest.sh

bt1cn@NixTop:~
↪ nix-shell -p stdenv

[nix-shell:~]$ echo $SOURCE_DATE_EPOCH 
315532800

[nix-shell:~]$ LANG=en_GB.UTF-8 date -ud @$SOURCE_DATE_EPOCH
Tue  1 Jan 00:00:00 UTC 1980

OPNA2608 avatar Aug 07 '22 22:08 OPNA2608

For usage of SOURCE_DATE_EPOCH, checking directly by the compiler seems straightforward. See #392

The drawback of course is that we have to compile fbc twice to get it working: first to add the feature, second time to use it to (within fbc itself).

Since the setting of SOURCE_DATE_EPOCH is handled externally and is imho an arbitrary value, then it is ultimately up to the builder / maintainer what to use - i.e. changelog.txt file timestamp from a source tarball, last git log timestamp from repository, etc. Adding a rule to the makefile to set this for releases is an option can explore later.

jayrm avatar Aug 13 '22 11:08 jayrm

Support added by #392

Documentation (at least a brief reference) added at FreeBASIC Build Options

jayrm avatar Sep 18 '22 18:09 jayrm