|
2 | 2 | from inspect import cleandoc as heredoc |
3 | 3 | from glob import glob |
4 | 4 | from pathlib import Path |
| 5 | +import shutil |
| 6 | +import sys |
5 | 7 |
|
6 | 8 | import nox |
7 | 9 | import nox.command |
@@ -135,6 +137,77 @@ def test_crossenv(session: nox.Session): |
135 | 137 | ) |
136 | 138 |
|
137 | 139 |
|
| 140 | +@nox.session(name="test-cross") |
| 141 | +def test_cross(session: nox.Session): |
| 142 | + session.install(".") |
| 143 | + session.install("-U", "setuptools", "build") |
| 144 | + |
| 145 | + shutil.rmtree("examples/namespace_package/dist", ignore_errors=True) |
| 146 | + |
| 147 | + namespace_package = Path(__file__).parent / "examples" / "namespace_package" |
| 148 | + os.chdir(namespace_package) |
| 149 | + session.run( |
| 150 | + "docker", |
| 151 | + "build", |
| 152 | + "-t", |
| 153 | + "cross-pyo3:aarch64-unknown-linux-gnu", |
| 154 | + ".", |
| 155 | + external=True, |
| 156 | + ) |
| 157 | + |
| 158 | + major_version = sys.version_info[0] |
| 159 | + minor_version = sys.version_info[1] |
| 160 | + |
| 161 | + cpXY = f"cp{major_version}{minor_version}" |
| 162 | + |
| 163 | + tmp = Path(session.create_tmp()) |
| 164 | + extra_config = tmp / "build-opts.cfg" |
| 165 | + build_config = """ |
| 166 | + [bdist_wheel] |
| 167 | + plat_name = manylinux2014_aarch64 |
| 168 | + """ |
| 169 | + extra_config.write_text(heredoc(build_config), encoding="utf-8") |
| 170 | + |
| 171 | + build_env = os.environ.copy() |
| 172 | + build_env["DIST_EXTRA_CONFIG"] = str(extra_config.absolute()) |
| 173 | + build_env["CARGO"] = "cross" |
| 174 | + build_env["CARGO_BUILD_TARGET"] = "aarch64-unknown-linux-gnu" |
| 175 | + build_env["PYO3_CROSS_LIB_DIR"] = f"/opt/python/{cpXY}-{cpXY}/lib" |
| 176 | + |
| 177 | + # build wheel using cross |
| 178 | + # |
| 179 | + # if this step fails, you may need to install cross: |
| 180 | + # cargo install cross --git https://github.com/cross-rs/cross |
| 181 | + session.run("python", "-m", "build", "--no-isolation", env=build_env) |
| 182 | + |
| 183 | + script_check = """ |
| 184 | +set -eux |
| 185 | +python3 --version |
| 186 | +python3 -m venv .venv |
| 187 | +source .venv/bin/activate |
| 188 | +pip install namespace_package --no-index --find-links /io/dist/ --force-reinstall |
| 189 | +python -c "from namespace_package import rust; assert rust.rust_func() == 14" |
| 190 | +python -c "from namespace_package import python; assert python.python_func() == 15" |
| 191 | +""" |
| 192 | + |
| 193 | + session.run( |
| 194 | + "docker", |
| 195 | + "run", |
| 196 | + "--rm", |
| 197 | + "-v", |
| 198 | + f"{namespace_package}:/io", |
| 199 | + "-w", |
| 200 | + "/io", |
| 201 | + "--platform", |
| 202 | + "aarch64", |
| 203 | + f"python:3.{minor_version}", |
| 204 | + "bash", |
| 205 | + "-c", |
| 206 | + script_check, |
| 207 | + external=True, |
| 208 | + ) |
| 209 | + |
| 210 | + |
138 | 211 | @nox.session() |
139 | 212 | def ruff(session: nox.Session): |
140 | 213 | session.install("ruff") |
|
0 commit comments