diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 966ab9686..1e1a19a8f 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -117,6 +117,7 @@ def __enter__(self) -> OCIContainer: self.engine.name, "create", "--env=CIBUILDWHEEL", + "--env=SOURCE_DATE_EPOCH", f"--name={self.name}", "--interactive", "--volume=/:/host", # ignored on CircleCI diff --git a/docs/options.md b/docs/options.md index b597684ce..078c907d5 100644 --- a/docs/options.md +++ b/docs/options.md @@ -680,6 +680,9 @@ A list of environment variables to pass into the linux container during the buil To specify more than one environment variable, separate the variable names by spaces. +!!! note + cibuildwheel automatically passes the environment variable [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/docs/source-date-epoch/) if defined. + #### Examples !!! tab examples "Environment passthrough" diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index ccbd05555..a4b200d99 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -72,6 +72,17 @@ def test_environment(container_engine): ) +def test_environment_pass(container_engine, monkeypatch): + monkeypatch.setenv("CIBUILDWHEEL", "1") + monkeypatch.setenv("SOURCE_DATE_EPOCH", "1489957071") + with OCIContainer(engine=container_engine, image=DEFAULT_IMAGE) as container: + assert container.call(["sh", "-c", "echo $CIBUILDWHEEL"], capture_output=True) == "1\n" + assert ( + container.call(["sh", "-c", "echo $SOURCE_DATE_EPOCH"], capture_output=True) + == "1489957071\n" + ) + + def test_cwd(container_engine): with OCIContainer( engine=container_engine, image=DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory"