Skip to content

Commit

Permalink
PYO3_CONFIG_FILE should work regardless of cross compiling or not
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 5, 2022
1 parent 847fe62 commit 5446ab1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
sudo apt-get install -y mingw-w64
rustup target add x86_64-pc-windows-gnu
cargo run -- build --no-sdist -m test-crates/pyo3-pure/Cargo.toml --target x86_64-pc-windows-gnu
- name: test cross compiling with PYO3_CONFIG_FILE
- name: test compiling with PYO3_CONFIG_FILE
shell: bash
run: |
export PYO3_CONFIG_FILE=$(pwd)/test-crates/pyo3-mixed/pyo3-config.txt
Expand Down
18 changes: 12 additions & 6 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,18 @@ pub fn find_interpreter(
match bridge {
BridgeModel::Bindings(binding_name, _) => {
let mut interpreters = Vec::new();
if binding_name.starts_with("pyo3") && target.is_unix() && target.cross_compiling() {
if let Some(config_file) = env::var_os("PYO3_CONFIG_FILE") {
if !binding_name.starts_with("pyo3") {
bail!("Only pyo3 bindings can be configured with PYO3_CONFIG_FILE");
}
let interpreter_config =
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
.context("Invalid PYO3_CONFIG_FILE")?;
interpreters.push(PythonInterpreter::from_config(interpreter_config));
} else if binding_name.starts_with("pyo3")
&& target.is_unix()
&& target.cross_compiling()
{
if let Some(cross_lib_dir) = std::env::var_os("PYO3_CROSS_LIB_DIR") {
let host_interpreters =
find_host_interpreter(bridge, interpreter, target, min_python_minor)?;
Expand Down Expand Up @@ -724,11 +735,6 @@ pub fn find_interpreter(
platform: None,
runnable: false,
});
} else if let Some(config_file) = env::var_os("PYO3_CONFIG_FILE") {
let interpreter_config =
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
.context("Invalid PYO3_CONFIG_FILE")?;
interpreters.push(PythonInterpreter::from_config(interpreter_config));
} else {
if interpreter.is_empty() {
bail!("Couldn't find any python interpreters. Please specify at least one with -i");
Expand Down

0 comments on commit 5446ab1

Please sign in to comment.