From 9405ffa3b9f14284697e2a7339fcd97c31e35d33 Mon Sep 17 00:00:00 2001 From: konstin Date: Sun, 9 Sep 2018 18:49:03 +0200 Subject: [PATCH] Add section about linking in the guide --- build.rs | 2 +- guide/src/debugging.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 26301965..4e4cb45b 100644 --- a/build.rs +++ b/build.rs @@ -532,7 +532,7 @@ fn main() { // TODO: Find out how we can set -undefined dynamic_lookup here (if this is possible) } - let env_vars = ["LD_LIBRARY_PATH", "PATH", "PYTHON_SYS_EXECUTABLE"]; + let env_vars = ["LD_LIBRARY_PATH", "PATH", "PYTHON_SYS_EXECUTABLE", "LIB"]; for var in env_vars.iter() { println!("cargo:rerun-if-env-changed={}", var); diff --git a/guide/src/debugging.md b/guide/src/debugging.md index e85451ae..976a4c6b 100644 --- a/guide/src/debugging.md +++ b/guide/src/debugging.md @@ -1,5 +1,7 @@ # Debugging +## Macros + Pyo3's attributes, `#[pyclass]`, `#[pymodinit]`, etc. are [procedural macros](https://doc.rust-lang.org/unstable-book/language-features/proc-macro.html), which means that rewrite the source of the annotated item. You can view the generated source with the following command, which also expands a few other things: ```bash @@ -15,3 +17,7 @@ cargo rustc --profile=check -- -Z unstable-options --pretty=expanded -Z trace-ma ``` See [cargo expand](https://github.com/dtolnay/cargo-expand) for a more elaborate version of those commands. + +## Linking + +When building, you can set `PYTHON_SYS_EXECUTABLE` to the python interpreter that pyo3 should be linked to. You might need to set the `python2` or `python3` feature accordingly. On linux/mac you might have to change `LD_LIBRARY_PATH` to include libpython, while on windows you might need to set `LIB` to include `pythonxy.lib` (where x and y are major and minor version), which is normally either in the `libs` or `Lib` folder of a python installation. Also make sure that python is in `PATH` when you're not using `PYTHON_SYS_EXECUTABLE`.