From b150e62fbdf80fabe9b78c0d765eddcab9bf399c Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 11:56:35 +0100 Subject: [PATCH 01/33] Rename hello-world example to hello-world-setuppy --- examples/{hello-world => hello-world-setuppy}/Cargo.lock | 0 examples/{hello-world => hello-world-setuppy}/Cargo.toml | 0 examples/{hello-world => hello-world-setuppy}/MANIFEST.in | 0 examples/{hello-world => hello-world-setuppy}/noxfile.py | 0 examples/{hello-world => hello-world-setuppy}/pyproject.toml | 0 examples/{hello-world => hello-world-setuppy}/pytest.ini | 0 .../python/hello_world/__init__.py | 0 examples/{hello-world => hello-world-setuppy}/setup.py | 0 examples/{hello-world => hello-world-setuppy}/src/main.rs | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename examples/{hello-world => hello-world-setuppy}/Cargo.lock (100%) rename examples/{hello-world => hello-world-setuppy}/Cargo.toml (100%) rename examples/{hello-world => hello-world-setuppy}/MANIFEST.in (100%) rename examples/{hello-world => hello-world-setuppy}/noxfile.py (100%) rename examples/{hello-world => hello-world-setuppy}/pyproject.toml (100%) rename examples/{hello-world => hello-world-setuppy}/pytest.ini (100%) rename examples/{hello-world => hello-world-setuppy}/python/hello_world/__init__.py (100%) rename examples/{hello-world => hello-world-setuppy}/setup.py (100%) rename examples/{hello-world => hello-world-setuppy}/src/main.rs (100%) diff --git a/examples/hello-world/Cargo.lock b/examples/hello-world-setuppy/Cargo.lock similarity index 100% rename from examples/hello-world/Cargo.lock rename to examples/hello-world-setuppy/Cargo.lock diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world-setuppy/Cargo.toml similarity index 100% rename from examples/hello-world/Cargo.toml rename to examples/hello-world-setuppy/Cargo.toml diff --git a/examples/hello-world/MANIFEST.in b/examples/hello-world-setuppy/MANIFEST.in similarity index 100% rename from examples/hello-world/MANIFEST.in rename to examples/hello-world-setuppy/MANIFEST.in diff --git a/examples/hello-world/noxfile.py b/examples/hello-world-setuppy/noxfile.py similarity index 100% rename from examples/hello-world/noxfile.py rename to examples/hello-world-setuppy/noxfile.py diff --git a/examples/hello-world/pyproject.toml b/examples/hello-world-setuppy/pyproject.toml similarity index 100% rename from examples/hello-world/pyproject.toml rename to examples/hello-world-setuppy/pyproject.toml diff --git a/examples/hello-world/pytest.ini b/examples/hello-world-setuppy/pytest.ini similarity index 100% rename from examples/hello-world/pytest.ini rename to examples/hello-world-setuppy/pytest.ini diff --git a/examples/hello-world/python/hello_world/__init__.py b/examples/hello-world-setuppy/python/hello_world/__init__.py similarity index 100% rename from examples/hello-world/python/hello_world/__init__.py rename to examples/hello-world-setuppy/python/hello_world/__init__.py diff --git a/examples/hello-world/setup.py b/examples/hello-world-setuppy/setup.py similarity index 100% rename from examples/hello-world/setup.py rename to examples/hello-world-setuppy/setup.py diff --git a/examples/hello-world/src/main.rs b/examples/hello-world-setuppy/src/main.rs similarity index 100% rename from examples/hello-world/src/main.rs rename to examples/hello-world-setuppy/src/main.rs From c1af5a76f14f5bf007fa48efc313155fc83e6f79 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 11:57:21 +0100 Subject: [PATCH 02/33] Rename hello-world-pyprojecttoml example to hello-world --- examples/{hello-world-pyprojecttoml => hello-world}/Cargo.lock | 0 examples/{hello-world-pyprojecttoml => hello-world}/Cargo.toml | 0 examples/{hello-world-pyprojecttoml => hello-world}/MANIFEST.in | 0 examples/{hello-world-pyprojecttoml => hello-world}/build.rs | 0 examples/{hello-world-pyprojecttoml => hello-world}/noxfile.py | 0 .../{hello-world-pyprojecttoml => hello-world}/pyproject.toml | 0 .../python/hello_world/__init__.py | 0 .../python/hello_world/sum_cli.py | 0 examples/{hello-world-pyprojecttoml => hello-world}/rust/lib.rs | 0 .../rust/print_hello.rs | 0 .../tests/test_hello_world.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename examples/{hello-world-pyprojecttoml => hello-world}/Cargo.lock (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/Cargo.toml (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/MANIFEST.in (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/build.rs (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/noxfile.py (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/pyproject.toml (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/python/hello_world/__init__.py (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/python/hello_world/sum_cli.py (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/rust/lib.rs (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/rust/print_hello.rs (100%) rename examples/{hello-world-pyprojecttoml => hello-world}/tests/test_hello_world.py (100%) diff --git a/examples/hello-world-pyprojecttoml/Cargo.lock b/examples/hello-world/Cargo.lock similarity index 100% rename from examples/hello-world-pyprojecttoml/Cargo.lock rename to examples/hello-world/Cargo.lock diff --git a/examples/hello-world-pyprojecttoml/Cargo.toml b/examples/hello-world/Cargo.toml similarity index 100% rename from examples/hello-world-pyprojecttoml/Cargo.toml rename to examples/hello-world/Cargo.toml diff --git a/examples/hello-world-pyprojecttoml/MANIFEST.in b/examples/hello-world/MANIFEST.in similarity index 100% rename from examples/hello-world-pyprojecttoml/MANIFEST.in rename to examples/hello-world/MANIFEST.in diff --git a/examples/hello-world-pyprojecttoml/build.rs b/examples/hello-world/build.rs similarity index 100% rename from examples/hello-world-pyprojecttoml/build.rs rename to examples/hello-world/build.rs diff --git a/examples/hello-world-pyprojecttoml/noxfile.py b/examples/hello-world/noxfile.py similarity index 100% rename from examples/hello-world-pyprojecttoml/noxfile.py rename to examples/hello-world/noxfile.py diff --git a/examples/hello-world-pyprojecttoml/pyproject.toml b/examples/hello-world/pyproject.toml similarity index 100% rename from examples/hello-world-pyprojecttoml/pyproject.toml rename to examples/hello-world/pyproject.toml diff --git a/examples/hello-world-pyprojecttoml/python/hello_world/__init__.py b/examples/hello-world/python/hello_world/__init__.py similarity index 100% rename from examples/hello-world-pyprojecttoml/python/hello_world/__init__.py rename to examples/hello-world/python/hello_world/__init__.py diff --git a/examples/hello-world-pyprojecttoml/python/hello_world/sum_cli.py b/examples/hello-world/python/hello_world/sum_cli.py similarity index 100% rename from examples/hello-world-pyprojecttoml/python/hello_world/sum_cli.py rename to examples/hello-world/python/hello_world/sum_cli.py diff --git a/examples/hello-world-pyprojecttoml/rust/lib.rs b/examples/hello-world/rust/lib.rs similarity index 100% rename from examples/hello-world-pyprojecttoml/rust/lib.rs rename to examples/hello-world/rust/lib.rs diff --git a/examples/hello-world-pyprojecttoml/rust/print_hello.rs b/examples/hello-world/rust/print_hello.rs similarity index 100% rename from examples/hello-world-pyprojecttoml/rust/print_hello.rs rename to examples/hello-world/rust/print_hello.rs diff --git a/examples/hello-world-pyprojecttoml/tests/test_hello_world.py b/examples/hello-world/tests/test_hello_world.py similarity index 100% rename from examples/hello-world-pyprojecttoml/tests/test_hello_world.py rename to examples/hello-world/tests/test_hello_world.py From 8530b868275d9849dc19233450b183205e3bc14f Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 12:11:32 +0100 Subject: [PATCH 03/33] Use pyproject.toml for hello-world-script example --- examples/hello-world-script/noxfile.py | 11 ++++------- examples/hello-world-script/pyproject.toml | 15 +++++++++++++++ examples/hello-world-script/setup.py | 20 -------------------- 3 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 examples/hello-world-script/setup.py diff --git a/examples/hello-world-script/noxfile.py b/examples/hello-world-script/noxfile.py index 3fed5bb9..2f34dc52 100644 --- a/examples/hello-world-script/noxfile.py +++ b/examples/hello-world-script/noxfile.py @@ -8,12 +8,9 @@ @nox.session() def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "wheel") + # Ensure build uses version of setuptools-rust under development session.install("--no-build-isolation", ".") + # Test Rust binary session.run("hello-world-script", *session.posargs) - - -@nox.session() -def setuptools_install(session: nox.Session): - session.install(SETUPTOOLS_RUST) - session.run("python", "setup.py", "install") - session.run("hello-world-script", *session.posargs) + # Test Python package + session.run("python", "-c", "import hello_world; print(hello_world)") diff --git a/examples/hello-world-script/pyproject.toml b/examples/hello-world-script/pyproject.toml index 8619d878..88ab8f09 100644 --- a/examples/hello-world-script/pyproject.toml +++ b/examples/hello-world-script/pyproject.toml @@ -1,3 +1,18 @@ [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] build-backend = "setuptools.build_meta" + +[project] +name = "hello-world" +version = "1.0" + +[tool.setuptools.packages] +# Pure Python packages/modules +find = { where = ["python"] } + +[[tool.setuptools-rust.bins]] +# Private Rust extension module to be nested into Python package +target = "hello-world-script" # Matches bin.name in Cargo.toml + # (or package.name if [[bin]] is missing and src/main.rs exists) +args = ["--profile", "release-lto"] # Extra args for Cargo +# See reference for RustBin in https://setuptools-rust.readthedocs.io/en/latest/reference.html diff --git a/examples/hello-world-script/setup.py b/examples/hello-world-script/setup.py deleted file mode 100644 index 7ea2e072..00000000 --- a/examples/hello-world-script/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from setuptools import find_packages, setup - -from setuptools_rust import RustExtension, Binding - -setup( - name="hello-world-script", - version="1.0", - packages=find_packages(where="python"), - package_dir={"": "python"}, - rust_extensions=[ - RustExtension( - {"hello-world-script": "hello_world.hello-world-script"}, - binding=Binding.Exec, - script=True, - args=["--profile", "release-lto"], - ) - ], - # rust extensions are not zip safe, just like C-extensions. - zip_safe=False, -) From 41db1597c44e91557c155cea49a99e96b53220a1 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 12:43:03 +0100 Subject: [PATCH 04/33] Use pyproject.toml for namespace_package example --- examples/namespace_package/noxfile.py | 9 ++------- examples/namespace_package/pyproject.toml | 22 ++++++++++++++++++++++ examples/namespace_package/setup.py | 19 ------------------- 3 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 examples/namespace_package/setup.py diff --git a/examples/namespace_package/noxfile.py b/examples/namespace_package/noxfile.py index 089613f3..65d0a3f4 100644 --- a/examples/namespace_package/noxfile.py +++ b/examples/namespace_package/noxfile.py @@ -8,12 +8,7 @@ @nox.session() def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "wheel", "pytest") + # Ensure build uses version of setuptools-rust under development session.install("--no-build-isolation", ".") - session.run("pytest", *session.posargs) - - -@nox.session() -def setuptools_install(session: nox.Session): - session.install(SETUPTOOLS_RUST, "pytest") - session.run("python", "setup.py", "install") + # Test Python package session.run("pytest", *session.posargs) diff --git a/examples/namespace_package/pyproject.toml b/examples/namespace_package/pyproject.toml index 8619d878..0b6302bd 100644 --- a/examples/namespace_package/pyproject.toml +++ b/examples/namespace_package/pyproject.toml @@ -1,3 +1,25 @@ [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] build-backend = "setuptools.build_meta" + +[project] +name="namespace_package" +version="0.1.0" + +[tool.setuptools.packages] +# Pure Python packages/modules +find = { where = ["python"] } + +[[tool.setuptools-rust.ext-modules]] +target = "namespace_package.rust" +# ^-- The last part of the target name (e.g. "rust") should match lib.name in Cargo.toml, +# but you can add a prefix to nest it inside of a parent Python package or namespace. +# Note that lib.name may not be defined in the Cargo.toml, but you still +# have to match the name of the function with the `#[pymodule]` attribute. +path = "Cargo.toml" +# ^-- Default value for cargo's manifest (can be omitted) +# Each manifest can have a single [lib] definition. +# To specify multiple extension modules you can use different toml files (one each). +binding = "PyO3" # Default value, can be omitted +debug = false +# See reference for RustExtension in https://setuptools-rust.readthedocs.io/en/latest/reference.html diff --git a/examples/namespace_package/setup.py b/examples/namespace_package/setup.py deleted file mode 100644 index 43003e94..00000000 --- a/examples/namespace_package/setup.py +++ /dev/null @@ -1,19 +0,0 @@ -from setuptools import setup, find_namespace_packages -from setuptools_rust import Binding, RustExtension - - -setup( - name="namespace_package", - version="0.1.0", - packages=find_namespace_packages(include=["namespace_package.*"], where="python"), - package_dir={"": "python"}, - zip_safe=False, - rust_extensions=[ - RustExtension( - "namespace_package.rust", - path="Cargo.toml", - binding=Binding.PyO3, - debug=False, - ) - ], -) From c76af32ae79f949569c6178f5c53cc351da317dd Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 12:54:31 +0100 Subject: [PATCH 05/33] Use pyproject.toml for html-py-ever example --- examples/html-py-ever/noxfile.py | 9 ++------- examples/html-py-ever/pyproject.toml | 16 ++++++++++++++++ examples/html-py-ever/setup.py | 11 ----------- 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100755 examples/html-py-ever/setup.py diff --git a/examples/html-py-ever/noxfile.py b/examples/html-py-ever/noxfile.py index 2c830e39..b2636c99 100644 --- a/examples/html-py-ever/noxfile.py +++ b/examples/html-py-ever/noxfile.py @@ -10,12 +10,7 @@ def test(session: nox.Session): session.install( SETUPTOOLS_RUST, "wheel", "pytest", "pytest-benchmark", "beautifulsoup4" ) + # Ensure build uses version of setuptools-rust under development session.install("--no-build-isolation", ".") - session.run("pytest", *session.posargs) - - -@nox.session() -def setuptools_install(session: nox.Session): - session.install(SETUPTOOLS_RUST, "pytest", "pytest-benchmark", "beautifulsoup4") - session.run("python", "setup.py", "install") + # Test Python package session.run("pytest", *session.posargs) diff --git a/examples/html-py-ever/pyproject.toml b/examples/html-py-ever/pyproject.toml index 8619d878..7e168df6 100644 --- a/examples/html-py-ever/pyproject.toml +++ b/examples/html-py-ever/pyproject.toml @@ -1,3 +1,19 @@ [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] build-backend = "setuptools.build_meta" + +[project] +name = "html-py-ever" +version = "0.1.0" + +[tool.setuptools.packages] +# Pure Python packages/modules +find = { where = ["python"] } + + +[[tool.setuptools-rust.ext-modules]] +# Rust extension module to be nested into Python package +target = "html_py_ever.html_py_ever" +# ^-- The last part of the name (e.g. "html_py_ever") has to match lib.name in Cargo.toml, +# but you can add a prefix to nest it inside of a Python package. +# See reference for RustExtension in https://setuptools-rust.readthedocs.io/en/latest/reference.html diff --git a/examples/html-py-ever/setup.py b/examples/html-py-ever/setup.py deleted file mode 100755 index 7d236d43..00000000 --- a/examples/html-py-ever/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -from setuptools import find_packages, setup - -from setuptools_rust import RustExtension - -setup( - packages=find_packages(where="python"), - package_dir={"": "python"}, - rust_extensions=[RustExtension("html_py_ever.html_py_ever")], -) From 5c1cce436942b44e57da50e181428327af2781be Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:35:49 +0100 Subject: [PATCH 06/33] Avoid setup.py install in hello-world-setuppy example --- examples/hello-world-setuppy/noxfile.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/hello-world-setuppy/noxfile.py b/examples/hello-world-setuppy/noxfile.py index 2c14c8cf..e7a54bdc 100644 --- a/examples/hello-world-setuppy/noxfile.py +++ b/examples/hello-world-setuppy/noxfile.py @@ -8,12 +8,7 @@ @nox.session() def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "wheel") + # Ensure build uses version of setuptools-rust under development session.install("--no-build-isolation", ".") - session.run("hello-world", *session.posargs) - - -@nox.session() -def setuptools_install(session: nox.Session): - session.install(SETUPTOOLS_RUST) - session.run("python", "setup.py", "install") + # Test Rust binary session.run("hello-world", *session.posargs) From 624f5db050805bb419d820a4ea3e1ea1f56e817b Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 15:24:11 +0100 Subject: [PATCH 07/33] Avoid setup.py install in rust_with_cffi example --- examples/rust_with_cffi/noxfile.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/rust_with_cffi/noxfile.py b/examples/rust_with_cffi/noxfile.py index 7b3ec060..77b3287c 100644 --- a/examples/rust_with_cffi/noxfile.py +++ b/examples/rust_with_cffi/noxfile.py @@ -8,12 +8,7 @@ @nox.session() def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "wheel", "pytest", "cffi") + # Ensure build uses version of setuptools-rust under development session.install("--no-build-isolation", ".") - session.run("pytest", *session.posargs) - - -@nox.session() -def setuptools_install(session: nox.Session): - session.install(SETUPTOOLS_RUST, "pytest", "cffi") - session.run("python", "setup.py", "install") + # Test Python package session.run("pytest", *session.posargs) From c7c9c7f87cb174e43c9dd845a327ebbd5dc47d58 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 15:20:44 +0100 Subject: [PATCH 08/33] Modify noxfile to use build instead of running setup.py --- noxfile.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 27f9547b..5997b622 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,5 +1,6 @@ import os import tarfile +from inspect import cleandoc as heredoc from glob import glob from pathlib import Path from unittest.mock import patch @@ -15,10 +16,22 @@ def test_examples(session: nox.Session): @nox.session(name="test-sdist-vendor") def test_sdist_vendor(session: nox.Session): - session.install(".") + session.install(".", "build", "wheel") namespace_package = Path(__file__).parent / "examples" / "namespace_package" os.chdir(namespace_package) - session.run("python", "setup.py", "sdist", "--vendor-crates", external=True) + tmp = session.create_tmp() + + build_config = """ + [sdist] + vendor_crates = True + """ + Path(tmp, "setup.cfg").write_text(heredoc(build_config), encoding="utf-8") + + env = os.environ.copy() + env.update(DIST_EXTRA_CONFIG=str(Path(tmp, "setup.cfg"))) + cmd = ["python", "-m", "build", "--sdist", "--no-isolation"] + session.run(*cmd, env=env, external=True) + dist = namespace_package / "dist" with tarfile.open(str(dist / "namespace_package-0.1.0.tar.gz")) as tf: tf.extractall(str(dist)) @@ -77,7 +90,7 @@ def chdir(path: Path): @nox.session(name="test-examples-emscripten") def test_examples_emscripten(session: nox.Session): - session.install(".") + session.install(".", "build") emscripten_dir = Path("./emscripten").resolve() session.run( @@ -108,7 +121,8 @@ def test_examples_emscripten(session: nox.Session): PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"), ) with session.chdir(example): - session.run("python", "setup.py", "bdist_wheel", env=env, external=True) + cmd = ["python", "-m", "build", "--wheel", "--no-isolation"] + session.run(*cmd, env=env, external=True) with session.chdir(emscripten_dir): session.run("node", "runner.js", str(example), external=True) From ecba282f9e549f962f585c02b762ac44897718bb Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 15:22:38 +0100 Subject: [PATCH 09/33] Adapt GitHub workflows config to the adsence of setup.py --- .github/workflows/ci.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5539643..215abbe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,8 +120,8 @@ jobs: PYO3_CROSS_LIB_DIR: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib run: | cd examples/namespace_package - pip install wheel - python setup.py bdist_wheel + pip install build wheel + python -m build --no-isolation ls -l dist/ pip install --force-reinstall dist/namespace_package*_universal2.whl cd - @@ -269,11 +269,13 @@ jobs: CARGO: cross CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu PYO3_CROSS_LIB_DIR: /opt/python/cp38-cp38/lib + DIST_EXTRA_CONFIG: /tmp/build-opts.cfg run: | cd examples/namespace_package docker build -t cross-pyo3:aarch64-unknown-linux-gnu . - python -m pip install wheel - python setup.py bdist_wheel --plat-name manylinux2014_aarch64 + python -m pip install build wheel + echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG + python -m build --no-isolation ls -la dist/ - uses: uraimo/run-on-arch-action@v2.5.0 name: Install built wheel @@ -313,12 +315,14 @@ jobs: CARGO: cargo-zigbuild CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu PYO3_CROSS_LIB_DIR: /opt/python/cp38-cp38/lib + DIST_EXTRA_CONFIG: /tmp/build-opts.cfg run: | mkdir -p $PYO3_CROSS_LIB_DIR docker cp -L $(docker create --rm quay.io/pypa/manylinux2014_aarch64:latest):/opt/python/cp38-cp38 /opt/python cd examples/namespace_package - python -m pip install wheel - python setup.py bdist_wheel --plat-name manylinux2014_aarch64 + python -m pip install build wheel + echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG + python -m build --no-isolation ls -la dist/ - uses: uraimo/run-on-arch-action@v2.5.0 name: Install built wheel From 3772b274cffea46311d809de8d58b4aba9ea6468 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 17:12:50 +0100 Subject: [PATCH 10/33] Adequate test-mingw to new hello-world example --- noxfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 5997b622..209785f9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -73,7 +73,9 @@ def chdir(path: Path): session.install(".") session.install("--no-build-isolation", str(examples / "hello-world")) - session.run("hello-world") + session.run("print-hello") + session.run("sum-cli", "5", "7") + session.run("rust-demo", "5", "7") session.install("pytest", "pytest-benchmark", "beautifulsoup4") session.install("--no-build-isolation", str(examples / "html-py-ever")) From f9fb03e5303295c2a133c9ebe873e0c7364c69ea Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 17:03:07 +0100 Subject: [PATCH 11/33] Remove other direct uses of 'setup.py' in workflows/ci.yml --- .github/workflows/ci.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 215abbe6..99bb21da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -159,16 +159,18 @@ jobs: - name: Build an abi3 wheel shell: bash + env: + # https://github.com/actions/setup-python/issues/26 + MACOSX_DEPLOYMENT_TARGET: 10.9 + DIST_EXTRA_CONFIG: /tmp/build-opts.cfg run: | set -e cd examples/rust_with_cffi/ python --version - pip install -U wheel - python setup.py bdist_wheel --py-limited-api=cp39 + pip install -U build cffi wheel + echo -e "[bdist_wheel]\npy_limited_api=cp39" > $DIST_EXTRA_CONFIG + python -m build --no-isolation ls -la dist/ - env: - # https://github.com/actions/setup-python/issues/26 - MACOSX_DEPLOYMENT_TARGET: 10.9 # Now we switch to a differnet Python version and ensure we can install # the wheel we just built. @@ -225,8 +227,10 @@ jobs: build-pip install cffi wheel "setuptools>=62.4" cross-expose cffi pip install wheel - pip install -e ../../ - python setup.py bdist_wheel --py-limited-api=cp37 + pip install build cffi -e ../../ + export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg + echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG + python -m build ls -la dist/ ' > build-wheels.sh From e90228c689c7a286761ed24bd91dc87ee264e624 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:03:12 +0100 Subject: [PATCH 12/33] Migrate the hello-world-script example to a 'rust' dir --- examples/hello-world-script/Cargo.toml | 12 ++++++++++++ examples/hello-world-script/MANIFEST.in | 2 +- examples/hello-world-script/pyproject.toml | 1 - examples/hello-world-script/{src => rust}/main.rs | 0 4 files changed, 13 insertions(+), 2 deletions(-) rename examples/hello-world-script/{src => rust}/main.rs (100%) diff --git a/examples/hello-world-script/Cargo.toml b/examples/hello-world-script/Cargo.toml index 3de8ff33..7556deb4 100644 --- a/examples/hello-world-script/Cargo.toml +++ b/examples/hello-world-script/Cargo.toml @@ -10,3 +10,15 @@ edition = "2018" [profile.release-lto] inherits = "release" lto = true + +[[bin]] +name = "hello-world-script" +path = "rust/main.rs" +# See https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries +# +# If [[bin]] is not specified, but the file ``src/main.rs`` exists, +# you can also rely on an implicit definition which will behave similarly to: +# +# [[bin]] +# name = +# path = "src/main.rs" diff --git a/examples/hello-world-script/MANIFEST.in b/examples/hello-world-script/MANIFEST.in index 53741426..7c475173 100644 --- a/examples/hello-world-script/MANIFEST.in +++ b/examples/hello-world-script/MANIFEST.in @@ -1,3 +1,3 @@ include Cargo.toml -recursive-include src * +recursive-include rust * recursive-include python * diff --git a/examples/hello-world-script/pyproject.toml b/examples/hello-world-script/pyproject.toml index 88ab8f09..8021b80c 100644 --- a/examples/hello-world-script/pyproject.toml +++ b/examples/hello-world-script/pyproject.toml @@ -13,6 +13,5 @@ find = { where = ["python"] } [[tool.setuptools-rust.bins]] # Private Rust extension module to be nested into Python package target = "hello-world-script" # Matches bin.name in Cargo.toml - # (or package.name if [[bin]] is missing and src/main.rs exists) args = ["--profile", "release-lto"] # Extra args for Cargo # See reference for RustBin in https://setuptools-rust.readthedocs.io/en/latest/reference.html diff --git a/examples/hello-world-script/src/main.rs b/examples/hello-world-script/rust/main.rs similarity index 100% rename from examples/hello-world-script/src/main.rs rename to examples/hello-world-script/rust/main.rs From b28f5a967fc000f5ba479b059c2e3ebd38c6e9a7 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:21:25 +0100 Subject: [PATCH 13/33] Migrate the namespace_package example to a 'rust' dir --- examples/namespace_package/Cargo.toml | 11 +++++++++++ examples/namespace_package/MANIFEST.in | 2 +- examples/namespace_package/{src => rust}/lib.rs | 0 3 files changed, 12 insertions(+), 1 deletion(-) rename examples/namespace_package/{src => rust}/lib.rs (100%) diff --git a/examples/namespace_package/Cargo.toml b/examples/namespace_package/Cargo.toml index eed58b45..3c0019ee 100644 --- a/examples/namespace_package/Cargo.toml +++ b/examples/namespace_package/Cargo.toml @@ -4,7 +4,18 @@ version = "0.1.0" edition = "2018" [lib] +# When omitted, the name field will be assumed to have the same value as package.name +# https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-name-field crate-type = ["cdylib", "rlib"] +path = "rust/lib.rs" # When omitted, the value of "src/lib.rs" is assumed +# See https://doc.rust-lang.org/cargo/reference/cargo-targets.html#library +# +# If [lib] is not specified, but the file ``src/lib.rs`` exists, +# you can also rely on an implicit definition which will behave similarly to: +# +# [lib] +# name = +# path = "src/lib.rs" [dependencies] pyo3 = { version = "0.19.2", features = ["extension-module"] } diff --git a/examples/namespace_package/MANIFEST.in b/examples/namespace_package/MANIFEST.in index 53741426..7c475173 100644 --- a/examples/namespace_package/MANIFEST.in +++ b/examples/namespace_package/MANIFEST.in @@ -1,3 +1,3 @@ include Cargo.toml -recursive-include src * +recursive-include rust * recursive-include python * diff --git a/examples/namespace_package/src/lib.rs b/examples/namespace_package/rust/lib.rs similarity index 100% rename from examples/namespace_package/src/lib.rs rename to examples/namespace_package/rust/lib.rs From b85e7bf7252f537196bd6d22a0ba4500bfa348d6 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:24:53 +0100 Subject: [PATCH 14/33] Migrate the rust_with_cffi example to a 'rust' dir --- examples/rust_with_cffi/Cargo.toml | 1 + examples/rust_with_cffi/MANIFEST.in | 2 +- examples/rust_with_cffi/{src => rust}/lib.rs | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename examples/rust_with_cffi/{src => rust}/lib.rs (100%) diff --git a/examples/rust_with_cffi/Cargo.toml b/examples/rust_with_cffi/Cargo.toml index 3ea2bd48..ed70c85f 100644 --- a/examples/rust_with_cffi/Cargo.toml +++ b/examples/rust_with_cffi/Cargo.toml @@ -10,3 +10,4 @@ pyo3 = { version = "0.19.2", features = ["extension-module"] } [lib] name = "rust_with_cffi" crate-type = ["cdylib"] +path = "rust/lib.rs" diff --git a/examples/rust_with_cffi/MANIFEST.in b/examples/rust_with_cffi/MANIFEST.in index dba5df43..541ad8f4 100644 --- a/examples/rust_with_cffi/MANIFEST.in +++ b/examples/rust_with_cffi/MANIFEST.in @@ -1,4 +1,4 @@ include Cargo.toml include cffi_module.py -recursive-include src * +recursive-include rust * recursive-include python * diff --git a/examples/rust_with_cffi/src/lib.rs b/examples/rust_with_cffi/rust/lib.rs similarity index 100% rename from examples/rust_with_cffi/src/lib.rs rename to examples/rust_with_cffi/rust/lib.rs From 95de1bd868af0efcb02657eec4e052fa86a0d234 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:27:38 +0100 Subject: [PATCH 15/33] Migrate the html-py-ever example to a 'rust' dir --- examples/html-py-ever/Cargo.toml | 1 + examples/html-py-ever/MANIFEST.in | 2 +- examples/html-py-ever/{src => rust}/lib.rs | 0 examples/html-py-ever/{src => rust}/main.rs | 0 4 files changed, 2 insertions(+), 1 deletion(-) rename examples/html-py-ever/{src => rust}/lib.rs (100%) rename examples/html-py-ever/{src => rust}/main.rs (100%) diff --git a/examples/html-py-ever/Cargo.toml b/examples/html-py-ever/Cargo.toml index bf387ab6..e469ed67 100644 --- a/examples/html-py-ever/Cargo.toml +++ b/examples/html-py-ever/Cargo.toml @@ -12,3 +12,4 @@ tendril = "0.4.3" [lib] name = "html_py_ever" crate-type = ["cdylib"] +path = "rust/lib.rs" diff --git a/examples/html-py-ever/MANIFEST.in b/examples/html-py-ever/MANIFEST.in index 53741426..7c475173 100644 --- a/examples/html-py-ever/MANIFEST.in +++ b/examples/html-py-ever/MANIFEST.in @@ -1,3 +1,3 @@ include Cargo.toml -recursive-include src * +recursive-include rust * recursive-include python * diff --git a/examples/html-py-ever/src/lib.rs b/examples/html-py-ever/rust/lib.rs similarity index 100% rename from examples/html-py-ever/src/lib.rs rename to examples/html-py-ever/rust/lib.rs diff --git a/examples/html-py-ever/src/main.rs b/examples/html-py-ever/rust/main.rs similarity index 100% rename from examples/html-py-ever/src/main.rs rename to examples/html-py-ever/rust/main.rs From fdc99506abe800699bbca498d3faa86644233add Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 11 Aug 2023 13:34:32 +0100 Subject: [PATCH 16/33] Migrate the hello-world-setuppy example to a 'rust' dir --- examples/hello-world-setuppy/Cargo.toml | 4 ++++ examples/hello-world-setuppy/MANIFEST.in | 2 +- examples/hello-world-setuppy/{src => rust}/main.rs | 0 3 files changed, 5 insertions(+), 1 deletion(-) rename examples/hello-world-setuppy/{src => rust}/main.rs (100%) diff --git a/examples/hello-world-setuppy/Cargo.toml b/examples/hello-world-setuppy/Cargo.toml index a432ecd4..879d064b 100644 --- a/examples/hello-world-setuppy/Cargo.toml +++ b/examples/hello-world-setuppy/Cargo.toml @@ -10,3 +10,7 @@ edition = "2018" [profile.release-lto] inherits = "release" lto = true + +[[bin]] +name = "hello-world" +path = "rust/main.rs" diff --git a/examples/hello-world-setuppy/MANIFEST.in b/examples/hello-world-setuppy/MANIFEST.in index 53741426..7c475173 100644 --- a/examples/hello-world-setuppy/MANIFEST.in +++ b/examples/hello-world-setuppy/MANIFEST.in @@ -1,3 +1,3 @@ include Cargo.toml -recursive-include src * +recursive-include rust * recursive-include python * diff --git a/examples/hello-world-setuppy/src/main.rs b/examples/hello-world-setuppy/rust/main.rs similarity index 100% rename from examples/hello-world-setuppy/src/main.rs rename to examples/hello-world-setuppy/rust/main.rs From a0752521c50629c7ab061e54834f383adaa985d9 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 10:52:50 +0100 Subject: [PATCH 17/33] Avoid build isolation for test-crossenv in CI workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99bb21da..12ea0978 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -230,7 +230,7 @@ jobs: pip install build cffi -e ../../ export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG - python -m build + python -m build --no-isolation ls -la dist/ ' > build-wheels.sh From 27dd25d429acea8af3a9917917794e21d2b6dfae Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 11:13:03 +0100 Subject: [PATCH 18/33] Ensure cffi is installed in test-crossenv --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12ea0978..e77dd55f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,8 +226,8 @@ jobs: . venv/bin/activate build-pip install cffi wheel "setuptools>=62.4" cross-expose cffi - pip install wheel - pip install build cffi -e ../../ + pip install wheel build -e ../../ + pip install cffi export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG python -m build --no-isolation From 86748d38c12c28f8f0bc7cc55ec2d23c1c71cb99 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 11:16:32 +0100 Subject: [PATCH 19/33] List all contents of wheel to facilitate debugging --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e77dd55f..187c348f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -281,6 +281,7 @@ jobs: echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG python -m build --no-isolation ls -la dist/ + unzip -l dist/*.whl # debug all files inside wheel file - uses: uraimo/run-on-arch-action@v2.5.0 name: Install built wheel with: @@ -328,6 +329,7 @@ jobs: echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG python -m build --no-isolation ls -la dist/ + unzip -l dist/*.whl # debug all files inside wheel file - uses: uraimo/run-on-arch-action@v2.5.0 name: Install built wheel with: From 831918c195b10c6e07d9683b987e2d83561ec67f Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 15:52:36 +0100 Subject: [PATCH 20/33] Account for `bdist_wheel.plat_name` when given by config file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of sys.arg --- setuptools_rust/setuptools_ext.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setuptools_rust/setuptools_ext.py b/setuptools_rust/setuptools_ext.py index 0a5d16f8..6712bdaa 100644 --- a/setuptools_rust/setuptools_ext.py +++ b/setuptools_rust/setuptools_ext.py @@ -163,8 +163,9 @@ def run(self) -> None: build_rust.inplace = self.inplace build_rust.target = self.target build_rust.verbose = self.verbose - options = self.distribution.get_cmdline_options().get("bdist_wheel", {}) - plat_name = options.get("plat-name") or self.plat_name + + bdist_wheel = self.distribution.get_command_obj("bdist_wheel") + plat_name = bdist_wheel.plat_name or self.plat_name build_rust.plat_name = plat_name build_rust.run() From dc2607d0e2b58a42117b867d5ae8767ee77754c1 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 17:45:17 +0100 Subject: [PATCH 21/33] Account for possibility bdist_wheel is not installed --- setuptools_rust/setuptools_ext.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/setuptools_rust/setuptools_ext.py b/setuptools_rust/setuptools_ext.py index 6712bdaa..21c586b1 100644 --- a/setuptools_rust/setuptools_ext.py +++ b/setuptools_rust/setuptools_ext.py @@ -4,7 +4,7 @@ import sysconfig import logging -from typing import List, Set, Tuple, Type, TypeVar, cast +from typing import List, Optional, Set, Tuple, Type, TypeVar, cast from functools import partial from setuptools.command.build_ext import build_ext @@ -163,14 +163,18 @@ def run(self) -> None: build_rust.inplace = self.inplace build_rust.target = self.target build_rust.verbose = self.verbose - - bdist_wheel = self.distribution.get_command_obj("bdist_wheel") - plat_name = bdist_wheel.plat_name or self.plat_name - build_rust.plat_name = plat_name + build_rust.plat_name = self._get_wheel_plat_name() or self.plat_name build_rust.run() build_ext_base_class.run(self) + def _get_wheel_plat_name(self) -> Optional[str]: + try: + cmd = self.distribution.get_command_obj("bdist_wheel") + return cast(Optional[str], cmd.plat_name) + except Exception: # unlikely scenario: `wheel` not installed + return None + dist.cmdclass["build_ext"] = build_ext_rust_extension clean_base_class = dist.cmdclass.get("clean") From 8930627623f1ac639c3fa9221fae22cd400004ed Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 19:23:57 +0100 Subject: [PATCH 22/33] Use 'cross-pip wheel' for test-crossenv --- .github/workflows/ci.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 187c348f..8e363b44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -224,14 +224,20 @@ jobs: python3.9 -m pip install crossenv python3.9 -m crossenv "/opt/python/cp39-cp39/bin/python3" --cc $TARGET_CC --cxx $TARGET_CXX --sysroot $TARGET_SYSROOT --env LIBRARY_PATH= --manylinux manylinux1 venv . venv/bin/activate - build-pip install cffi wheel "setuptools>=62.4" + + build-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 + cross-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 + build-pip install cffi cross-expose cffi - pip install wheel build -e ../../ - pip install cffi + cross-pip install -e ../../ + cross-pip list + export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG - python -m build --no-isolation + + cross-pip wheel --no-build-isolation --no-deps --wheel-dir dist . ls -la dist/ + unzip -l dist/*.whl # debug all files inside wheel file ' > build-wheels.sh docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheels.sh From 71e28fd999fa89314fb36ad2d1dfe49baddbc4bb Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 19:45:59 +0100 Subject: [PATCH 23/33] Prefer build-system requires to setup_requires in rust_with_cffi --- examples/rust_with_cffi/pyproject.toml | 2 +- examples/rust_with_cffi/setup.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/rust_with_cffi/pyproject.toml b/examples/rust_with_cffi/pyproject.toml index 8619d878..4b5a004a 100644 --- a/examples/rust_with_cffi/pyproject.toml +++ b/examples/rust_with_cffi/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools-rust"] +requires = ["setuptools", "setuptools-rust", "cffi"] build-backend = "setuptools.build_meta" diff --git a/examples/rust_with_cffi/setup.py b/examples/rust_with_cffi/setup.py index 3a99f443..87c223ee 100644 --- a/examples/rust_with_cffi/setup.py +++ b/examples/rust_with_cffi/setup.py @@ -21,7 +21,6 @@ ], cffi_modules=["cffi_module.py:ffi"], install_requires=["cffi"], - setup_requires=["cffi"], include_package_data=True, zip_safe=False, ) From 634efa8b81bbf1921e4d673ecbda3017a1f31658 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 14 Aug 2023 20:26:31 +0100 Subject: [PATCH 24/33] Avoid using unzip in test-crossenv --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e363b44..d0e9a5c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,7 +237,7 @@ jobs: cross-pip wheel --no-build-isolation --no-deps --wheel-dir dist . ls -la dist/ - unzip -l dist/*.whl # debug all files inside wheel file + python -m zipfile -l dist/*.whl # debug all files inside wheel file ' > build-wheels.sh docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheels.sh From 745a781f712013068c0149aba38b0fad3a88ba3b Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 11:43:05 +0100 Subject: [PATCH 25/33] Add Cross.toml to namespace_package/MANIFEST.in --- examples/namespace_package/MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/namespace_package/MANIFEST.in b/examples/namespace_package/MANIFEST.in index 7c475173..f5c8d51c 100644 --- a/examples/namespace_package/MANIFEST.in +++ b/examples/namespace_package/MANIFEST.in @@ -1,3 +1,4 @@ include Cargo.toml +include Cross.toml recursive-include rust * recursive-include python * From 1d3d9219561e6c88da5c96879b42646aeb4c2035 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 13:24:25 +0100 Subject: [PATCH 26/33] Disable build isolation for cibuildwheel --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0e9a5c0..416e84fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -362,9 +362,13 @@ jobs: - uses: pypa/cibuildwheel@v2.3.1 env: CIBW_BUILD: cp39-* - CIBW_BEFORE_BUILD: pip install -e . + CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 -e . CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" CIBW_BUILD_VERBOSITY: 1 + CIBW_BUILD_FRONTEND: pip # pip allows disabling isolation via env var + CIBW_ENVIRONMENT: PIP_NO_BUILD_ISOLATION=false + # ^ -- necessary to use working copy of setuptools-rust, + # (however PIP_NO_BUILD_ISOLATION is counter-intuitive: see pypa/pip#5735) with: package-dir: examples/namespace_package From 085013b1abdfcdb7801bec2b093c20cc5ea343a0 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 20:56:53 +0100 Subject: [PATCH 27/33] Increase cibuildwheel verbosity for debugging --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416e84fa..8eebaa3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -362,9 +362,9 @@ jobs: - uses: pypa/cibuildwheel@v2.3.1 env: CIBW_BUILD: cp39-* - CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 -e . + CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 -e . && pip list CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" - CIBW_BUILD_VERBOSITY: 1 + CIBW_BUILD_VERBOSITY: 3 CIBW_BUILD_FRONTEND: pip # pip allows disabling isolation via env var CIBW_ENVIRONMENT: PIP_NO_BUILD_ISOLATION=false # ^ -- necessary to use working copy of setuptools-rust, From 023dc7b0479f23613214edbc42012005cef81d30 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 21:38:37 +0100 Subject: [PATCH 28/33] Do a 2 stage installation for cibuildwheel This attempts to fix the problem with old setuptools being used to install the working version of setuptools-rust --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eebaa3f..c89f0497 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -362,7 +362,7 @@ jobs: - uses: pypa/cibuildwheel@v2.3.1 env: CIBW_BUILD: cp39-* - CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 -e . && pip list + CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 && pip install -e . && pip list CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" CIBW_BUILD_VERBOSITY: 3 CIBW_BUILD_FRONTEND: pip # pip allows disabling isolation via env var From 81ec0b09b20154eee93857433693dbb5e145ce5e Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 22:25:12 +0100 Subject: [PATCH 29/33] Add workaround for auditwheel --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c89f0497..59ad8b9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -362,13 +362,15 @@ jobs: - uses: pypa/cibuildwheel@v2.3.1 env: CIBW_BUILD: cp39-* - CIBW_BEFORE_BUILD: pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1 && pip install -e . && pip list + CIBW_BEFORE_BUILD: pip install -U 'pip>=23.2.1' 'setuptools>=68.0.0' 'wheel<=0.37.1' && pip install -e . && pip list + # ^-- cap on `wheel` is a workaround for pypa/auditwheel#436 + # setuptools needs to be upgraded before installing setuptools-rust CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" CIBW_BUILD_VERBOSITY: 3 CIBW_BUILD_FRONTEND: pip # pip allows disabling isolation via env var CIBW_ENVIRONMENT: PIP_NO_BUILD_ISOLATION=false - # ^ -- necessary to use working copy of setuptools-rust, - # (however PIP_NO_BUILD_ISOLATION is counter-intuitive: see pypa/pip#5735) + # ^-- necessary to use working copy of setuptools-rust, + # (however PIP_NO_BUILD_ISOLATION is counter-intuitive: see pypa/pip#5735) with: package-dir: examples/namespace_package From e9b85ebf275c9e825e5db1dc606b7c061d9fecb0 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 15 Aug 2023 14:14:59 +0100 Subject: [PATCH 30/33] Reuse logic to get bdist_wheel command object --- setuptools_rust/build.py | 28 ++++++++++++++++++++++------ setuptools_rust/setuptools_ext.py | 8 +++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 72e40cb2..e954e53b 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -19,6 +19,8 @@ from typing import Dict, List, NamedTuple, Optional, Set, Tuple, cast import pkg_resources +from semantic_version import Version +from setuptools import Distribution from setuptools.command.build import build as CommandBuild from setuptools.command.build_ext import build_ext as CommandBuildExt from setuptools.command.build_ext import get_abi3_suffix @@ -36,6 +38,12 @@ logger = logging.getLogger(__name__) +try: + from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel +except ImportError: # wheel installation might be deferred in PEP 517 + from setuptools import Command as CommandBdistWheel + + def _check_cargo_supports_crate_type_option() -> bool: version = get_rust_version() @@ -468,17 +476,13 @@ def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str: return ext_path def _py_limited_api(self) -> _PyLimitedApi: - bdist_wheel = self.distribution.get_command_obj("bdist_wheel", create=False) + bdist_wheel = _get_bdist_wheel_cmd(self.distribution, create=False) if bdist_wheel is None: # wheel package is not installed, not building a limited-api wheel return False else: - from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel - - bdist_wheel_command = cast(CommandBdistWheel, bdist_wheel) # type: ignore[no-any-unimported] - bdist_wheel_command.ensure_finalized() - return cast(_PyLimitedApi, bdist_wheel_command.py_limited_api) + return cast(_PyLimitedApi, bdist_wheel.py_limited_api) def _detect_rust_target( self, forced_target_triple: Optional[str] = None @@ -773,3 +777,15 @@ def _replace_cross_target_dir(path: str, ext: RustExtension, *, quiet: bool) -> cross_target_dir = ext._metadata(cargo="cross", quiet=quiet)["target_directory"] local_target_dir = ext._metadata(cargo="cargo", quiet=quiet)["target_directory"] return path.replace(cross_target_dir, local_target_dir) + + +def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported] + dist: Distribution, + create: bool = True +) -> Optional[CommandBdistWheel]: + try: + cmd_obj = dist.get_command_obj("bdist_wheel", create=create) + cmd_obj.ensure_finalized() + return cast(CommandBdistWheel, cmd_obj) # type: ignore [no-any-unimported] + except Exception: + return None diff --git a/setuptools_rust/setuptools_ext.py b/setuptools_rust/setuptools_ext.py index 21c586b1..b59a7f52 100644 --- a/setuptools_rust/setuptools_ext.py +++ b/setuptools_rust/setuptools_ext.py @@ -16,6 +16,7 @@ from setuptools.dist import Distribution from typing_extensions import Literal +from .build import _get_bdist_wheel_cmd from .extension import Binding, RustBin, RustExtension, Strip try: @@ -169,11 +170,8 @@ def run(self) -> None: build_ext_base_class.run(self) def _get_wheel_plat_name(self) -> Optional[str]: - try: - cmd = self.distribution.get_command_obj("bdist_wheel") - return cast(Optional[str], cmd.plat_name) - except Exception: # unlikely scenario: `wheel` not installed - return None + cmd = _get_bdist_wheel_cmd(self.distribution) + return cast(Optional[str], getattr(cmd, "plat_name", None)) dist.cmdclass["build_ext"] = build_ext_rust_extension From 849cfb116960d863f9feddd0ce318171365ee25a Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 17 Aug 2023 09:48:41 +0100 Subject: [PATCH 31/33] Add CHANGELOG entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae6b7ffc..e9e84de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ ### Added - Add support for `pyproject.toml` configuration using `[tool.setuptools-rust]` options. [#348](https://github.com/PyO3/setuptools-rust/pull/348) +### Fixed +- Fix `plat_name` handling in the case `bdist_wheel.plat_name` is set via configuration file (e.g., `setup.cfg`). [#352](https://github.com/PyO3/setuptools-rust/pull/352) + ## 1.6.0 (2023-04-27) ### Changed - Prefer passing `--crate-type` option to cargo if "toolchain >= 1.64". [#322](https://github.com/PyO3/setuptools-rust/pull/322) From a808242dbaee620ad4235b43f9a8cb60bf81e005 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 18 Aug 2023 08:41:29 +0100 Subject: [PATCH 32/33] Fix linting problem --- setuptools_rust/build.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index e954e53b..c99cfd10 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -780,8 +780,7 @@ def _replace_cross_target_dir(path: str, ext: RustExtension, *, quiet: bool) -> def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported] - dist: Distribution, - create: bool = True + dist: Distribution, create: bool = True ) -> Optional[CommandBdistWheel]: try: cmd_obj = dist.get_command_obj("bdist_wheel", create=create) From 85df414f6d6762a3b64bac9172abeebeddbb1304 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 18 Aug 2023 08:45:26 +0100 Subject: [PATCH 33/33] Address type checker not dealing with try..except block --- setuptools_rust/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index c99cfd10..70365b01 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -784,7 +784,7 @@ def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported] ) -> Optional[CommandBdistWheel]: try: cmd_obj = dist.get_command_obj("bdist_wheel", create=create) - cmd_obj.ensure_finalized() - return cast(CommandBdistWheel, cmd_obj) # type: ignore [no-any-unimported] + cmd_obj.ensure_finalized() # type: ignore[union-attr] + return cast(CommandBdistWheel, cmd_obj) # type: ignore[no-any-unimported] except Exception: return None