Skip to content

Commit 6c1213c

Browse files
committed
Stop hardcoding the path
1 parent 9ac4a10 commit 6c1213c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

jingle_python/build.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
use std::process::Command;
12

23
fn main() {
3-
let var = std::env::var("Z3_PYTHON_LIB").unwrap_or_else(|_| "/Users/maroed/RustroverProjects/jingle/jingle_python/.venv/lib/python3.13/site-packages/z3/lib/".to_string());
4-
// Get the directory where Python's Z3 library is located
5-
let z3_python_lib = std::path::Path::new(&var);
64

7-
// Set the environment variable for Rust to use the same library
8-
println!("cargo:rerun-if-changed=build.rs");
9-
println!("cargo:libdir={}", z3_python_lib.display());
5+
// Run the Python script to get the venv's lib directory
6+
let output = Command::new("python")
7+
.arg("find_path.py") // Assuming the script is named find_venv_lib.py
8+
.output()
9+
.expect("Failed to execute Python script");
10+
11+
if !output.status.success() {
12+
panic!("Python script failed: {:?}", output);
13+
}
1014

15+
let venv_lib = String::from_utf8_lossy(&output.stdout).trim().to_string();
16+
// Get the directory where Python's Z3 library is located
17+
let z3_python_lib = std::path::Path::new(&venv_lib).join("z3").join("lib");
1118
// Optionally, set the rpath for dynamic libraries
1219
println!("cargo:rustc-link-search=native={}", z3_python_lib.display());
1320
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import os
3+
import sysconfig
4+
5+
# Get the virtual environment's lib directory
6+
venv_lib = sysconfig.get_paths()["purelib"]
7+
8+
# Print the path so that we can capture it in build.rs
9+
print(venv_lib)

0 commit comments

Comments
 (0)