-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
build: depend on standard variable to let the user define the builddate #7186
Conversation
Currently Arch Linux has an unreproducible package due to this -- the time-limited results can be seen here: https://tests.reproducible-builds.org/archlinux/community/crystal/crystal-0.27.0-1-x86_64.pkg.tar.xz.html This seemed like a better fix than adding special code to our package. |
Well, it's always possible to simply set But changing to a standardized environment variable doesn't sound like a bad idea. The implementation isn't portable, though. These |
A disadvantage of However, it is more accurate as it enforces a granularity of one second. I'm not sure if that is truly relevant, though. |
At least I agree on the |
Oof, should have thought of that. Actually, the reproducible-builds docs specifically suggest for BSD compatibility to use |
eb95a0c
to
d17d208
Compare
The only people using it (for deterministic builds) don't typically worry about human readability, they worry about accuracy. :) And, you can easily generate it yourself with |
It might work for now. Windows will need a different implementation, though. But I guess that can be solved later.
I meant that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think replacing CRYSTAL_CONFIG_BUILD_DATE
is probably fine. If anyone objects though, i'm fine with continuing to support both.
Having both would probably be the worst option. Either one of them is fine. |
I don't know crystal, so I'm somewhat limited to guessing based on generic programming patterns and sticking things in willy-nilly if they look useful. And, it was a lot easier to try to stick with existing subprocesses but change the shell code used, than to try to do real programming in crystal. :D But apparently that won't be so simple... So looking through google to find out how to manipulate time natively gets me to references for
Oookay. So, turns out the top google hit for crystal documentation is a very old version, and there is no indication of that on https://crystal-lang.org/api/0.20.0/Time.html (or header dropdowns offering to steer me to the latest version). I guess, it looks like
This would surely be the cleanest way forward, since crystal can control its own API for embedding a number and turning it into a formatted date string. So... how to do it? |
We can probably do this: def self.date
unix = {{(env("SOURCE_DATE_EPOCH") || `date +%s`).to_i}}
Time.unix(unix).to_s("%Y-%m-%d")
end You can only execute a subset of the language in macros in Crystal so you can't manipulate time and so on. However, we can compute the unix seconds, either with the env var or by using Eventually we could introduce one or all of |
And we should also keep |
Surely that's a reason not to keep it around? The build date reported by |
d17d208
to
3cf6ecd
Compare
Okay, new version still does the compile-time subprocess thing but embeds an epoch, and then formats that as output. It successfully compiles and respects |
Nix pkg uses it. . But that should't be a big deal to change. Keeping two environment variables for the same purpose is just going to be a burdon. |
I believe Nixos has a global setup hook which sets |
I see no problem keeping two environment variables. It's more flexible and maintaining that is just one line of code. But if you all free it's too much we can remove it. |
SOURCE_DATE_EPOCH is the standard for reproducible builds; using it means most groups that care will automatically benefit from this without setting project-specific variables. https://reproducible-builds.org/docs/source-date-epoch/
3cf6ecd
to
a4e36b0
Compare
@peterhoeg relevant to #6788 (comment) I think this is a better solution. Nixos should be fine with this, correct?
I guess that would be this instead... https://github.com/NixOS/nixpkgs/blob/6a2c004d0f044b1055e4e6197dfd0db86caa0398/pkgs/stdenv/generic/setup.sh#L244 |
There's also NixOS/nixpkgs@81e530a#diff-6b4b935e9a925c39793b071281c8c98a @asterite I don't see the benefit in keeping two environment variables. It's just more things that a distro maintainer can get wrong (imagine if something starts parsing |
Using |
SOURCE_DATE_EPOCH is the standard for reproducible builds; using it means most groups that care will automatically benefit from this without setting project-specific variables.
https://reproducible-builds.org/docs/source-date-epoch/
...
I am going with the flow here since this currently uses a subprocess, but surely there must be some part of the language spec that allows you to do this without such hacks? Anyway, that's not strictly related to this fix...