Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove build.rs #657

Merged
merged 21 commits into from Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/continuous-integration-workflow.yaml
Expand Up @@ -37,6 +37,10 @@ jobs:
default: true
profile: minimal
components: clippy
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v3
- name: clippy
Expand All @@ -59,6 +63,10 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v3
- name: cargo update -Zminimal-versions
Expand All @@ -80,7 +88,7 @@ jobs:
matrix:
toolchain:
- stable
- 1.53.0
- 1.56.0
os:
- ubuntu-latest
- macos-latest
Expand All @@ -96,6 +104,10 @@ jobs:
toolchain: ${{ matrix.toolchain }}
default: true
profile: minimal
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v3
- uses: Swatinem/rust-cache@v1
Expand Down Expand Up @@ -123,6 +135,10 @@ jobs:
toolchain: nightly
default: true
profile: minimal
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v1
- name: install cargo-no-std-check
uses: actions-rs/cargo@v1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
target
Cargo.lock

.DS_Store
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -25,6 +25,7 @@ members = [
"tests-2015",
"tests-no-std",
"tests/single-include",
"tests/vendored",
]

exclude = [
Expand All @@ -33,7 +34,6 @@ exclude = [
"fuzz",
# Same counts for the afl fuzz targets
"afl",
"test-vendored"
]

[lib]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions prost-build/Cargo.toml
Expand Up @@ -14,7 +14,6 @@ edition = "2018"

[features]
default = []
vendored = []
# When MSRV moves to 1.60, these can change to dep:
cleanup-markdown = ["pulldown-cmark", "pulldown-cmark-to-cmark"]

Expand All @@ -30,15 +29,12 @@ prost-types = { version = "0.10.0", path = "../prost-types", default-features =
tempfile = "3"
lazy_static = "1.4.0"
regex = { version = "1.5.5", default-features = false, features = ["std", "unicode-bool"] }
# These two must be kept in sync
which = "4"

# These two must be kept in sync, used for `cleanup-markdown` feature.
pulldown-cmark = { version = "0.9.1", optional = true, default-features = false }
pulldown-cmark-to-cmark = { version = "10.0.1", optional = true }

[build-dependencies]
which = { version = "4", default-features = false }
cfg-if = "1"
cmake = "0.1"

[dev-dependencies]
env_logger = { version = "0.8", default-features = false }

120 changes: 0 additions & 120 deletions prost-build/build.rs

This file was deleted.

86 changes: 72 additions & 14 deletions prost-build/src/lib.rs
Expand Up @@ -257,6 +257,8 @@ pub struct Config {
disable_comments: PathMap<()>,
skip_protoc_run: bool,
include_file: Option<PathBuf>,
protoc_path: Option<PathBuf>,
protoc_include_path: Option<PathBuf>,
}

impl Config {
Expand Down Expand Up @@ -637,7 +639,7 @@ impl Config {
///
/// In `build.rs`:
///
/// ```rust
/// ```rust, no_run
/// # use std::env;
/// # use std::path::PathBuf;
/// # let mut config = prost_build::Config::new();
Expand Down Expand Up @@ -733,6 +735,24 @@ impl Config {
self
}

/// Configures the path from where to find the `protoc` binary.
pub fn protoc_path<P>(&mut self, arg: P) -> &mut Self
where
P: Into<PathBuf>,
{
self.protoc_path = Some(arg.into());
self
}

/// Configures the path from where the protobuf include files are.
pub fn protoc_include_path<P>(&mut self, arg: P) -> &mut Self
where
P: Into<PathBuf>,
{
self.protoc_include_path = Some(arg.into());
self
}

/// Configures the optional module filename for easy inclusion of all generated Rust files
///
/// If set, generates a file (inside the `OUT_DIR` or `out_dir()` as appropriate) which contains
Expand Down Expand Up @@ -824,7 +844,19 @@ impl Config {
};

if !self.skip_protoc_run {
let mut cmd = Command::new(protoc());
let protoc = self
.protoc_path
.as_ref()
.map(PathBuf::clone)
.unwrap_or_else(protoc_from_env);

let protoc_include = self
.protoc_include_path
.as_ref()
.map(PathBuf::clone)
.unwrap_or_else(protoc_from_env);

let mut cmd = Command::new(protoc.clone());
cmd.arg("--include_imports")
.arg("--include_source_info")
.arg("-o")
Expand All @@ -836,7 +868,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(protoc_include);

for arg in &self.protoc_args {
cmd.arg(arg);
Expand All @@ -849,7 +881,7 @@ impl Config {
let output = cmd.output().map_err(|error| {
Error::new(
error.kind(),
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): {}", error),
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, error),
)
})?;

Expand All @@ -861,7 +893,15 @@ impl Config {
}
}

let buf = fs::read(file_descriptor_set_path)?;
let buf = fs::read(&file_descriptor_set_path).map_err(|e| {
Error::new(
e.kind(),
format!(
"unable to open file_descriptor_set_path: {:?}, OS: {}",
&file_descriptor_set_path, e
),
)
})?;
let file_descriptor_set = FileDescriptorSet::decode(&*buf).map_err(|error| {
Error::new(
ErrorKind::InvalidInput,
Expand Down Expand Up @@ -1043,6 +1083,8 @@ impl default::Default for Config {
protoc_args: Vec::new(),
disable_comments: PathMap::default(),
skip_protoc_run: false,
protoc_path: None,
protoc_include_path: None,
include_file: None,
}
}
Expand Down Expand Up @@ -1200,19 +1242,33 @@ pub fn compile_protos(protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>]
}

/// 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")),
}
pub fn protoc_from_env() -> PathBuf {
env::var_os("PROTOC")
.map(PathBuf::from)
.or_else(|| which::which("protoc").ok())
.expect("`PROTOC` environment variable not set or `protoc` not found in `PATH`.")
}

/// 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")),
pub fn protoc_include_from_env() -> PathBuf {
let protoc_include: PathBuf = env::var_os("PROTOC_INCLUDE")
.expect("`PROTOC_INCLUDE` environment variable not set")
.into();

if !protoc_include.exists() {
panic!(
"PROTOC_INCLUDE environment variable points to non-existent directory ({:?})",
protoc_include
);
}
if !protoc_include.is_dir() {
panic!(
"PROTOC_INCLUDE environment variable points to a non-directory file ({:?})",
protoc_include
);
}

protoc_include
}

#[cfg(test)]
Expand Down Expand Up @@ -1289,6 +1345,7 @@ mod tests {
let _ = env_logger::try_init();
Config::new()
.service_generator(Box::new(ServiceTraitGenerator))
.out_dir(std::env::temp_dir())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to use something like tempdir? It can ensure we don't have test case collisions (if we add more that would collide later) and then cleans up the generated temp directory on drop. Not vital by any means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can fix this in another PR but prob a good idea.

.compile_protos(&["src/smoke_test.proto"], &["src"])
.unwrap();
}
Expand All @@ -1303,6 +1360,7 @@ mod tests {
Config::new()
.service_generator(Box::new(gen))
.include_file("_protos.rs")
.out_dir(std::env::temp_dir())
.compile_protos(&["src/hello.proto", "src/goodbye.proto"], &["src"])
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion prost-build/third-party/protobuf
Submodule protobuf deleted from 22d0e2