Skip to content

Commit 25e97ca

Browse files
authored
Fix some issues with pb-jelly-gen and newer python/protoc (#155)
1 parent 6698c7c commit 25e97ca

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

pb-jelly-gen/codegen/pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
[project]
22
name = "pb-jelly"
33
version = "0.0.14"
4+
description = "Generate rust bindings from protobuf specs"
5+
keywords = ["rust", "proto", "dropbox"]
6+
license = { text = "Apache License 2.0" }
7+
dependencies = ["protobuf>=3.13.0"]
8+
9+
[project.scripts]
10+
protoc-gen-rust = "codegen:main"
411

512
[build-system]
613
requires = [

pb-jelly-gen/codegen/setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ keywords = rust proto dropbox
66
license = Apache License 2.0
77
url = https://github.com/dropbox/pb-jelly
88

9+
[options]
10+
install_requires =
11+
protobuf>=3.13.0
12+
913
[options.entry_points]
1014
console_scripts =
1115
protoc-gen-rust = codegen:main
12-
install_requires =
13-
protobuf>=3.13.0

pb-jelly-gen/src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use include_dir::{
3838
use std::os::unix::fs::PermissionsExt;
3939
use std::{
4040
convert::AsRef,
41+
ffi::OsStr,
4142
fs,
4243
io::Write,
4344
iter::IntoIterator,
@@ -228,17 +229,17 @@ impl GenProtos {
228229
}
229230

230231
fn gen_rust_protos(&self, temp_dir: tempfile::TempDir) -> Output {
232+
let venv_bin = self.create_venv(&temp_dir);
231233
let new_path = {
232-
let venv_bin = self.create_venv(&temp_dir);
233234
let mut path: Vec<_> = std::env::split_paths(&std::env::var_os("PATH").unwrap()).collect();
234-
path.insert(0, venv_bin);
235+
path.insert(0, venv_bin.clone());
235236
std::env::join_paths(path).unwrap()
236237
};
237238
dbg!(&new_path);
238239

239240
// Create protoc cmd in the venv
240241
let mut protoc_cmd = Command::new("protoc");
241-
protoc_cmd.env("PATH", new_path);
242+
protoc_cmd.env("PATH", &new_path);
242243
protoc_cmd.env("PYTHONPATH", temp_dir.path());
243244

244245
// Directories that contain protos
@@ -264,8 +265,24 @@ impl GenProtos {
264265
dbg!(path);
265266
}
266267

268+
protoc_cmd.arg(
269+
[
270+
OsStr::new("--plugin=protoc-gen-rust_pb_jelly="),
271+
venv_bin
272+
.join(if cfg!(windows) {
273+
"protoc-gen-rust.exe"
274+
} else {
275+
"protoc-gen-rust"
276+
})
277+
.as_os_str(),
278+
]
279+
.join(OsStr::new("")),
280+
);
281+
267282
// Set the Rust out path
268-
protoc_cmd.arg("--rust_out");
283+
// (Don't use "rust" as the name of the plugin because protoc now has (broken) upstream Rust support that
284+
// overrides the plugin)
285+
protoc_cmd.arg("--rust_pb_jelly_out");
269286
protoc_cmd.arg(&self.gen_path);
270287

271288
// Get paths of our Protos

0 commit comments

Comments
 (0)