fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Vendored protoc keeps the build hermetic: contributors and CI need
    // only a Rust toolchain, not a system protobuf install.
    std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path()?);
    // The protos are vendored into the crate so it packages and builds from
    // crates.io with no out-of-tree paths. `image.proto` is imported by
    // `imagebuilder.proto`, so it is watched even though it is not a root.
    for proto in [
        "proto/workerproxy/v1/workerproxy.proto",
        "proto/imagebuilder/v1/imagebuilder.proto",
        "proto/image/v1/image.proto",
    ] {
        println!("cargo:rerun-if-changed={proto}");
    }
    // Server stubs are emitted only under the `test-fakes` feature, which the
    // test build enables so integration tests can run an in-process fake worker
    // proxy. Production builds (the SDK is a pure client) skip them.
    println!("cargo:rerun-if-env-changed=CARGO_FEATURE_TEST_FAKES");
    let build_server = std::env::var_os("CARGO_FEATURE_TEST_FAKES").is_some();
    tonic_prost_build::configure()
        .build_server(build_server)
        .compile_protos(
            &[
                "proto/workerproxy/v1/workerproxy.proto",
                "proto/imagebuilder/v1/imagebuilder.proto",
            ],
            &["proto"],
        )?;
    Ok(())
}
