Skip to content

Commit

Permalink
feat: fallback to protobuf vendored crate in the event protoc is not …
Browse files Browse the repository at this point in the history
…available
  • Loading branch information
khorshuheng committed Jul 22, 2024
1 parent b525cd2 commit 8ce39d4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions collab-entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ prost = "0.12"
[build-dependencies]
prost-build = "0.12"
walkdir = ">=2.0.0"
protoc-bin-vendored = "3.0.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }


15 changes: 11 additions & 4 deletions collab-entity/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ use std::io::Result;
use std::process::Command;
use walkdir::WalkDir;

fn compile_proto_files(proto_files: &[String]) -> Result<()> {
prost_build::Config::new()
.protoc_arg("--experimental_allow_proto3_optional")
.out_dir("src/proto")
.compile_protos(proto_files, &["proto/"])
}

fn main() -> Result<()> {
let mut proto_files = Vec::new();
for e in WalkDir::new("proto").into_iter().filter_map(|e| e.ok()) {
Expand All @@ -10,10 +17,10 @@ fn main() -> Result<()> {
}
}

prost_build::Config::new()
.protoc_arg("--experimental_allow_proto3_optional")
.out_dir("src/proto")
.compile_protos(&proto_files, &["proto/"])?;
if compile_proto_files(&proto_files).is_err() {
std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap());
compile_proto_files(&proto_files)?
}

let generated_files = std::fs::read_dir("src/proto")?
.filter_map(Result::ok)
Expand Down

0 comments on commit 8ce39d4

Please sign in to comment.