From bd426d4065f5cd5efe3429209ff76cd4f4720864 Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Fri, 6 Sep 2019 22:14:48 +0100 Subject: [PATCH 1/2] Use python3 explicitly --- build.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 376973ec542..64b730134aa 100644 --- a/build.rs +++ b/build.rs @@ -18,6 +18,7 @@ use version_check::{Channel, Date, Version}; /// But note that this is the rustc version which can be lower than the nightly version const MIN_DATE: &'static str = "2019-07-18"; const MIN_VERSION: &'static str = "1.37.0-nightly"; +const PYTHON_INTERPRETER: &'static str = "python3"; /// Information returned from python interpreter #[derive(Deserialize, Debug)] @@ -357,7 +358,7 @@ elif sysconfig.get_config_var("Py_ENABLE_SHARED"): else: print("static") "#; - let out = run_python_script("python", script).unwrap(); + let out = run_python_script(PYTHON_INTERPRETER, script).unwrap(); Ok(out.trim_end().to_owned()) } @@ -425,22 +426,19 @@ fn find_interpreter_and_get_config() -> Result<(InterpreterConfig, HashMap Date: Sun, 8 Sep 2019 00:37:17 +0100 Subject: [PATCH 2/2] Search for both python3 and python --- Cargo.toml | 1 + build.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d42f8417896..62527dc7bcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ regex = "1.2.1" version_check = "0.9.1" serde = { version = "1.0.99", features = ["derive"] } serde_json = "1.0.40" +lazy_static = "1.4" [features] default = [] diff --git a/build.rs b/build.rs index 64b730134aa..a429ead6e10 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate lazy_static; + use regex::Regex; use serde::Deserialize; use std::collections::HashMap; @@ -18,7 +21,18 @@ use version_check::{Channel, Date, Version}; /// But note that this is the rustc version which can be lower than the nightly version const MIN_DATE: &'static str = "2019-07-18"; const MIN_VERSION: &'static str = "1.37.0-nightly"; -const PYTHON_INTERPRETER: &'static str = "python3"; +//const PYTHON_INTERPRETER: &'static str = "python3"; + +lazy_static! { + static ref PYTHON_INTERPRETER: &'static str = { + ["python3", "python"] + .iter() + .map(|bin| (bin, Command::new(bin).spawn())) + .find(|(_, r)| r.is_ok()) + .map(|(bin, _)| bin) + .expect("Python 3.x interpreter not found") + }; +} /// Information returned from python interpreter #[derive(Deserialize, Debug)] @@ -358,7 +372,7 @@ elif sysconfig.get_config_var("Py_ENABLE_SHARED"): else: print("static") "#; - let out = run_python_script(PYTHON_INTERPRETER, script).unwrap(); + let out = run_python_script(&PYTHON_INTERPRETER, script).unwrap(); Ok(out.trim_end().to_owned()) } @@ -426,19 +440,19 @@ fn find_interpreter_and_get_config() -> Result<(InterpreterConfig, HashMap