diff --git a/Cargo.toml b/Cargo.toml index 7296427c..006e64c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,10 @@ extension-module = [ "python3-sys/extension-module" ] # or python3-sys. (honestly, we should probably merge both crates into 'python-sys') extension-module-2-7 = [ "python27-sys/extension-module" ] +# Use these features to explicitly control linking for Python 3. +# (See the documentation in python3-sys/Cargo.toml for more info.) +py-link-mode-default = [ "python3-sys/link-mode-default" ] +py-link-mode-unresolved-static = [ "python3-sys/link-mode-unresolved-static" ] # Optional features to support explicitly specifying python minor version. # If you don't care which minor version, just specify python3-sys as a diff --git a/build.rs b/build.rs index d1e0ca6f..701e32c3 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,16 @@ const PYTHONSYS_ENV_VAR: &'static str = "DEP_PYTHON27_PYTHON_FLAGS"; const PYTHONSYS_ENV_VAR: &'static str = "DEP_PYTHON3_PYTHON_FLAGS"; fn main() { - // python{27,3.x}-sys/build.rs passes python interpreter compile flags via + if cfg!(feature="python27-sys") { + if env::var_os("CARGO_FEATURE_PY_LINK_MODE_DEFAULT").is_some() || + env::var_os("CARGO_FEATURE_PY_LINK_MODE_UNRESOLVED_STATIC").is_some() { + writeln!(std::io::stderr(), + "Cannot use link mode control with Python 2.7"); + std::process::exit(1); + } + } + + // python{27,3.x}-sys/build.rs passes python interpreter compile flags via // environment variable (using the 'links' mechanism in the cargo.toml). let flags = match env::var(PYTHONSYS_ENV_VAR) { Ok(flags) => flags, diff --git a/python3-sys/Cargo.toml b/python3-sys/Cargo.toml index a06a85b3..b6c1ec0a 100644 --- a/python3-sys/Cargo.toml +++ b/python3-sys/Cargo.toml @@ -37,6 +37,30 @@ default = ["python-3"] # so that the module can also be used with statically linked python interpreters. extension-module = [ ] +# This feature implies default linking behavior. +# +# If not an extension module or on Windows, the crate will link against +# pythonXY where XY is derived from the discovered Python version. The link +# type will be static, shared, or framework depending on the discovered Python. +# +# The path to pythonXY from the discovered Python install may also be +# added to the linker search path. +# +# This link mode is used by default unless an alternate link mode feature is +# used. +link-mode-default = [] + +# This feature forces Python symbols to be unresolved by emitting a +# `rustc-link-lib=static-nobundle=pythonXY` directive on Windows (which +# is the only platform where it makes sense). +# +# This mode is useful for scenarios where you want another crate to emit +# the linker directives that define the location of a static Python library. +# +# This mode is typically not needed, as Python distributions on Windows +# rarely use a static Python library. +link-mode-unresolved-static = [] + # Bind to any python 3.x. python-3 = [] diff --git a/python3-sys/build.rs b/python3-sys/build.rs index 5cfbb6a5..40602d80 100644 --- a/python3-sys/build.rs +++ b/python3-sys/build.rs @@ -316,16 +316,43 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result