Skip to content

Commit 18625cb

Browse files
committed
Automatically use the protoc version downloaded by the maven plugin
1 parent 9e459f8 commit 18625cb

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

dev/mvn-build-helper/proto/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>com.google.protobuf</groupId>
1818
<artifactId>protobuf-java</artifactId>
19-
<version>3.21.9</version>
19+
<version>${protobufVersion}</version>
2020
</dependency>
2121
</dependencies>
2222

native-engine/blaze-serde/build.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,38 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::{fs, path::PathBuf};
16+
1517
fn main() -> Result<(), String> {
1618
// for use in docker build where file changes can be wonky
1719
println!("cargo:rerun-if-env-changed=FORCE_REBUILD");
1820

1921
println!("cargo:rerun-if-changed=proto/blaze.proto");
20-
tonic_build::compile_protos("proto/blaze.proto")
22+
23+
let mut prost_build = tonic_build::Config::new();
24+
25+
// protobuf-maven-plugin download the protoc executable in the target directory
26+
let protoc_dir_path = "../../dev/mvn-build-helper/proto/target/protoc-plugins";
27+
let mut protoc_file: Option<PathBuf> = None;
28+
if let Ok(entries) = fs::read_dir(protoc_dir_path) {
29+
for entry in entries.filter_map(Result::ok) {
30+
let path = entry.path();
31+
if path.is_file()
32+
&& path
33+
.file_name()
34+
.map(|f| f.to_string_lossy().starts_with("protoc"))
35+
.unwrap_or(false)
36+
{
37+
protoc_file = Some(path);
38+
break;
39+
}
40+
}
41+
}
42+
if let Some(path) = protoc_file {
43+
eprintln!("Using protoc executable: {:?}", path);
44+
prost_build.protoc_executable(path);
45+
}
46+
prost_build
47+
.compile_protos(&["proto/blaze.proto"], &["proto"])
2148
.map_err(|e| format!("protobuf compilation failed: {}", e))
2249
}

0 commit comments

Comments
 (0)