use std::fs::create_dir_all;
use std::path::Path;
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
pyo3_build_config::add_extension_module_link_args();
#[cfg(feature = "grpc_network")]
build_protobuf()?;
Ok(())
}
fn build_protobuf() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/relayrl_grpc.proto")?;
Ok(())
}
fn build_data_bindings() -> Result<(), Box<dyn std::error::Error>> {
let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let maturin_check = Command::new("maturin").arg("--version").output();
if maturin_check.is_err() || !maturin_check.unwrap().status.success() {
panic!("Maturin not found. Please install it with `pip install maturin`");
}
let status = Command::new("maturin")
.arg("develop")
.arg("--release")
.arg("--features=training_data")
.current_dir(&crate_dir)
.status()?;
if !status.success() {
panic!("Failed to build Python bindings, exit status: {}", status);
}
println!("Successfully built Python bindings");
Ok(())
}
fn build_python_binary() -> Result<(), Box<dyn std::error::Error>> {
let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let python_dir = Path::new(&crate_dir).join("src/native/python");
let binary_output_dir = python_dir.join("bin");
create_dir_all(&binary_output_dir)?;
let pyoxidizer_check = Command::new("pyoxidizer").arg("--version").output();
if pyoxidizer_check.is_err() || !pyoxidizer_check.unwrap().status.success() {
panic!("PyOxidizer not found. Please install it with `cargo install pyoxidizer`");
}
println!("cargo:rerun-if-changed=src/native/python");
let status = Command::new("pyoxidizer")
.arg("build")
.current_dir(&python_dir)
.status()?;
if !status.success() {
panic!("Failed to build python binary, exit status: {}", status);
}
println!("Successfully built Python binary.");
Ok(())
}