Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Feature] Remove timestamp from header to make script builds reproducible

Open Thesola10 opened this issue 10 months ago • 5 comments

Is your feature request related to a problem? Please describe. Currently, as a default, Amber adds a comment that looks like this to the top of a compiled file:

#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha
# date: 2025-02-07 15:51:45

The outstanding issue here is the date entry, which specifies when the script has been built, down to the second. Fundamentally, this breaks reproducible builds -- i.e. the guarantee that you will get the exact same output given the exact same input.

Describe the solution you'd like To aid in reproducibility efforts ongoing on several Linux distributions, it would be nice to have an option to disable adding a timestamp to built scripts.

This could be an environment variable, such as AMBER_NO_TIMESTAMP.

Describe alternatives you've considered Wrapping the compiler in a program that simulates a zero timestamp would be too cumbersome, and introduce fragility into an otherwise simple build process.

Post-processing the script to remove the date field would be even more fragile.

Thesola10 avatar Feb 07 '25 15:02 Thesola10

if I am not wrong we added a way to customize the header in the script but I don't remember right now.

Mte90 avatar Feb 07 '25 16:02 Mte90

It was discussed in #344 but right now it looks to me like header generation is hardcoded:

https://github.com/amber-lang/amber/blob/d3ceda317fc053ae9645e9f3c8f166657eba24e9/src/compiler.rs#L199-L203

Thesola10 avatar Feb 07 '25 16:02 Thesola10

i wouldn't change the current header, but rather add an option to use a custom template for the header. probably add some more variables that could be used. im pretty sure that's been discussed before and honestly shouldn't be very hard to implement

b1ek avatar Feb 10 '25 04:02 b1ek

I think that:

  • AMBER_HEADER = "path to header.sh"

Can be the best option, if that variable is not set use the default one. In this way we can improve it without adding too many parameters in the code and the user can do whatevery he wants.

I think too that isn't very difficult to implement. Also can be used to inject BASH code if the user need it, like to import stuff.

Mte90 avatar Feb 18 '25 10:02 Mte90

I want to add also https://github.com/amber-lang/amber/issues/635 so we can do both in a single PR

Mte90 avatar Feb 18 '25 10:02 Mte90