protobuf_src/
lib.rs

1// Copyright Materialize, Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License in the LICENSE file at the
6// root of this repository, or online at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! [<img src="https://materialize.com/wp-content/uploads/2020/01/materialize_logo_primary.png" width=180 align=right>](https://materialize.com)
17//! Build system integration with `libprotobuf`, the C++ implementation of
18//! [Protocol Buffers], Google's data interchange format.
19//!
20//! # Maintainership
21//!
22//! This crate is maintained by [Materialize]. Contributions are encouraged:
23//!
24//! * [View source code](https://github.com/MaterializeInc/rust-protobuf-native/tree/master/src/protobuf-src)
25//! * [Report an issue](https://github.com/MaterializeInc/rust-protobuf-native/issues/new/choose)
26//! * [Submit a pull request](https://github.com/MaterializeInc/rust-protobuf-native/compare)
27//!
28//! # Details
29//!
30//! This crate builds a vendored copy of libprotobuf and protoc using Cargo's
31//! support for custom build scripts. It is not intended for direct consumption,
32//! but as a dependency for other crates that need libprotobuf or protoc
33//! available, like [prost-build].
34//!
35//! protobuf-src is currently bundling protobuf [v3.19.1].
36//!
37//! To use this crate, declare a `dependency` or `dev-dependency` on
38//! `protobuf-src`. Then, in the build script for your crate, the environment
39//! variable `DEP_PROTOBUF_SRC_ROOT` will point to the directory in which the
40//! bundled copy of protobuf has been installed. You can build and link another
41//! C/C++ library against this copy of libprotobuf or generate Rust bindings and
42//! link Rust code against this copy of libprotobuf.
43//!
44//! If you simply need to invoke the vendored protoc binary, [`protoc`] returns
45//! the path to pass to [`std::process::Command`].
46//!
47//! [Materialize]: https://materialize.com
48//! [Protocol Buffers]: https://developers.google.com/protocol-buffers
49//! [v3.19.1]: https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.1
50//! [prost-build]: https://docs.rs/prost-build/latest/prost_build/
51
52use std::path::PathBuf;
53
54/// Returns the path to the vendored protoc binary.
55pub fn protoc() -> PathBuf {
56    PathBuf::from(env!("INSTALL_DIR"))
57        .join("bin")
58        .join("protoc")
59}
60
61/// Returns the path to the vendored include directory.
62pub fn include() -> PathBuf {
63    PathBuf::from(env!("INSTALL_DIR")).join("include")
64}