use std::env;
use std::process::Command;
fn main() {
let project_root = env::current_dir().unwrap();
let lib_path = project_root.join("target/debug/libproofmode.so");
if !lib_path.exists() {
eprintln!("Library not found at {:?}. Please run 'cargo build --features uniffi' first.", lib_path);
std::process::exit(1);
}
let python_out_dir = project_root.join("python-uniffi/python/proofmode/uniffi_generated");
std::fs::create_dir_all(&python_out_dir).unwrap();
let status = Command::new("python3")
.arg("-c")
.arg(format!(r#"
import os
import sys
sys.path.insert(0, "{}")
import uniffi_bindgen
# Generate Python bindings
uniffi_bindgen.generate_bindings(
udl_file=None,
config_file_override=None,
library_path="{}",
language="python",
out_dir="{}",
try_format_code=True
)
print("Python bindings generated successfully!")
"#, project_root.display(), lib_path.display(), python_out_dir.display()))
.status();
match status {
Ok(status) if status.success() => {
println!("Python bindings generated successfully!");
}
Ok(status) => {
eprintln!("Python binding generation failed with status: {}", status);
}
Err(e) => {
eprintln!("Failed to run Python binding generation: {}", e);
println!("Trying alternative approach...");
let alt_status = Command::new("uniffi-bindgen")
.arg("generate")
.arg("--library")
.arg(&lib_path)
.arg("--language")
.arg("python")
.arg("--out-dir")
.arg(&python_out_dir)
.status();
match alt_status {
Ok(status) if status.success() => {
println!("Python bindings generated with uniffi-bindgen!");
}
_ => {
println!("uniffi-bindgen not available, trying manual approach...");
let binding_content = format!(r#"
# Generated UniFFI bindings for ProofMode
import ctypes
import os
from pathlib import Path
# Load the native library
lib_path = Path(__file__).parent.parent.parent.parent / "target" / "debug" / "libproofmode.so"
if lib_path.exists():
_lib = ctypes.CDLL(str(lib_path))
print(f"Loaded ProofMode library from {{lib_path}}")
# TODO: Add proper UniFFI-generated function bindings here
# For now, this is a placeholder that loads the library
else:
raise ImportError(f"ProofMode library not found at {{lib_path}}")
print("UniFFI bindings loaded (placeholder)")
"#);
let binding_file = python_out_dir.join("proofmode.py");
std::fs::write(&binding_file, binding_content).unwrap();
println!("Created placeholder Python bindings at {:?}", binding_file);
}
}
}
}
let ruby_out_dir = project_root.join("ruby-uniffi/lib/uniffi_generated");
std::fs::create_dir_all(&ruby_out_dir).unwrap();
let ruby_binding_content = format!(r#"
# Generated UniFFI bindings for ProofMode
require 'ffi'
module ProofMode
extend FFI::Library
# Load the native library
lib_path = File.join(__dir__, "..", "..", "..", "target", "debug", "libproofmode.so")
if File.exist?(lib_path)
ffi_lib lib_path
puts "Loaded ProofMode library from #{{lib_path}}"
# TODO: Add proper UniFFI-generated function bindings here
# For now, this is a placeholder that loads the library
else
raise LoadError, "ProofMode library not found at #{{lib_path}}"
end
puts "UniFFI bindings loaded (placeholder)"
end
"#);
let ruby_binding_file = ruby_out_dir.join("proofmode.rb");
std::fs::write(&ruby_binding_file, ruby_binding_content).unwrap();
println!("Created placeholder Ruby bindings at {:?}", ruby_binding_file);
}