We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c148ad4 commit 776ea02Copy full SHA for 776ea02
build.rs
@@ -0,0 +1,33 @@
1
+use std::process::{Command, Stdio};
2
+use std::str;
3
+fn is_python2() -> bool {
4
+ let script = r"
5
+import sys
6
+print(sys.version_info[0])
7
+";
8
+ let out = Command::new("python")
9
+ .args(&["-c", script])
10
+ .stderr(Stdio::inherit())
11
+ .output()
12
+ .expect("Failed to run the python interpreter");
13
+ let version = str::from_utf8(&out.stdout).unwrap();
14
+ version.starts_with("2")
15
+}
16
+
17
+fn cfg(python2: bool) {
18
+ if python2 {
19
+ println!("cargo:rustc-cfg=Py_2");
20
+ } else {
21
+ println!("cargo:rustc-cfg=Py_3");
22
+ }
23
24
25
+fn main() {
26
+ if cfg!(feature = "python3") {
27
+ cfg(false);
28
+ } else if cfg!(feature = "python2") {
29
+ cfg(true);
30
31
+ cfg(is_python2());
32
33
0 commit comments