2022-02-18 18:20:32 +00:00
|
|
|
use std::env;
|
2020-03-08 07:17:25 +00:00
|
|
|
|
2022-01-25 13:46:27 +00:00
|
|
|
use pyo3_build_config::pyo3_build_script_impl::{cargo_env_var, errors::Result};
|
2022-02-18 18:20:32 +00:00
|
|
|
use pyo3_build_config::{bail, print_feature_cfgs, InterpreterConfig};
|
2021-05-21 07:38:59 +00:00
|
|
|
|
2021-08-05 21:43:26 +00:00
|
|
|
fn ensure_auto_initialize_ok(interpreter_config: &InterpreterConfig) -> Result<()> {
|
2023-06-05 16:48:11 +00:00
|
|
|
if cargo_env_var("CARGO_FEATURE_AUTO_INITIALIZE").is_some() && !interpreter_config.shared {
|
|
|
|
bail!(
|
|
|
|
"The `auto-initialize` feature is enabled, but your python installation only supports \
|
|
|
|
embedding the Python interpreter statically. If you are attempting to run tests, or a \
|
|
|
|
binary which is okay to link dynamically, install a Python distribution which ships \
|
|
|
|
with the Python shared library.\n\
|
|
|
|
\n\
|
|
|
|
Embedding the Python interpreter statically does not yet have first-class support in \
|
|
|
|
PyO3. If you are sure you intend to do this, disable the `auto-initialize` feature.\n\
|
|
|
|
\n\
|
|
|
|
For more information, see \
|
|
|
|
https://pyo3.rs/v{pyo3_version}/\
|
|
|
|
building_and_distribution.html#embedding-python-in-rust",
|
|
|
|
pyo3_version = env::var("CARGO_PKG_VERSION").unwrap()
|
|
|
|
);
|
2021-08-05 21:43:26 +00:00
|
|
|
}
|
2021-05-21 07:38:59 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-08-05 21:43:26 +00:00
|
|
|
/// Prepares the PyO3 crate for compilation.
|
|
|
|
///
|
|
|
|
/// This loads the config from pyo3-build-config and then makes some additional checks to improve UX
|
|
|
|
/// for users.
|
2021-06-01 17:31:34 +00:00
|
|
|
///
|
2021-08-05 21:43:26 +00:00
|
|
|
/// Emits the cargo configuration based on this config as well as a few checks of the Rust compiler
|
|
|
|
/// version to enable features which aren't supported on MSRV.
|
2021-05-19 20:50:25 +00:00
|
|
|
fn configure_pyo3() -> Result<()> {
|
2022-01-25 13:46:27 +00:00
|
|
|
let interpreter_config = pyo3_build_config::get();
|
2021-08-14 18:10:53 +00:00
|
|
|
|
2021-05-21 07:38:59 +00:00
|
|
|
interpreter_config.emit_pyo3_cfgs();
|
2021-03-31 15:04:15 +00:00
|
|
|
|
2022-01-25 13:46:27 +00:00
|
|
|
ensure_auto_initialize_ok(interpreter_config)?;
|
2021-07-31 12:53:23 +00:00
|
|
|
|
2023-06-05 07:42:40 +00:00
|
|
|
// Emit cfgs like `thread_local_const_init`
|
2022-02-18 18:20:32 +00:00
|
|
|
print_feature_cfgs();
|
2021-07-31 12:53:23 +00:00
|
|
|
|
2020-12-30 23:45:03 +00:00
|
|
|
Ok(())
|
2017-06-11 23:35:24 +00:00
|
|
|
}
|
2017-05-13 05:05:00 +00:00
|
|
|
|
2021-03-29 07:37:27 +00:00
|
|
|
fn main() {
|
2021-04-24 09:52:58 +00:00
|
|
|
if let Err(e) = configure_pyo3() {
|
2021-08-04 11:54:45 +00:00
|
|
|
eprintln!("error: {}", e.report());
|
2021-03-29 07:37:27 +00:00
|
|
|
std::process::exit(1)
|
2021-04-24 09:52:58 +00:00
|
|
|
}
|
2021-03-29 07:37:27 +00:00
|
|
|
}
|