Skip to content

Commit

Permalink
[bazel] Make pip wheels install reproducible
Browse files Browse the repository at this point in the history
When installing python packages using pip, we use a custom script
that invokes python directly. By default, python will timestamp
bytecode files hence making the builds non-reproducible which is
bad for CI. Python also uses a random seed for hash.
This commit sets two environment variables when running pip that
force python to use a deterministic seed and to use a fixed
timestamp instead of the current time.

Signed-off-by: Amaury Pouly <amaury.pouly@lowrisc.org>
  • Loading branch information
pamaury committed Jan 18, 2024
1 parent de31bdf commit 9fe2120
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions third_party/python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def _pip_wheel_impl(rctx):
rctx.report_progress("Installing the Python wheel package")
result = rctx.execute(
args,
environment = {
"SOURCE_DATE_EPOCH": "315532800",
"PYTHONHASHSEED": "0",
},
timeout = rctx.attr.timeout,
quiet = rctx.attr.quiet,
)
Expand All @@ -66,6 +70,10 @@ def _pip_wheel_impl(rctx):
rctx.report_progress("Pre-building Python wheels")
result = rctx.execute(
args,
environment = {
"SOURCE_DATE_EPOCH": "315532800",
"PYTHONHASHSEED": "0",
},
timeout = rctx.attr.timeout,
quiet = rctx.attr.quiet,
)
Expand All @@ -81,6 +89,10 @@ def _pip_wheel_impl(rctx):
rctx.report_progress("Generating sanitzed requirements file")
result = rctx.execute(
args,
environment = {
"SOURCE_DATE_EPOCH": "315532800",
"PYTHONHASHSEED": "0",
},
timeout = rctx.attr.timeout,
quiet = rctx.attr.quiet,
working_directory = "./",
Expand Down

0 comments on commit 9fe2120

Please sign in to comment.