fn main() {
    let proto_file = "proto/hello.proto";
    let out_dir = std::env::var("OUT_DIR").unwrap();

    // Find the protoc-gen-roto binary
    // Since we added roto-codegen to build-dependencies, it will be built.
    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let target_dir = std::path::Path::new(&manifest_dir).join("../../target/debug");
    let plugin_path = target_dir.join("protoc-gen-roto");

    if !plugin_path.exists() {
        panic!("protoc-gen-roto plugin not found at {:?}", plugin_path);
    }

    let status = std::process::Command::new("protoc")
        .arg(format!("--plugin=protoc-gen-roto={}", plugin_path.display()))
        .arg(format!("--roto_out={}", out_dir))
        .arg(format!("--roto_opt=src=proto")) // Assuming the plugin handles this or we just pass it
        .arg(proto_file)
        .status()
        .expect("Failed to execute protoc");

    if !status.success() {
        panic!("protoc failed with status {}", status);
    }
}
