Skip to content

Commit

Permalink
Compile protoc from source rather than bundled binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
benesch committed Jan 16, 2022
1 parent c3b7037 commit f424122
Show file tree
Hide file tree
Showing 23 changed files with 3 additions and 2,722 deletions.
1 change: 1 addition & 0 deletions prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ itertools = "0.10"
log = "0.4"
multimap = { version = "0.8", default-features = false }
petgraph = { version = "0.6", default-features = false }
protobuf-src = "1.0.1"
prost = { version = "0.9.0", path = "..", default-features = false }
prost-types = { version = "0.9.0", path = "../prost-types", default-features = false }
tempfile = "3"
Expand Down
119 changes: 0 additions & 119 deletions prost-build/build.rs

This file was deleted.

52 changes: 2 additions & 50 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,6 @@
//!
//! That's it! Run `cargo doc` to see documentation for the generated code. The full
//! example project can be found on [GitHub](https://github.com/danburkert/snazzy).
//!
//! ## Sourcing `protoc`
//!
//! `prost-build` depends on the Protocol Buffers compiler, `protoc`, to parse `.proto` files into
//! a representation that can be transformed into Rust. If set, `prost-build` uses the `PROTOC` and
//! `PROTOC_INCLUDE` environment variables for locating `protoc` and the Protobuf includes
//! directory. For example, on a macOS system where Protobuf is installed with Homebrew, set the
//! environment to:
//!
//! ```bash
//! PROTOC=/usr/local/bin/protoc
//! PROTOC_INCLUDE=/usr/local/include
//! ```
//!
//! and in a typical Linux installation:
//!
//! ```bash
//! PROTOC=/usr/bin/protoc
//! PROTOC_INCLUDE=/usr/include
//! ```
//!
//! If `PROTOC` is not found in the environment, then a pre-compiled `protoc` binary bundled in the
//! prost-build crate is used. Pre-compiled `protoc` binaries exist for Linux (non-musl), macOS,
//! and Windows systems. If no pre-compiled `protoc` is available for the host platform, then the
//! `protoc` or `protoc.exe` binary on the `PATH` is used. If `protoc` is not available in any of
//! these fallback locations, then the build fails.
//!
//! If `PROTOC_INCLUDE` is not found in the environment, then the Protobuf include directory
//! bundled in the prost-build crate is be used.
//!
//! To force `prost-build` to use the `protoc` on the `PATH`, add `PROTOC=protoc` to the
//! environment.

mod ast;
mod code_generator;
Expand Down Expand Up @@ -802,7 +770,7 @@ impl Config {
};

if !self.skip_protoc_run {
let mut cmd = Command::new(protoc());
let mut cmd = Command::new(protobuf_src::protoc());
cmd.arg("--include_imports")
.arg("--include_source_info")
.arg("-o")
Expand All @@ -814,7 +782,7 @@ impl Config {

// Set the protoc include after the user includes in case the user wants to
// override one of the built-in .protos.
cmd.arg("-I").arg(protoc_include());
cmd.arg("-I").arg(protobuf_src::include());

for arg in &self.protoc_args {
cmd.arg(arg);
Expand Down Expand Up @@ -1077,22 +1045,6 @@ pub fn compile_protos(protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>]
Config::new().compile_protos(protos, includes)
}

/// Returns the path to the `protoc` binary.
pub fn protoc() -> PathBuf {
match env::var_os("PROTOC") {
Some(protoc) => PathBuf::from(protoc),
None => PathBuf::from(env!("PROTOC")),
}
}

/// Returns the path to the Protobuf include directory.
pub fn protoc_include() -> PathBuf {
match env::var_os("PROTOC_INCLUDE") {
Some(include) => PathBuf::from(include),
None => PathBuf::from(env!("PROTOC_INCLUDE")),
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
32 changes: 0 additions & 32 deletions prost-build/third-party/protobuf/LICENSE

This file was deleted.

158 changes: 0 additions & 158 deletions prost-build/third-party/protobuf/include/google/protobuf/any.proto

This file was deleted.

Loading

0 comments on commit f424122

Please sign in to comment.