From 87b6a9bd927bcc1514f02c6b3860f0f99018ff7f Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 17 Dec 2022 11:32:56 +0000 Subject: [PATCH] ci: run pyo3-ffi-check using nox --- .github/workflows/build.yml | 8 ++---- Cargo.toml | 2 ++ noxfile.py | 47 ++++++++++++++++++++++++++++++--- pyo3-ffi-check/Cargo.toml | 9 ++----- pyo3-ffi-check/build.rs | 1 - pyo3-ffi-check/macro/Cargo.toml | 5 ++-- pyo3-ffi-check/macro/src/lib.rs | 4 +-- pyo3-ffi-check/src/main.rs | 9 ++++++- xtask/Cargo.toml | 1 + 9 files changed, 64 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15efcb64..43b7b11c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,17 +128,13 @@ jobs: - '.github/workflows/ci.yml' - '.github/workflows/build.yml' - - run: cargo doc -p pyo3-ffi - working-directory: pyo3-ffi-check - if: ${{ steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && inputs.python-version != 'pypy-3.7' && inputs.python-version != 'pypy-3.8' }} - - name: Run pyo3-ffi-check - run: cargo run - working-directory: pyo3-ffi-check + run: nox -s ffi-check # Allow failure on PyPy for now continue-on-error: ${{ startsWith(inputs.python-version, 'pypy') }} if: ${{ steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && inputs.python-version != 'pypy-3.7' && inputs.python-version != 'pypy-3.8' }} + - name: Test cross compilation if: ${{ inputs.os == 'ubuntu-latest' && inputs.python-version == '3.9' }} uses: PyO3/maturin-action@v1 diff --git a/Cargo.toml b/Cargo.toml index 1014e9f7..08b863db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -158,6 +158,8 @@ harness = false [workspace] members = [ "pyo3-ffi", + "pyo3-ffi-check", + "pyo3-ffi-check/macro", "pyo3-build-config", "pyo3-macros", "pyo3-macros-backend", diff --git a/noxfile.py b/noxfile.py index 0a0b0b73..dbaa2ef7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -111,6 +111,9 @@ def _clippy(session: nox.Session, *, env: Dict[str, str] = None) -> bool: *feature_set, "--all-targets", "--workspace", + # linting pyo3-ffi-check requires docs to have been built or + # the macros will error; doesn't seem worth it on CI + "--exclude=pyo3-ffi-check", *extra, external=True, env=env, @@ -404,9 +407,27 @@ def check_changelog(session: nox.Session): @nox.session(name="set-minimal-package-versions") def set_minimal_package_versions(session: nox.Session): + projects = ( + None, + "examples/decorator", + "examples/maturin-starter", + "examples/setuptools-rust-starter", + "examples/word-count", + ) + # run cargo update first to ensure that everything is at highest # possible version, so that this matches what CI will resolve to. - _run(session, "cargo", "update", external=True) + for project in projects: + if project is None: + _run(session, "cargo", "update", external=True) + else: + _run( + session, + "cargo", + "update", + f"--manifest-path={project}/Cargo.toml", + external=True, + ) _run_cargo_set_package_version(session, "indexmap", "1.6.2") _run_cargo_set_package_version(session, "hashbrown:0.12.3", "0.9.1") @@ -418,6 +439,9 @@ def set_minimal_package_versions(session: nox.Session): _run_cargo_set_package_version(session, "rayon", "1.5.3") _run_cargo_set_package_version(session, "rayon-core", "1.9.3") + # string_cache 0.8.4 depends on parking_lot 0.12 + _run_cargo_set_package_version(session, "string_cache:0.8.4", "0.8.3") + # 1.15.0 depends on hermit-abi 0.2.6 which has edition 2021 and breaks 1.48.0 _run_cargo_set_package_version(session, "num_cpus", "1.14.0") _run_cargo_set_package_version( @@ -433,7 +457,7 @@ def set_minimal_package_versions(session: nox.Session): ) for project in projects: _run_cargo_set_package_version( - session, "parking_lot", "0.11.0", project=project + session, "parking_lot:0.12.1", "0.11.0", project=project ) _run_cargo_set_package_version(session, "once_cell", "1.14.0", project=project) @@ -447,7 +471,24 @@ def set_minimal_package_versions(session: nox.Session): # As a smoke test, cargo metadata solves all dependencies, so # will break if any crates rely on cargo features not # supported on MSRV - _run(session, "cargo", "metadata", silent=True, external=True) + for project in projects: + if project is None: + _run(session, "cargo", "metadata", silent=True, external=True) + else: + _run( + session, + "cargo", + "metadata", + f"--manifest-path={project}/Cargo.toml", + silent=True, + external=True, + ) + + +@nox.session(name="ffi-check") +def ffi_check(session: nox.Session): + session.run("cargo", "doc", "-p", "pyo3-ffi", "--no-deps", external=True) + _run(session, "cargo", "run", "-p", "pyo3-ffi-check", external=True) @lru_cache() diff --git a/pyo3-ffi-check/Cargo.toml b/pyo3-ffi-check/Cargo.toml index e5594f5f..9808096b 100644 --- a/pyo3-ffi-check/Cargo.toml +++ b/pyo3-ffi-check/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pyo3-ffi-check" version = "0.1.0" -edition = "2021" +edition = "2018" publish = false [dependencies] @@ -10,12 +10,7 @@ memoffset = "0.7.0" [dependencies.pyo3-ffi] path = "../pyo3-ffi" -features = ["extension-module"] # A lazy way of skipping linking in most cases (as we don't use any runtime symbols) - -[workspace] -members = [ - "macro" -] +features = ["extension-module"] # A lazy way of skipping linking in most cases (as we don't use any runtime symbols) [build-dependencies] bindgen = "0.63.0" diff --git a/pyo3-ffi-check/build.rs b/pyo3-ffi-check/build.rs index 2d3e751b..ca4a17b6 100644 --- a/pyo3-ffi-check/build.rs +++ b/pyo3-ffi-check/build.rs @@ -10,7 +10,6 @@ fn main() { .expect("failed to get lib dir"); println!("cargo:rerun-if-changed=wrapper.h"); - dbg!(format!("-I{python_include_dir}")); let bindings = bindgen::Builder::default() .header("wrapper.h") diff --git a/pyo3-ffi-check/macro/Cargo.toml b/pyo3-ffi-check/macro/Cargo.toml index 7a73c424..a9f51f65 100644 --- a/pyo3-ffi-check/macro/Cargo.toml +++ b/pyo3-ffi-check/macro/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "pyo3-ffi-check-macro" version = "0.1.0" -edition = "2021" +edition = "2018" +publish = false [lib] proc-macro = true @@ -10,4 +11,4 @@ proc-macro = true glob = "0.3" quote = "1" proc-macro2 = "1" -scraper = "0.13" +scraper = "0.12" diff --git a/pyo3-ffi-check/macro/src/lib.rs b/pyo3-ffi-check/macro/src/lib.rs index 5c2af3c7..5d036062 100644 --- a/pyo3-ffi-check/macro/src/lib.rs +++ b/pyo3-ffi-check/macro/src/lib.rs @@ -19,7 +19,7 @@ pub fn for_all_structs(input: proc_macro::TokenStream) -> proc_macro::TokenStrea } }; - if !input.next().is_none() { + if input.next().is_some() { return quote!(compile_error!( "for_all_structs!() takes only a single ident as input" )) @@ -109,7 +109,7 @@ pub fn for_all_fields(input: proc_macro::TokenStream) -> proc_macro::TokenStream } }; - if !input.next().is_none() { + if input.next().is_some() { return quote!(compile_error!( "for_all_fields!() takes exactly two idents as input" )) diff --git a/pyo3-ffi-check/src/main.rs b/pyo3-ffi-check/src/main.rs index 6fdfea2e..c5373625 100644 --- a/pyo3-ffi-check/src/main.rs +++ b/pyo3-ffi-check/src/main.rs @@ -1,6 +1,13 @@ -use std::process::exit; +use std::{ffi::CStr, process::exit}; fn main() { + println!( + "comparing pyo3-ffi against headers generated for {}", + CStr::from_bytes_with_nul(bindings::PY_VERSION) + .unwrap() + .to_string_lossy() + ); + let mut failed = false; macro_rules! check_struct { diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index b3560ae1..48a5a63f 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -2,6 +2,7 @@ name = "xtask" version = "0.1.0" edition = "2018" +publish = false [[bin]] name = "xtask"