Skip to content

Commit

Permalink
Fix some issues with pb-jelly-gen and newer python/protoc
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie committed Dec 2, 2023
1 parent 6698c7c commit c27c4ea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 7 additions & 0 deletions pb-jelly-gen/codegen/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[project]
name = "pb-jelly"
version = "0.0.14"
description = "Generate rust bindings from protobuf specs"
keywords = ["rust", "proto", "dropbox"]
license = { text = "Apache License 2.0" }
dependencies = ["protobuf>=3.13.0"]

[project.scripts]
protoc-gen-rust = "codegen:main"

[build-system]
requires = [
Expand Down
6 changes: 4 additions & 2 deletions pb-jelly-gen/codegen/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ keywords = rust proto dropbox
license = Apache License 2.0
url = https://github.com/dropbox/pb-jelly

[options]
install_requires =
protobuf>=3.13.0

[options.entry_points]
console_scripts =
protoc-gen-rust = codegen:main
install_requires =
protobuf>=3.13.0
25 changes: 21 additions & 4 deletions pb-jelly-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use include_dir::{
use std::os::unix::fs::PermissionsExt;
use std::{
convert::AsRef,
ffi::OsStr,
fs,
io::Write,
iter::IntoIterator,
Expand Down Expand Up @@ -228,17 +229,17 @@ impl GenProtos {
}

fn gen_rust_protos(&self, temp_dir: tempfile::TempDir) -> Output {
let venv_bin = self.create_venv(&temp_dir);
let new_path = {
let venv_bin = self.create_venv(&temp_dir);
let mut path: Vec<_> = std::env::split_paths(&std::env::var_os("PATH").unwrap()).collect();
path.insert(0, venv_bin);
path.insert(0, venv_bin.clone());
std::env::join_paths(path).unwrap()
};
dbg!(&new_path);

// Create protoc cmd in the venv
let mut protoc_cmd = Command::new("protoc");
protoc_cmd.env("PATH", new_path);
protoc_cmd.env("PATH", &new_path);
protoc_cmd.env("PYTHONPATH", temp_dir.path());

// Directories that contain protos
Expand All @@ -264,8 +265,24 @@ impl GenProtos {
dbg!(path);
}

protoc_cmd.arg(
[
OsStr::new("--plugin=protoc-gen-rust_pb_jelly="),
venv_bin
.join(if cfg!(windows) {
"protoc-gen-rust.exe"
} else {
"protoc-gen-rust"
})
.as_os_str(),
]
.join(OsStr::new("")),
);

// Set the Rust out path
protoc_cmd.arg("--rust_out");
// (Don't use "rust" as the name of the plugin because protoc now has (broken) upstream Rust support that
// overrides the plugin)
protoc_cmd.arg("--rust_pb_jelly_out");
protoc_cmd.arg(&self.gen_path);

// Get paths of our Protos
Expand Down

0 comments on commit c27c4ea

Please sign in to comment.