Commit Graph

167 Commits

Author SHA1 Message Date
messense f8e2a26439
Warn about unknown config keys in `PYO3_CONFIG_FILE` 2023-01-29 10:49:27 +08:00
David Hewitt 224a4160b4 release: 0.18.0 2023-01-17 19:04:30 +00:00
messense 7e89456c77
Remove `libpython.so` from cross compile error message 2023-01-05 17:07:21 +08:00
David Hewitt f2608a923c remove functionality deprecated in 0.16 2022-12-28 12:23:53 +00:00
David Hewitt 97487ffbb5 add abi3-py311 feature 2022-11-23 08:08:12 +00:00
messense dee791de90
`pyo3-build-config`: rebuild when `PYO3_ENVIRONMENT_SIGNATURE` value changed 2022-11-09 20:28:18 +08:00
David Hewitt 548e90fcec release: 0.17.3 2022-11-01 20:47:46 +00:00
David Hewitt bd40011e93 release: 0.17.2 2022-10-04 08:13:53 +01:00
David Hewitt 8102ad1a1b rust: updates for 1.64 2022-09-22 21:03:34 +02:00
David Hewitt caaf7bbda7 release: 0.17.1 2022-08-28 08:27:56 +01:00
David Hewitt 04c1ac87f1 release: 0.17.0 2022-08-23 21:21:19 +01:00
Sergey Kvachonok 97eaa77db8 docs: Update the guide for `python3-dll-a` v0.2.6
Bump the minimum `python3-dll-a` dependency version.

Document the implemented workaround for
https://github.com/PyO3/python3-dll-a/issues/28
2022-08-21 14:33:52 +03:00
David Hewitt 49246bec45 pyo3-build-config: add link args for wasm32-unknown-emscripten 2022-08-06 08:05:45 +01:00
David Hewitt 209c942277 pyfunction: use extract_argument with holder to avoid extractext 2022-07-14 08:42:22 +01:00
messense dfe223619a
Add support for generating PyPy Windows import library 2022-07-14 14:22:33 +08:00
David Hewitt c4a2c6c912 clippy: fix some warnings from beta toolchain 2022-07-12 23:02:47 +01:00
Bruno Kolenbrander 58d4ba833e
Rust 1.62 (#2489)
* Rust 1.62

* Make rust happy

* Just use a doctest instead

Co-authored-by: mejrs <>
2022-07-02 16:08:01 +01:00
messense 2bd24565c4
Rename `fixup_import_libs` to `generate_import_libs` 2022-05-28 15:07:10 +08:00
messense 4787ad75c9
Add a `default_lib_name_for_target` function 2022-05-28 14:59:10 +08:00
messense 4986d8ee7f
Fixup `lib_name` when using `PYO3_CONFIG_FILE` 2022-05-28 13:58:54 +08:00
David Hewitt 3dcbcb7a95 update main to reflect 0.16.5 release 2022-05-15 20:31:00 +01:00
messense ded0d9fc93
Allow false positive `clippy::unnecessary-wraps` lint 2022-05-14 20:45:03 +08:00
messense 742774cdb5
Auto generate Windows import libraries when using a pyo3 config file 2022-05-14 20:45:02 +08:00
messense df6e9bcdb2
Change default python lib name for Windows when cross compiling
Stop treating `gnu` abi as mingw by default.
2022-05-12 14:32:21 +08:00
messense c477718fe7
Add support for generating non-abi3 python import libraries for Windows
targets
2022-05-12 14:32:20 +08:00
messense 10cb5a1f95
pyo3-build-config: switch to `python3_dll_a::ImportLibraryGenerator` 2022-05-12 14:32:17 +08:00
Adam Reichold d2caa056e9 release: 0.16.4 2022-04-14 07:56:42 +01:00
David Hewitt 8cd551fdfc
Merge pull request #2293 from ravenexp/abi3-no-python
pyo3-build-config: Build "abi3" extensions without an interpreter
2022-04-14 07:55:53 +01:00
Sergey Kvachonok ae7e1f5ee9 pyo3-build-config: Build "abi3" extensions without an interpreter
Support compiling portable "abi3" extension modules even when
the build host Python interpreter configuration is not available
or the discovered Python interpreter version is not supported.

Maturin already implements this by building "abi3" extension wheels
with `PYO3_NO_PYTHON` environment veriable set for cargo when
an `abi3-py3*` feature is detected.

Closes #2292
2022-04-13 10:40:08 +03:00
Adam Reichold 58b7081274 Use more robust hexadecimal escaping of interpreter configuration. 2022-04-12 20:53:03 +02:00
Sergey Kvachonok 479fe6781f pyo3-build-config: Add `python3-dll-a` crate support
Automatically generate `python3.dll` import libraries for Windows
compile targets in the build script.

Adds a new PyO3 crate feature `generate-abi3-import-lib` enabling
automatic import library generation.

Closes #2231
2022-04-10 16:45:32 +03:00
Sergey Kvachonok 8f9976ad33 pyo3-build-config: Use "m" ABI tag for libpython-3.7 by default
According to https://bugs.python.org/issue36707, this tag is useless
since version 3.4, but also the default until version 3.8.

For example, Debian 10 ships `libpython3.7m.so`.
2022-04-09 13:28:44 +03:00
Sergey Kvachonok 29476b0d0d pyo3-build-config: Inline the `PYO3_NO_PYTHON` switch
This patch folds the `PYO3_NO_PYTHON` + `abi3` special case into
the existing native and cross compilation code paths.

The cross compilation route is now guaranteed to behave the same
whether `PYO3_NO_PYTHON` is set or not (except for sysconfigdata
discovery for the Unix targets).

The native compilation route now stores the hardcoded abi3 interpreter
configuration in place of the discovered configuration blob.
2022-04-05 17:19:49 +03:00
David Hewitt 1ae0971a09 release: 0.16.3 2022-04-05 04:05:57 +01:00
Sergey Kvachonok 80675361f4 pyo3-build-config: Add `PYO3_CROSS_PYTHON_IMPLEMENTATION` env var
Adds a new cross-compile target interpreter configuration
environment variable.

This feature allows PyO3 to target PyPy on both Windows and Unix
cross compile targets.
2022-04-04 15:23:11 +03:00
Sergey Kvachonok ccda497e04 pyo3-build-config: Create per-target cross config files
Rename `$OUT_DIR/pyo3-cross-compile-config.txt` to
`$OUT_DIR/<triple>/pyo3-build-config.txt` to exclude the possibility
of using stale build configuration data when the build target changes.

Use the presence of the corresponding build configuration file
in the `pyo3-build-config` build script output directory
to detect whether we are cross compiling or not.

This patch enables cross compilation without using
any of `PYO3_CROSS_*` env variables in many cases.
2022-04-01 11:32:46 +03:00
Sergey Kvachonok 328e7d69f6 pyo3-build-config: Try "default" cross-compilation
Try to generalize `windows_hardcoded_cross_compile()`
to all supported target platforms (when possible).
Rename it to `default_cross_compile()` and add some unit tests.

Rewrite `load_cross_compile_config()` to fall back to
the default interpreter configuration when no other config
information sources are available.
2022-04-01 11:32:46 +03:00
Sergey Kvachonok 54ae025722 pyo3-build-config: Make `lib_dir` optional in `CrossCompileConfig`
Change the `CrossCompileConfig` structure definition and make
the public `lib_dir` field optional to support more flexible
cross-compilation configuration in the future.

FIXME: This change breaks the public `pyo3-build-config` crate API.

Update the sysconfigdata extraction functions to fall through
when `lib_dir` field is not set.

WIP: Add `unwrap()` stubs to the main cross compile switch.
2022-04-01 11:32:46 +03:00
Sergey Kvachonok 9b45a19161 pyo3-build-config: Replace `TargetInfo` with `target_lexicon::Triple`
Add a new public crate function `cross_compile_from_to()` using
`target_lexicon::Triple` arguments instead of plain strings
used in `cross_compile()`.

Deprecate `pyo3_build_config::cross_compile()` since v0.17.

Attempt to extract common code patterns into methods and standalone
helper functions. Add docstrings to the new private items.
Make some of the new helper functions public within the PyO3 crate
and reuse them in the build scripts.

Add PYO3_CROSS_PYTHON_VERSION parsing unit test.

Add a ChangeLog entry mentioning the new `pyo3-build-config` API.
2022-04-01 09:36:49 +03:00
David Hewitt 16ee22c7cc
Merge pull request #2244 from mejrs/lint-more
Add more lints
2022-03-23 13:40:35 +00:00
mejrs 00ea040834 Feedback 2022-03-23 13:30:32 +01:00
David Hewitt 2813c87eaf
Merge pull request #2092 from aganders3/export-conf
Add export-config feature to pyo3-build-config
2022-03-23 11:16:04 +00:00
Sergey Kvachonok 5237000317 pyo3-build-config: Fix `abi3-py310` feature
Fix `abi3-py310` feature: use Python 3.10 ABI when available
instead of silently falling back to the 3.9 ABI.
2022-03-23 09:45:25 +03:00
Ashley Anderson 4a62a62cae Improvements based on code review: API and documentation. 2022-03-21 12:55:39 -04:00
Ashley Anderson bbe7a493d6 Refactor to serialize the whole InterpreterConfig into DEP_PYTHON_PYO3_CONFIG 2022-03-17 12:10:38 -04:00
Ashley Anderson bc356f23e0 Fix coverage for pyo3-build-config CI ("full" feature) 2022-03-17 11:20:37 -04:00
Ashley Anderson 161d79fae3 Fix test for MSRV 2022-03-17 11:20:37 -04:00
Ashley Anderson 14bd6282ad Add test for export-config round trip. 2022-03-17 11:20:37 -04:00
Ashley Anderson 04b8652612 Fix test on windows (line ending mismatch). 2022-03-17 11:20:37 -04:00
Ashley Anderson ef4b91256d Add tests for run_python_script*. 2022-03-17 11:20:36 -04:00
Ashley Anderson cb3effdb96 Additon conditional compilation for InterpreterConfig::from_pyo3_export_config 2022-03-17 11:19:27 -04:00
Ashley Anderson 755bf97fdb Add export-config feature to pyo3-build-config. 2022-03-17 11:19:27 -04:00
Kevin Phillips 34ff72f6ba Added a test for PYTHONFRAMEWORK 2022-03-17 08:41:26 +01:00
Kevin Phillips 13f13e5ee1 pyo3-build-config: Change for from_sysconfigdata to set the shared property based on PYTHONFRAMEWORK in addition to Py_ENABLE_SHARED in order that a macos Framework build is considered shared just like the logic in from_interpreter 2022-03-17 07:42:29 +01:00
David Hewitt 52d2c78ae1 pyo3-build-config: fix windows "cross-compile" panic 2022-03-16 13:22:00 +01:00
Adam Reichold 922bbfc92d release: 0.16.2 2022-03-15 19:20:00 +01:00
David Hewitt 7056bae21f release: 0.16.1 2022-03-05 16:21:44 +00:00
messense afe5221724
Fix cross compiling to aarch64 macOS 2022-03-04 17:22:50 +08:00
David Hewitt 6fda258f01
Merge pull request #2198 from PanQL/fix-interpreter-script
use platform.system to check if it is on windows
2022-03-03 09:05:02 +00:00
David Hewitt 5f39e483c5
Merge pull request #2196 from davidhewitt/more-clippy
clippy: enable some more lints
2022-03-03 08:58:41 +00:00
David Hewitt ddf13ea98f clippy: enable some more lints 2022-03-03 07:23:28 +00:00
Adam Reichold 12be3f219d Enable the resolve-config feature of pyo3-build-config on docs.rs to make the dependent functionality visible. 2022-03-01 10:31:38 +01:00
PanQL 5ac495e547 use platform.system to check if it is on windows 2022-03-01 17:26:19 +08:00
David Hewitt 4c434a21bd release: 0.16.0 2022-02-27 20:28:51 +00:00
David Hewitt efbf92bd52 pypy: don't allow abi to be adjusted by abi3 flag 2022-02-25 07:28:54 +00:00
David Hewitt f3df59c76b pypy: include minor version in library on Python 3.9 2022-02-25 07:28:22 +00:00
mejrs f346d1c86f Move emitting cfgs to pyo3-build-config 2022-02-18 19:20:32 +01:00
Ashley Anderson c30ca03b60
Expose cross compiling configuration from pyo3-build-config (#1996)
* Initial refactor - expose cross-compiling functions and add necessary fields to InterpreterConfig

* Refactor cross_compiling to take arch/vendor/os separately.

* Address review comments.

* Update changelog with note about pyo3-build-config APIs.

* Fix panic when parsing ABI tag on Windows.

* Update parse_sysconfigdata test to best-guess values for linux.

* Revert added fields in InterpreterConfig.

* Refactor parse_sysconfigdata to return Sysconfigdata (HashMap). Add InterpreterConfig::from_sysconfigdata.

* Update BuildFlags test to use from_sysconfigdata.

* Add tests for from_sysconfigdata. Refactor Sysconfigdata API to be more open.

* Add basic tests for not cross compiling. Add some error handling.

* Address review comments.

* Update search_lib_dir to recurse into lib and pypy dirs.

* Look even harder for sysconfigdata.

* Add skip-build-config feature.

* Revert skip-build-config feature.

* Suppress cargo:rerun-if-env-changed without resolve-config feature.
2021-12-16 00:18:37 +00:00
David Hewitt a5ef9ff64a ci: clippy whole workspace 2021-12-09 08:11:28 +00:00
Georg Brandl 9990bf9d31 Fix some clippy and dead code warnings. 2021-11-24 09:11:39 +01:00
David Hewitt 70030f130d python: drop support for 3.6 2021-11-20 13:02:42 +00:00
David Hewitt b9cc10f3fb pyo3-build-config: don't enable resolve-config by default 2021-11-19 14:19:24 +00:00
David Hewitt eb5059acc7 release: 0.15.1 2021-11-18 07:34:22 +00:00
messense f01595163c Don't link to python3.lib for PyPy on Windows 2021-11-15 15:40:29 +08:00
messense 73c3911748 Don't emit `Py_LIMITED_API` cfg for PyPy 2021-11-15 15:40:27 +08:00
messense 2325c283b0 Fix mingw platform detection 2021-11-15 15:15:16 +08:00
David Hewitt 47747444c7 release: 0.15.0 2021-11-03 23:00:38 +00:00
Giovanni Barillari c06058888f review sysconfigdata filename match rules to support cp37m 2021-10-12 23:41:26 +01:00
David Hewitt a5d0aa777c py310: add abi3-py310 feature 2021-09-26 16:21:35 +01:00
Sergey Kvachonok 2f74ab0d23 build-config: Always pass `abi3` flag to `default_lib_name_windows()`
Hardcoding `false` here leads to an incorrect abi3 DLL name
when cross-compiling to Windows.
2021-09-22 07:30:21 +01:00
David Hewitt 097d7e09cb pyo3-build-config: fix location for conda interpreter on windows 2021-09-16 23:38:46 +01:00
David Hewitt dca02a92ce changelog: updates for 0.14.5 backports 2021-09-05 15:19:36 +01:00
Gregory Szorc 3957afc9c5 pyo3-build-config: conditionalize symbols on resolve-config feature
PR #1856 was buggy in that the `pyo3-build-config` crate didn't actually
work in library mode because `include_str!()` was attempting to resolve
missing files as part of populating some `const` values.

We could change the logic of these constants to make them lazy if
we wanted to support possibly getting access to the value. But the
simple solution is to conditionalize their presence on the crate
feature.

Test coverage for building and testing the crate in insolation with the
feature disabled has been added.

Various code has been conditionalized to avoid compiler warnings.

Also, it appears `cargo build|test -p pyo3-build-config
--no-default-features` still passes default features. This seems wrong
to me. But it is how my system behaves. Maybe it is an sccache bug?
I coded the new tests to `cd pyo3-build-config` first to work around.
2021-09-02 17:18:55 -07:00
Gregory Szorc 1e951d5d8b pyo3-build-config: add a crate feature to control build script
I have a use case in PyOxidizer where I want to use the
pyo3-build-config crate as a library crate so I can access the
`InterpreterConfig` struct so I can read/write config files without
reinventing the wheel.

This is doable before this commit. But it requires that the
build environment have a Python interpreter. This is undesirable
for library usage.

This commit introduces a cargo feature flag to control whether the
build script does anything. The feature flag must be present for
the build script to resolve a config. The feature flag is enabled
by default for backwards compatibility. The pyo3 and pyo3-macros-backend
crates use this feature by default, for backwards compatibility and
because it is the reasonable default.

This is probably room to conditionalize some APIs and other behavior
based on this feature flag. But we stop short of doing that for
the time being.
2021-09-01 19:44:54 -07:00
David Hewitt 7d40461dcf
Merge pull request #1847 from davidhewitt/test-parse-sysconfigdata
pyo3-build-config: add test for parsing sysconfigdata
2021-09-01 08:50:29 +01:00
Gregory Szorc 05815bf861 pyo3-build-config: derive Clone on BuildFlags
This isn't strictly necessary since you can `.0.clone()`. But it is
more ergonomic.
2021-08-31 18:47:58 -07:00
David Hewitt 4a6ea17959 pyo3-build-config: add test for parsing sysconfigdata 2021-08-31 22:29:02 +01:00
David Hewitt 5e8d43c8bd
Merge pull request #1848 from indygreg/public-interpreter-config
pyo3-build-config: make InterpreterConfig public
2021-08-31 22:21:28 +01:00
Gregory Szorc c9c606f7c6 build: enable suppression of `cargo:rustc-link-*` lines
PyOxidizer requires advanced control over the settings used to link
libpython. We recently implemented support for configuration files
defining explicit lines to emit from build scripts to give callers
control over what lines to emit from build scripts so use cases
like PyOxidizer's are feasible without hacks in PyO3's code base.

However, the default logic in `emit_link_config()` may not be
appropriate in scenarios where link settings are provided via this
"extra lines" mechanism. The default logic may prohibit use of or
interfere with desired settings provided externally.

This commit defines a new field on the interpreter config that
suppresses the emission of the default link control logic from the
`pyo3` build script. It effectively gives advanced consumers like
PyOxidizer full control over link logic while minimally polluting
PyO3's build logic.

I thought about implementing this control as a crate feature. But
given the expected target audience size of ~1, I thought a crate
feature was too visible for a power user feature and decided to
implement it via the configuration file.
2021-08-30 10:01:36 -07:00
Gregory Szorc 04c77e35c5 build: support emitting arbitrary lines from pyo3 build script
PyOxidizer needs to do some... questionable things with regards to
configuring how the Python interpreter is linked. The way I solved this
problem for the `cpython` / `python3-sys` crates was by adding a bunch
of crate features to control what `cargo:` lines were emitted by the
build scripts. This added a lot of complexity to the those crates for
a target audience of ~1.

Now that PyO3 has support for config files to control settings, this
provides a richer mechanism than crate features to influence the build
script.

This commit defines a new field on the `InterpreterConfig` struct to
hold an arbitrary list of strings/lines that should be emitted by
the build script. This field is only every populated when parsing config
files and it is only read by pyo3's build script to `println!()`
additional values.

My intended use case for this is to have PyOxidizer effectively control
the interpreter link settings via the config file (at my own peril)
while having minimal impact on the maintainability of PyO3's code base.
Given the complexity of the link hacks employed, you probably don't want
this polluting pyo3's code base.
2021-08-30 09:52:11 -07:00
Gregory Szorc 62e134242d pyo3-build-config: make interpreter config and references types public
PyOxidizer will want to create interpreter config files. Rather
than reinvent the logic for reading/writing these files, I think
it makes sense to consume the `pyo3-build-config` crate so we can
use the `InterpreterConfig` type directly. But the symbol needs
to be public to allow us to do that. And in order to allow direct
construction, we need to make all the types referenced by its fields
public as well.
2021-08-30 09:45:37 -07:00
David Hewitt 5119bad580 changelog: updates for 0.14.4 2021-08-29 08:07:44 +01:00
David Hewitt bc1a983371 changelog: update for 0.14.3 release 2021-08-22 01:25:29 +01:00
Gregory Szorc 736b03b8cc build: document InterpreterConfig fields
I'm building functionality on top of this config and figured I'd
take the time to document the fields to make things easier to
understand.
2021-08-21 12:47:20 -07:00
David Hewitt 1873264b7d release: 0.14.2 2021-08-09 07:58:31 +01:00
Dean Li 1086fdb965
fix compiler warning
Fix issue [link](https://github.com/rust-lang/rust/issues/79813) which
will eventually deny trailing semicolons in expression macro in rust compiler.
2021-08-07 16:31:54 +08:00
David Hewitt 5af835daed pyo3-build-config: fix build for windows gnu targets 2021-08-07 00:25:14 +01:00
David Hewitt 2cf2c2fef9 pyo3-build-config: improve test coverage
[review] birkenfeld

Co-authored-by: Georg Brandl <georg@python.org>
2021-08-06 12:55:03 +01:00
David Hewitt 49387e9a70 pyo3-build-config: many tidy ups 2021-08-05 23:19:43 +01:00
David Hewitt 9507979d93
pyo3-build-config: inline config when not cross compiling 2021-08-04 12:54:45 +01:00