Skip to content

Commit 55db0d0

Browse files
committed
fix: buffrs should not use protoc-bin-vendored
Instead, we should use protoc crate for working with user provided binary.
1 parent 839ddde commit 55db0d0

File tree

4 files changed

+20
-75
lines changed

4 files changed

+20
-75
lines changed

.github/workflows/cli.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v3
23+
- uses: arduino/setup-protoc@v2
2324
- run: rustup update && rustup component add clippy
2425
- uses: Swatinem/rust-cache@v2
2526
- run: cargo clippy --all-targets --workspace -- -D warnings -D clippy::all
@@ -30,6 +31,7 @@ jobs:
3031
- uses: actions/checkout@v3
3132
with:
3233
lfs: "true"
34+
- uses: arduino/setup-protoc@v2
3335
- run: rustup update
3436
- uses: Swatinem/rust-cache@v2
3537
- run: cargo test --workspace
@@ -51,6 +53,7 @@ jobs:
5153
- uses: actions/checkout@v3
5254
with:
5355
lfs: 'true'
56+
- uses: arduino/setup-protoc@v2
5457
- run: rustup update
5558
- run: rustup component add llvm-tools-preview
5659
- uses: Swatinem/rust-cache@v2

Cargo.lock

Lines changed: 6 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test = true
2323

2424
[features]
2525
default = ["build", "git", "validation"]
26-
build = ["dep:tonic-build", "dep:protoc-bin-vendored"]
26+
build = ["dep:tonic-build", "dep:protoc"]
2727
validation = ["dep:anyhow", "dep:protobuf", "dep:protobuf-parse", "dep:diff-struct"]
2828
git = ["dep:git2"]
2929

@@ -41,7 +41,7 @@ human-panic = "1"
4141
miette = { version = "5.10.0", features = ["fancy"] }
4242
protobuf = { version = "3.3.0", optional = true }
4343
protobuf-parse = { version = "3.3.0", optional = true }
44-
protoc-bin-vendored = { version = "3.0.0", optional = true }
44+
protoc = { version = "2.28.0", optional = true }
4545
reqwest = { version = "0.11", features = ["rustls-tls-native-roots"], default-features = false }
4646
semver = { version = "1", features = ["serde"] }
4747
serde = { version = "1", features = ["derive"] }

src/generator.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use std::{fmt, path::PathBuf};
1616

1717
use miette::{ensure, miette, Context, IntoDiagnostic};
18-
use protoc_bin_vendored::protoc_bin_path;
1918
use serde::{Deserialize, Serialize};
2019
use tracing::{debug, info};
2120

@@ -57,18 +56,12 @@ impl Generator {
5756

5857
/// Run the generator for a dependency and output files at the provided path
5958
pub async fn run(&self) -> miette::Result<()> {
60-
let protoc = protoc_bin_path()
61-
.into_diagnostic()
62-
.wrap_err(miette!("unable to locate vendored protoc"))?;
63-
64-
std::env::set_var("PROTOC", protoc.clone());
65-
6659
let store = PackageStore::current().await?;
6760
let manifest = Manifest::read().await?;
6861

6962
store.populate(&manifest).await?;
7063

71-
let protos = store.populated_files(&manifest).await;
64+
let proto_files = store.populated_files(&manifest).await;
7265
let includes = &[store.proto_vendor_path()];
7366

7467
match self {
@@ -78,15 +71,15 @@ impl Generator {
7871
.build_server(true)
7972
.build_transport(true)
8073
.include_file(Self::TONIC_INCLUDE_FILE)
81-
.compile(&protos, includes)
74+
.compile(&proto_files, includes)
8275
.into_diagnostic()?;
8376
}
8477
Generator::Protoc { language, out_dir } => {
85-
let mut protoc_cmd = tokio::process::Command::new(protoc);
78+
let mut protoc = protoc::ProtocLangOut::new();
8679

8780
match language {
8881
Language::Python => {
89-
protoc_cmd.arg("--python_out").arg(out_dir);
82+
protoc.lang("python").out_dir(out_dir);
9083
}
9184
}
9285

@@ -95,25 +88,14 @@ impl Generator {
9588
// e.g. if input proto path is proto/vendor/units/units.proto and the proto path is 'proto'
9689
// and the --python_out is 'proto/build/gen' then the file will be output to
9790
// proto/build/gen/vendor/units/units.py
91+
// We need both of these if we want "vendor" to be removed, and it has to come first
92+
protoc.includes(["proto/vendor", "proto"]);
9893

99-
protoc_cmd.arg("--proto_path").arg("proto/vendor"); // We need both of these if we want "vendor" to be removed, and it has to come first
100-
protoc_cmd.arg("--proto_path").arg("proto");
101-
102-
protoc_cmd.args(&protos);
103-
104-
debug!(":: running {protoc_cmd:?}");
105-
106-
let output = protoc_cmd.output().await.into_diagnostic()?;
94+
protoc.inputs(&proto_files);
10795

108-
let exit = output.status.code().ok_or(miette!(
109-
"a signal interrupted the protoc subprocess before it could complete"
110-
))?;
96+
debug!(":: running protoc");
11197

112-
ensure!(
113-
exit == 0,
114-
"the protoc subprocess terminated with an error: {exit}. stderr: {}",
115-
String::from_utf8_lossy(&output.stderr)
116-
);
98+
protoc.run().into_diagnostic()?;
11799

118100
info!(":: {language} code generated successfully");
119101
}

0 commit comments

Comments
 (0)