protoc-gen-rust-grpc 0.9.0

Protobuf plugin to generate gRPC-Rust service bindings
Documentation
/*
 *
 * Copyright 2026 gRPC authors.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */

//! Library for compiling and using the [`gRPC-Rust`] plugin for [`protoc`].
//!
//! [`protoc`]: https://protobuf.dev/installation/
//! [`gRPC-Rust`]: https://crates.io/crates/grpc

use std::path::PathBuf;

fn bin_file(file: &str) -> String {
    let mut path = PathBuf::from(bin()).join(file);
    if cfg!(target_os = "windows") {
        path.set_extension("exe");
    }
    path.to_str()
        .expect("Path contains invalid UTF-8")
        .to_owned()
}

/// The full path to the `protoc` executable.
pub fn protoc() -> String {
    bin_file("protoc")
}

/// The full path to the gRPC `protoc` plugin, `protoc-gen-rust-grpc`.
pub fn protoc_gen_rust_grpc() -> String {
    bin_file("protoc-gen-rust-grpc")
}

/// The path to the `bin` directory containing the C++ binaries this package
/// builds.
pub fn bin() -> String {
    PathBuf::from(env!("OUT_DIR"))
        .join("build")
        .join("bin")
        .to_str()
        .expect("Path contains invalid UTF-8")
        .to_owned()
}