| 1 | use pyo3_build_configrust-analyzer cargo pyo3-build-config 0.28.2 crate/::{ |
| 2 | bailrust-analyzer cargo pyo3-build-config 0.28.2 errors/bail!, ensurerust-analyzer cargo pyo3-build-config 0.28.2 errors/ensure!, print_feature_cfgsrust-analyzer cargo pyo3-build-config 0.28.2 print_feature_cfgs()., |
| 3 | pyo3_build_script_implrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/::{ |
| 4 | cargo_env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/cargo_env_var()., env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/env_var()., errorsrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/errors/::Resultrust-analyzer cargo pyo3-build-config 0.28.2 errors/Result#, is_linking_libpython_for_targetrust-analyzer cargo pyo3-build-config 0.28.2 impl_/is_linking_libpython_for_target()., |
| 5 | resolve_build_configrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/resolve_build_config()., target_triple_from_envrust-analyzer cargo pyo3-build-config 0.28.2 impl_/target_triple_from_env()., BuildConfigrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfig#, BuildConfigSourcerust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfigSource#, |
| 6 | InterpreterConfigrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#, MaximumVersionExceededrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/MaximumVersionExceeded#, PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#, |
| 7 | }, |
| 8 | warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!, PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#, |
| 9 | }; |
| 10 | |
| 11 | /// Minimum Python version PyO3 supports. |
| 12 | struct SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# { |
| 13 | minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#, |
| 14 | maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#, |
| 15 | } |
| 16 | |
| 17 | const SUPPORTED_VERSIONS_CPYTHONrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_CPYTHON.: SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# = SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# { |
| 18 | minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion# { majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major.: 3, minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor.: 7 }, |
| 19 | maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion# { |
| 20 | majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major.: 3, |
| 21 | minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor.: 14, |
| 22 | }, |
| 23 | }; |
| 24 | |
| 25 | const SUPPORTED_VERSIONS_PYPYrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_PYPY.: SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# = SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# { |
| 26 | minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion# { |
| 27 | majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major.: 3, |
| 28 | minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor.: 11, |
| 29 | }, |
| 30 | maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.: SUPPORTED_VERSIONS_CPYTHONrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_CPYTHON..maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max., |
| 31 | }; |
| 32 | |
| 33 | const SUPPORTED_VERSIONS_GRAALPYrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_GRAALPY.: SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# = SupportedVersionsrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions# { |
| 34 | minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min.: PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion# { |
| 35 | majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major.: 3, |
| 36 | minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor.: 10, |
| 37 | }, |
| 38 | maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.: SUPPORTED_VERSIONS_CPYTHONrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_CPYTHON..maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max., |
| 39 | }; |
| 40 | |
| 41 | fn ensure_python_versionrust-analyzer cargo pyo3-ffi 0.28.2 ensure_python_version().(interpreter_config: &InterpreterConfigrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#) -> Resultrust-analyzer cargo pyo3-build-config 0.28.2 errors/Result#<()> { |
| 42 | // This is an undocumented env var which is only really intended to be used in CI / for testing |
| 43 | // and development. |
| 44 | if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("UNSAFE_PYO3_SKIP_VERSION_CHECK").as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_deref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#("1") { |
| 45 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 46 | } |
| 47 | |
| 48 | match interpreter_config.implementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#implementation. { |
| 49 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::CPythonrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#CPython# => { |
| 50 | let versions = SUPPORTED_VERSIONS_CPYTHONrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_CPYTHON.; |
| 51 | ensurerust-analyzer cargo pyo3-build-config 0.28.2 errors/ensure!!( |
| 52 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. >= versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 53 | "the configured Python interpreter version ({}) is lower than PyO3's minimum supported version ({})", |
| 54 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version., |
| 55 | versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 56 | ); |
| 57 | let v_plus_1 = PythonVersionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion# { |
| 58 | majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major.: versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max..majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major., |
| 59 | minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor.: versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max..minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().1, |
| 60 | }; |
| 61 | if interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. rust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[PythonVersion][`PartialEq<Self>`]eq().==rust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[PythonVersion][`PartialEq<Self>`]eq(). rust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[PythonVersion][`PartialEq<Self>`]eq().v_plus_1 { |
| 62 | warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!!( |
| 63 | "Using experimental support for the Python {}.{} ABI. \ |
| 64 | Build artifacts may not be compatible with the final release of CPython, \ |
| 65 | so do not distribute them.", |
| 66 | v_plus_1.majorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#major., v_plus_1.minorrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonVersion#minor., |
| 67 | ); |
| 68 | } else if interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().v_plus_1 { |
| 69 | let mut error = MaximumVersionExceededrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/MaximumVersionExceeded#::newrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]new().(interpreter_config, versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.); |
| 70 | if interpreter_config.is_free_threadedrust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[InterpreterConfig]is_free_threaded().() { |
| 71 | error.add_helprust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]add_help().( |
| 72 | "the free-threaded build of CPython does not support the limited API so this check cannot be suppressed.", |
| 73 | ); |
| 74 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.finishrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]finish().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 75 | } |
| 76 | |
| 77 | if env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/env_var().("PYO3_USE_ABI3_FORWARD_COMPATIBILITY").is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(|os_str| os_str rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne()."1") |
| 78 | { |
| 79 | error.add_helprust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]add_help().("set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this check and build anyway using the stable ABI"); |
| 80 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.finishrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]finish().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::PyPyrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#PyPy# => { |
| 85 | let versions = SUPPORTED_VERSIONS_PYPYrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_PYPY.; |
| 86 | ensurerust-analyzer cargo pyo3-build-config 0.28.2 errors/ensure!!( |
| 87 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. >= versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 88 | "the configured PyPy interpreter version ({}) is lower than PyO3's minimum supported version ({})", |
| 89 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version., |
| 90 | versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 91 | ); |
| 92 | // PyO3 does not support abi3, so we cannot offer forward compatibility |
| 93 | if interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max. { |
| 94 | let error = MaximumVersionExceededrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/MaximumVersionExceeded#::newrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]new().(interpreter_config, versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.); |
| 95 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.finishrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]finish().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 96 | } |
| 97 | } |
| 98 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::GraalPyrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#GraalPy# => { |
| 99 | let versions = SUPPORTED_VERSIONS_GRAALPYrust-analyzer cargo pyo3-ffi 0.28.2 SUPPORTED_VERSIONS_GRAALPY.; |
| 100 | ensurerust-analyzer cargo pyo3-build-config 0.28.2 errors/ensure!!( |
| 101 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. >= versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 102 | "the configured GraalPy interpreter version ({}) is lower than PyO3's minimum supported version ({})", |
| 103 | interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version., |
| 104 | versions.minrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#min., |
| 105 | ); |
| 106 | // GraalPy does not support abi3, so we cannot offer forward compatibility |
| 107 | if interpreter_config.versionrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#version. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max. { |
| 108 | let error = MaximumVersionExceededrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/MaximumVersionExceeded#::newrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]new().(interpreter_config, versions.maxrust-analyzer cargo pyo3-ffi 0.28.2 SupportedVersions#max.); |
| 109 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.finishrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/impl#[MaximumVersionExceeded]finish().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if interpreter_config.abi3rust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#abi3. { |
| 115 | match interpreter_config.implementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#implementation. { |
| 116 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::CPythonrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#CPython# => { |
| 117 | if interpreter_config.is_free_threadedrust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[InterpreterConfig]is_free_threaded().() { |
| 118 | warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!!( |
| 119 | "The free-threaded build of CPython does not yet support abi3 so the build artifacts will be version-specific." |
| 120 | ) |
| 121 | } |
| 122 | } |
| 123 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::PyPyrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#PyPy# => warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!!( |
| 124 | "PyPy does not yet support abi3 so the build artifacts will be version-specific. \ |
| 125 | See https://github.com/pypy/pypy/issues/3397 for more information." |
| 126 | ), |
| 127 | PythonImplementationrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#::GraalPyrust-analyzer cargo pyo3-build-config 0.28.2 impl_/PythonImplementation#GraalPy# => warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!!( |
| 128 | "GraalPy does not support abi3 so the build artifacts will be version-specific." |
| 129 | ), |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 134 | } |
| 135 | |
| 136 | fn ensure_target_pointer_widthrust-analyzer cargo pyo3-ffi 0.28.2 ensure_target_pointer_width().(interpreter_config: &InterpreterConfigrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#) -> Resultrust-analyzer cargo pyo3-build-config 0.28.2 errors/Result#<()> { |
| 137 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pointer_width) = interpreter_config.pointer_widthrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#pointer_width. { |
| 138 | // Try to check whether the target architecture matches the python library |
| 139 | let rust_target = match cargo_env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/cargo_env_var().("CARGO_CFG_TARGET_POINTER_WIDTH") |
| 140 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 141 | .as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() |
| 142 | { |
| 143 | "64" => 64, |
| 144 | "32" => 32, |
| 145 | x => bailrust-analyzer cargo pyo3-build-config 0.28.2 errors/bail!!("unexpected Rust target pointer width: {}", x), |
| 146 | }; |
| 147 | |
| 148 | ensurerust-analyzer cargo pyo3-build-config 0.28.2 errors/ensure!!( |
| 149 | rust_target == pointer_width, |
| 150 | "your Rust target architecture ({}-bit) does not match your python interpreter ({}-bit)", |
| 151 | rust_target, |
| 152 | pointer_width |
| 153 | ); |
| 154 | } |
| 155 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 156 | } |
| 157 | |
| 158 | fn emit_link_configrust-analyzer cargo pyo3-ffi 0.28.2 emit_link_config().(build_config: &BuildConfigrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfig#) -> Resultrust-analyzer cargo pyo3-build-config 0.28.2 errors/Result#<()> { |
| 159 | let interpreter_config = &build_config.interpreter_configrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfig#interpreter_config.; |
| 160 | let target_os = cargo_env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/cargo_env_var().("CARGO_CFG_TARGET_OS").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 161 | |
| 162 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 163 | "cargo:rustc-link-lib={link_model}{alias}{lib_name}", |
| 164 | link_model = if interpreter_config.sharedrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#shared. { |
| 165 | "" |
| 166 | } else { |
| 167 | "static=" |
| 168 | }, |
| 169 | alias = if target_os == "windows" { |
| 170 | "pythonXY:" |
| 171 | } else { |
| 172 | "" |
| 173 | }, |
| 174 | lib_name = interpreter_config.lib_namerust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#lib_name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().( |
| 175 | "attempted to link to Python shared library but config does not contain lib_name" |
| 176 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 177 | ); |
| 178 | |
| 179 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(lib_dir) = &interpreter_config.lib_dirrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#lib_dir. { |
| 180 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-search=native={lib_dir}"); |
| 181 | } else if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(build_config.sourcerust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfig#source., BuildConfigSourcerust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfigSource#::CrossCompilerust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfigSource#CrossCompile#) { |
| 182 | warnrust-analyzer cargo pyo3-build-config 0.28.2 errors/warn!!( |
| 183 | "The output binary will link to libpython, \ |
| 184 | but PYO3_CROSS_LIB_DIR environment variable is not set. \ |
| 185 | Ensure that the target Python library directory is \ |
| 186 | in the rustc native library search path." |
| 187 | ); |
| 188 | } |
| 189 | |
| 190 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 191 | } |
| 192 | |
| 193 | /// Prepares the PyO3 crate for compilation. |
| 194 | /// |
| 195 | /// This loads the config from pyo3-build-config and then makes some additional checks to improve UX |
| 196 | /// for users. |
| 197 | /// |
| 198 | /// Emits the cargo configuration based on this config as well as a few checks of the Rust compiler |
| 199 | /// version to enable features which aren't supported on MSRV. |
| 200 | fn configure_pyo3rust-analyzer cargo pyo3-ffi 0.28.2 configure_pyo3().() -> Resultrust-analyzer cargo pyo3-build-config 0.28.2 errors/Result#<()> { |
| 201 | let target = target_triple_from_envrust-analyzer cargo pyo3-build-config 0.28.2 impl_/target_triple_from_env().(); |
| 202 | let build_config = resolve_build_configrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/resolve_build_config().(&target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 203 | let interpreter_config = &build_config.interpreter_configrust-analyzer cargo pyo3-build-config 0.28.2 pyo3_build_script_impl/BuildConfig#interpreter_config.; |
| 204 | |
| 205 | if env_varrust-analyzer cargo pyo3-build-config 0.28.2 impl_/env_var().("PYO3_PRINT_CONFIG").is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|os_str| os_str rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq()."1") { |
| 206 | print_config_and_exitrust-analyzer cargo pyo3-ffi 0.28.2 print_config_and_exit().(interpreter_config); |
| 207 | } |
| 208 | |
| 209 | ensure_python_versionrust-analyzer cargo pyo3-ffi 0.28.2 ensure_python_version().(interpreter_config)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 210 | ensure_target_pointer_widthrust-analyzer cargo pyo3-ffi 0.28.2 ensure_target_pointer_width().(interpreter_config)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 211 | |
| 212 | // Serialize the whole interpreter config into DEP_PYTHON_PYO3_CONFIG env var. |
| 213 | interpreter_config.to_cargo_dep_envrust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[InterpreterConfig]to_cargo_dep_env().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 214 | |
| 215 | if is_linking_libpython_for_targetrust-analyzer cargo pyo3-build-config 0.28.2 impl_/is_linking_libpython_for_target().(&target) |
| 216 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().interpreter_config.suppress_build_script_link_linesrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#suppress_build_script_link_lines. |
| 217 | { |
| 218 | emit_link_configrust-analyzer cargo pyo3-ffi 0.28.2 emit_link_config().(&build_config)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 219 | } |
| 220 | |
| 221 | for cfg in interpreter_config.build_script_outputsrust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[InterpreterConfig]build_script_outputs().() { |
| 222 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{cfg}") |
| 223 | } |
| 224 | |
| 225 | // Extra lines come last, to support last write wins. |
| 226 | for line in &interpreter_config.extra_build_script_linesrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#extra_build_script_lines. { |
| 227 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{line}"); |
| 228 | } |
| 229 | |
| 230 | print_feature_cfgsrust-analyzer cargo pyo3-build-config 0.28.2 print_feature_cfgs().(); |
| 231 | |
| 232 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 233 | } |
| 234 | |
| 235 | fn print_config_and_exitrust-analyzer cargo pyo3-ffi 0.28.2 print_config_and_exit().(config: &InterpreterConfigrust-analyzer cargo pyo3-build-config 0.28.2 impl_/InterpreterConfig#) { |
| 236 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\n-- PYO3_PRINT_CONFIG=1 is set, printing configuration and halting compile --"); |
| 237 | config |
| 238 | .to_writerrust-analyzer cargo pyo3-build-config 0.28.2 impl_/impl#[InterpreterConfig]to_writer().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().()) |
| 239 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to print config to stdout"); |
| 240 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\nnote: unset the PYO3_PRINT_CONFIG environment variable and retry to compile with the above config"); |
| 241 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(101); |
| 242 | } |
| 243 | |
| 244 | fn mainrust-analyzer cargo pyo3-ffi 0.28.2 main().() { |
| 245 | pyo3_build_configrust-analyzer cargo pyo3-build-config 0.28.2 crate/::print_expected_cfgsrust-analyzer cargo pyo3-build-config 0.28.2 print_expected_cfgs().(); |
| 246 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = configure_pyo3rust-analyzer cargo pyo3-ffi 0.28.2 configure_pyo3().() { |
| 247 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("error: {}", e.reportrust-analyzer cargo pyo3-build-config 0.28.2 errors/impl#[Error]report().()); |
| 248 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(1) |
| 249 | } |
| 250 | } |