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

build_context: improve wheel reproducibility by sorting libs #2261

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

ycongal-smile
Copy link
Contributor

While tracking a reproducibility issue from maturin's output, we found that the .so file in the output .whl were not ordered the same every time.

Order of the external libraries in the .whl comes down to the order soname_map is iterated. But, std::HashMap does not provide a stable order and that create an unstable order in the wheel.

Switch to std::BTreeMap which keeps keys sorted and is iterable in a stable order.

This can be tested by building current python3-cryptography :

SOURCE_DATE_EPOCH=1728915855 maturin build

Before this commit, the above give two possible outputs (~50% each), the difference is in the order of libssl and libcrypto.

After this commit, the output is reproducible.

@ycongal-smile ycongal-smile force-pushed the yco/improve_reproducibility branch from 69d43d1 to e608c97 Compare October 17, 2024 15:44
@ycongal-smile
Copy link
Contributor Author

ping @moto-timo

@ycongal-smile ycongal-smile marked this pull request as ready for review October 17, 2024 15:46
@ycongal-smile ycongal-smile force-pushed the yco/improve_reproducibility branch from f894adf to 3656138 Compare October 17, 2024 15:47
While tracking a reproducibility issue from maturin's output, we found
that the .so file in the output .whl were not ordered the same
every time.

Order of the external libraries in the .whl comes down to the order
`soname_map` is iterated. But, `std::HashMap` does not provide a stable
order and that create an unstable order in the wheel.

Switch to `std::BTreeMap` which keeps keys sorted and is iterable
in a stable order.

This can be tested by building current python3-cryptography :
```
SOURCE_DATE_EPOCH=1728915855 maturin build
```
Before this commit, the above give two possible outputs (~50% each), the
difference is in the order of libssl and libcrypto.

After this commit, the output is reproducible.

Signed-off-by: Yoann Congal <[email protected]>
@ycongal-smile ycongal-smile force-pushed the yco/improve_reproducibility branch from de35126 to b3c7051 Compare October 17, 2024 15:49
Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@konstin konstin enabled auto-merge October 17, 2024 15:53
@konstin konstin added this pull request to the merge queue Oct 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2024
@konstin konstin added this pull request to the merge queue Oct 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2024
@konstin konstin merged commit 61d5480 into PyO3:main Oct 17, 2024
29 checks passed
@ycongal-smile ycongal-smile deleted the yco/improve_reproducibility branch October 18, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants