diff --git a/build.rs b/build.rs index b0f1e06f..d96e5260 100644 --- a/build.rs +++ b/build.rs @@ -126,7 +126,7 @@ impl CrossCompileConfig { include_dir: None, os: env::var("CARGO_CFG_TARGET_OS").unwrap(), arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(), - version: env::var_os("PYO3_PYTHON_VERSION").map(|s| s.into_string().unwrap()), + version: env::var_os("PYO3_CROSS_PYTHON_VERSION").map(|s| s.into_string().unwrap()), }) } @@ -296,7 +296,12 @@ fn ends_with(entry: &DirEntry, pat: &str) -> bool { /// /// [1]: https://github.com/python/cpython/blob/3.5/Lib/sysconfig.py#L389 fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result { - let mut sysconfig_paths = search_lib_dir(&cross.lib_dir, &cross); + let sysconfig_paths = search_lib_dir(&cross.lib_dir, &cross); + let mut sysconfig_paths = sysconfig_paths + .iter() + .filter_map(|p| fs::canonicalize(p).ok()) + .collect::>(); + sysconfig_paths.dedup(); if sysconfig_paths.is_empty() { bail!( "Could not find either libpython.so or _sysconfigdata*.py in {}", @@ -378,7 +383,7 @@ fn load_cross_compile_from_sysconfigdata( let interpreter_config = InterpreterConfig { version: python_version, - libdir: python_paths.lib_dir.to_str().map(String::from), //libpython_path.to_str().map(String::from), + libdir: python_paths.lib_dir.to_str().map(String::from), shared, ld_version, base_prefix: "".to_string(), diff --git a/guide/src/building_and_distribution.md b/guide/src/building_and_distribution.md index 8f908e8d..e32806d8 100644 --- a/guide/src/building_and_distribution.md +++ b/guide/src/building_and_distribution.md @@ -54,7 +54,7 @@ After you've obtained the above, you can build a cross compiled PyO3 module by s * `PYO3_CROSS_INCLUDE_DIR`: This variable must be set to the directory containing the headers for the target's Python interpreter. **It is only necessary if targeting Windows platforms** * `PYO3_CROSS_LIB_DIR`: This variable must be set to the directory containing the target's libpython DSO and the associated `_sysconfigdata*.py` file. -* `PYO3_PYTHON_VERSION`: This variable must be set if there are multiple versions of python compiled for a unix machine. +* `PYO3_CROSS_PYTHON_VERSION`: This variable must be set if there are multiple versions of python compiled for a unix machine. An example might look like the following (assuming your target's sysroot is at `/home/pyo3/cross/sysroot` and that your target is `armv7`): @@ -66,7 +66,7 @@ cargo build --target armv7-unknown-linux-gnueabihf If there are multiple python versions at the cross lib directory and you cannot set a more precise location to include both the `libpython` DSO and `_sysconfigdata*.py` files, you can set the required version: ```sh -export PYO3_PYTHON_VERSION=3.8 +export PYO3_CROSS_PYTHON_VERSION=3.8 export PYO3_CROSS_LIB_DIR="/home/pyo3/cross/sysroot/usr/lib" cargo build --target armv7-unknown-linux-gnueabihf