-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move codegen to separate crate (#1467)
- Loading branch information
Showing
11 changed files
with
102 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "codegen" | ||
authors = ["Lucio Franco <[email protected]>"] | ||
license = "MIT" | ||
edition = "2021" | ||
publish = false | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
tonic-build = {path = "../tonic-build", default-features = false, features = ["prost", "cleanup-markdown"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
// tonic-health | ||
codegen( | ||
&PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.unwrap() | ||
.join("tonic-health"), | ||
&["proto/health.proto"], | ||
&["proto"], | ||
&PathBuf::from("src/generated"), | ||
&PathBuf::from("src/generated/grpc_health_v1.bin"), | ||
true, | ||
true, | ||
); | ||
|
||
// tonic-reflection | ||
codegen( | ||
&PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.unwrap() | ||
.join("tonic-reflection"), | ||
&["proto/reflection.proto"], | ||
&["proto"], | ||
&PathBuf::from("src/generated"), | ||
&PathBuf::from("src/generated/reflection_v1alpha1.bin"), | ||
true, | ||
true, | ||
); | ||
|
||
// tonic-types | ||
codegen( | ||
&PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.unwrap() | ||
.join("tonic-types"), | ||
&["proto/status.proto", "proto/error_details.proto"], | ||
&["proto"], | ||
&PathBuf::from("src/generated"), | ||
&PathBuf::from("src/generated/types.bin"), | ||
false, | ||
false, | ||
); | ||
} | ||
|
||
fn codegen( | ||
root_dir: &PathBuf, | ||
iface_files: &[&str], | ||
include_dirs: &[&str], | ||
out_dir: &PathBuf, | ||
file_descriptor_set_path: &PathBuf, | ||
build_client: bool, | ||
build_server: bool, | ||
) { | ||
let iface_files: Vec<PathBuf> = iface_files | ||
.into_iter() | ||
.map(|&path| root_dir.join(path)) | ||
.collect(); | ||
|
||
let include_dirs: Vec<PathBuf> = include_dirs | ||
.into_iter() | ||
.map(|&path| root_dir.join(path)) | ||
.collect(); | ||
let out_dir = root_dir.join(out_dir); | ||
let file_descriptor_set_path = root_dir.join(file_descriptor_set_path); | ||
|
||
tonic_build::configure() | ||
.build_client(build_client) | ||
.build_server(build_server) | ||
.out_dir(&out_dir) | ||
.file_descriptor_set_path(file_descriptor_set_path) | ||
.compile(&iface_files, &include_dirs) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.