Skip to content
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

Use SOURCE_DATE_EPOCH environment variable to set mtime of files in wheel #1320

Closed
zmanji opened this issue Dec 2, 2022 · 1 comment · Fixed by #1334
Closed

Use SOURCE_DATE_EPOCH environment variable to set mtime of files in wheel #1320

zmanji opened this issue Dec 2, 2022 · 1 comment · Fixed by #1334
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zmanji
Copy link
Contributor

zmanji commented Dec 2, 2022

Currently running maturin build does not have reproducible wheel output even if the input files have not changed. This can be observed by doing the following:

  1. Running maturin build
  2. Record the md5sum of the output wheel
  3. Running the same maturin build command again without changing any of the python or rust files
  4. Observe the md5sum of the output wheel is different

I noticed in my case it's because the mtime timestamp of the files in the wheel have been updated.

It would be great if maturin respected the SOURCE_DATE_EPOCH environment variable like wheel already does:
https://github.com/pypa/wheel/blob/70d8f7f5189fac0dfbf21b83adbd2781d2537c17/src/wheel/wheelfile.py#L26-L31

If this environment variable is set, it would be used to set the mtime of the files in the wheel, making the output reproducible.

Having reproducibility is really handy for me because a build system may skip tasks if the wheel is the same.

I think the change would be as simple as adjusting

let options = zip::write::FileOptions::default()
.unix_permissions(permissions)
.compression_method(compression_method);
self.zip.start_file(target.clone(), options)?;
self.zip.write_all(bytes)?;
to explicitly set the mtime.

@zmanji zmanji added the enhancement New feature or request label Dec 2, 2022
@messense messense added the good first issue Good for newcomers label Dec 2, 2022
@messense
Copy link
Member

messense commented Dec 3, 2022

Pull requests are welcome.

bors bot added a commit that referenced this issue Dec 6, 2022
1334: Support SOURCE_DATE_EPOCH environment variable in wheel building r=messense a=zmanji

This adds support for the `SOURCE_DATE_EPOCH` environment variable like wheel does when building wheels. If this environment variable is set, the `mtime` of the files in the wheel are set to this value to ensure reproducible output.

Fixes #1320

Co-authored-by: Zameer Manji <zmanji@gmail.com>
@bors bors bot closed this as completed in 15f8045 Dec 6, 2022
messense pushed a commit to messense/maturin that referenced this issue Dec 8, 2022
This adds support for the `SOURCE_DATE_EPOCH` environment variable like wheel
does when building wheels. If this environment variable is set, the `mtime` of
the files in the wheel are set to this value to ensure reproducible output.

Fixes PyO3#1320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants