protoc_gen_rust_grpc/lib.rs
1/*
2 *
3 * Copyright 2026 gRPC authors.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
25//! Library for compiling and using the [`gRPC-Rust`] plugin for [`protoc`].
26//!
27//! [`protoc`]: https://protobuf.dev/installation/
28//! [`gRPC-Rust`]: https://crates.io/crates/grpc
29
30use std::path::PathBuf;
31
32fn bin_file(file: &str) -> String {
33 let mut path = PathBuf::from(bin()).join(file);
34 if cfg!(target_os = "windows") {
35 path.set_extension("exe");
36 }
37 path.to_str()
38 .expect("Path contains invalid UTF-8")
39 .to_owned()
40}
41
42/// The full path to the `protoc` executable.
43pub fn protoc() -> String {
44 bin_file("protoc")
45}
46
47/// The full path to the gRPC `protoc` plugin, `protoc-gen-rust-grpc`.
48pub fn protoc_gen_rust_grpc() -> String {
49 bin_file("protoc-gen-rust-grpc")
50}
51
52/// The path to the `bin` directory containing the C++ binaries this package
53/// builds.
54pub fn bin() -> String {
55 PathBuf::from(env!("OUT_DIR"))
56 .join("build")
57 .join("bin")
58 .to_str()
59 .expect("Path contains invalid UTF-8")
60 .to_owned()
61}