django-language-server/crates/djls-project/build.rs
Josh Thomas d99c96d6b6
Some checks are pending
lint / pre-commit (push) Waiting to run
lint / rustfmt (push) Waiting to run
lint / clippy (push) Waiting to run
lint / cargo-check (push) Waiting to run
release / release (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
release / build (push) Waiting to run
release / test (push) Waiting to run
test / Python , Django () (push) Blocked by required conditions
test / tests (push) Blocked by required conditions
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
Replace PyO3 with IPC approach for Python/project information (#214)
2025-09-09 19:08:42 -05:00

56 lines
1.8 KiB
Rust

use std::env;
use std::path::PathBuf;
use std::process::Command;
fn get_python_executable_path() -> PathBuf {
let python = which::which("python3")
.or_else(|_| which::which("python"))
.expect("Python not found. Please install Python to build this project.");
println!(
"cargo:warning=Building Python inspector with: {}",
python.display()
);
python
}
fn main() {
println!("cargo:rerun-if-changed=../../python/src/djls_inspector");
println!("cargo:rerun-if-changed=../../python/build.py");
let workspace_dir = env::var("CARGO_WORKSPACE_DIR").expect("CARGO_WORKSPACE_DIR not set");
let workspace_path = PathBuf::from(workspace_dir);
let python_dir = workspace_path.join("python");
let dist_dir = python_dir.join("dist");
let pyz_path = dist_dir.join("djls_inspector.pyz");
std::fs::create_dir_all(&dist_dir).expect("Failed to create python/dist directory");
let python = get_python_executable_path();
let output = Command::new(&python)
.arg("build.py")
.current_dir(&python_dir)
.output()
.expect("Failed to run Python build script");
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
panic!("Failed to build Python inspector:\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
}
assert!(
pyz_path.exists(),
"Python inspector zipapp was not created at expected location: {}",
pyz_path.display()
);
let metadata =
std::fs::metadata(&pyz_path).expect("Failed to get metadata for inspector zipapp");
println!(
"cargo:warning=Successfully built Python inspector: {} ({} bytes)",
pyz_path.display(),
metadata.len()
);
}