PyO3 / maturin

Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
https://maturin.rs
Apache License 2.0
3.85k stars 267 forks source link

--interpreter option recompiles pyo3 on every build #2256

Open sentialx opened 1 week ago

sentialx commented 1 week ago

Bug Description

Providing an --interpreter option causes recompilation of pyo3 on every build on Linux (Windows works fine).

Your maturin version (maturin --version)

1.7.4

Your Python version (python -V)

3.12

Your pip version (pip -V)

24.0

What bindings you're using

pyo3

Does cargo build work?

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

Steps to Reproduce

maturin build --release -o out --skip-auditwheel --interpreter python3.12

🔗 Found pyo3 bindings
⚠️  Warning: Failed to determine python platform
🐍 Found CPython 3.12
warning: unused manifest key: lib.version
   Compiling pyo3-build-config v0.22.5
   Compiling pyo3-ffi v0.22.5
   Compiling pyo3-macros-backend v0.22.5
   Compiling pyo3 v0.22.5
   Compiling pyo3-macros v0.22.5
   Compiling user_lib v0.0.1 (/usr/src/app)
    Finished `release` profile [optimized] target(s) in 3.54s
📦 Built wheel for CPython 3.12 to pace/builder/build_env/user_lib-0.0.1-cp312-cp312-linux_aarch64.whl
3
2024-10-16T12:53:38.985362Z DEBUG into_build_context: maturin::project_layout: Using cargo manifest path from working directory: "/usr/src/app/Cargo.toml"
2024-10-16T12:53:38.985435Z DEBUG into_build_context:resolve_cargo_metadata: maturin::project_layout: Resolving cargo metadata from "/usr/src/app/Cargo.toml"
🔗 Found pyo3 bindings
2024-10-16T12:53:39.013722Z  INFO into_build_context:resolve_cargo_metadata: maturin::project_layout: close time.busy=28.3ms time.idle=625ns
2024-10-16T12:53:39.013760Z DEBUG into_build_context: maturin::project_layout: Project layout resolved project_root=/usr/src/app python_dir=/usr/src/app rust_module=/usr/src/app/user_lib python_module=/usr/src/app/user_lib extension_name=user_lib module_name=user_lib
⚠️  Warning: Failed to determine python platform
🐍 Found CPython 3.12
2024-10-16T12:53:39.037871Z  INFO into_build_context:check_executable: maturin::python_interpreter: close time.busy=202µs time.idle=1.83µs executable=python3.12
2024-10-16T12:53:39.037895Z DEBUG into_build_context: maturin::build_options: Found CPython 3.12 in bundled sysconfig
2024-10-16T12:53:39.037908Z  INFO into_build_context: maturin::build_options: close time.busy=52.6ms time.idle=1.50µs
2024-10-16T12:53:39.037942Z DEBUG build_wheels: maturin::compile: Setting crate_type to cdylib for Rust >= 1.64.0
2024-10-16T12:53:39.038111Z DEBUG build_wheels: maturin::compile: Running env -u CARGO PYO3_CONFIG_FILE="/usr/src/app/target/maturin/pyo3-config-aarch64-unknown-linux-gnu-3.12.txt" "cargo" "rustc" "--message-format" "json-render-diagnostics" "--manifest-path" "/usr/src/app/Cargo.toml" "--release" "--lib" "--crate-type" "cdylib"
warning: unused manifest key: lib.version
   Compiling pyo3-build-config v0.22.5
   Compiling pyo3-ffi v0.22.5
   Compiling pyo3-macros-backend v0.22.5
   Compiling pyo3 v0.22.5
   Compiling pyo3-macros v0.22.5
   Compiling user_lib v0.0.1 (/usr/src/app)
    Finished `release` profile [optimized] target(s) in 3.77s
2024-10-16T12:53:42.835314Z  INFO build_wheels:warn_missing_py_init: maturin::compile: close time.busy=410µs time.idle=1.42µs
2024-10-16T12:53:42.836781Z DEBUG build_wheels: maturin::module_writer: Adding user_lib-0.0.1.dist-info/METADATA
2024-10-16T12:53:42.836838Z DEBUG build_wheels: maturin::module_writer: Adding user_lib-0.0.1.dist-info/WHEEL
2024-10-16T12:53:42.836886Z DEBUG build_wheels:write_bindings_module: maturin::module_writer: Adding user_lib/__init__.py
2024-10-16T12:53:42.836934Z DEBUG build_wheels:write_bindings_module: maturin::module_writer: Adding user_lib/user_lib.cpython-312-aarch64-linux-gnu.so from /usr/src/app/target/release/libuser_lib.so
2024-10-16T12:53:42.852572Z  INFO build_wheels:write_bindings_module: maturin::module_writer: close time.busy=15.7ms time.idle=916ns
2024-10-16T12:53:42.852591Z DEBUG build_wheels: maturin::module_writer: Adding user_lib-0.0.1.dist-info/RECORD
2024-10-16T12:53:42.852821Z  INFO build_wheels: maturin::build_context: close time.busy=3.81s time.idle=750ns
messense commented 1 week ago

This should be easy to fix, just need to skip writing the pyo3 config file if it's already up-to-date to avoid changing file modification time:

https://github.com/PyO3/maturin/blob/8cf2e152179d39169225e1dbb8854aac9b6ba822/src/compile.rs#L418

Pull requests are welcome.

kliwongan commented 4 days ago

Can I try this one?

konstin commented 4 days ago

sure!