Skip to content

Commit

Permalink
Fix proto out_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tinrab committed Nov 14, 2023
1 parent 584ee08 commit f0b6b21
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 48 deletions.
5 changes: 3 additions & 2 deletions bomboni_prost/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ pub struct ApiConfig {
impl Default for CompileConfig {
fn default() -> Self {
Self {
file_descriptor_set_path: Default::default(),
output_path: Default::default(),
file_descriptor_set_path: PathBuf::from(std::env::var("OUT_DIR").unwrap())
.join("fd.pb"),
output_path: std::env::var("OUT_DIR").unwrap().into(),
format: true,
api: Default::default(),
}
Expand Down
12 changes: 4 additions & 8 deletions bomboni_proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ use bomboni_prost::{
};

fn main() -> Result<(), Box<dyn Error + 'static>> {
let fd_path = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("fd.pb");

#[cfg(feature = "testing")]
{
let mut config = prost_build::Config::new();
config
.file_descriptor_set_path("./tests/proto/fd.pb")
.out_dir("./tests/proto")
.file_descriptor_set_path(fd_path.clone())
.protoc_arg("--experimental_allow_proto3_optional")
.btree_map(["."])
.compile_protos(&["./tests/proto/tools.proto"], &["./tests/proto/"])?;

compile(CompileConfig {
file_descriptor_set_path: "./tests/proto/fd.pb".into(),
output_path: "./tests/proto".into(),
..Default::default()
})?;
}
Expand All @@ -44,8 +43,7 @@ fn main() -> Result<(), Box<dyn Error + 'static>> {

let mut config = prost_build::Config::new();
config
.out_dir("./src")
.file_descriptor_set_path("./src/fd.pb")
.file_descriptor_set_path(fd_path)
.compile_well_known_types()
.protoc_arg("--experimental_allow_proto3_optional")
.btree_map(["."]);
Expand Down Expand Up @@ -83,8 +81,6 @@ fn main() -> Result<(), Box<dyn Error + 'static>> {

config.compile_protos(&proto_paths, &["./proto"])?;
compile(CompileConfig {
file_descriptor_set_path: "./src/fd.pb".into(),
output_path: "./src".into(),
api: ApiConfig {
domain: Some("type.googleapis.com".into()),
..Default::default()
Expand Down
2 changes: 0 additions & 2 deletions bomboni_proto/src/.gitignore

This file was deleted.

Binary file removed bomboni_proto/src/fd.pb
Binary file not shown.
2 changes: 0 additions & 2 deletions bomboni_proto/src/google/mod.rs

This file was deleted.

9 changes: 0 additions & 9 deletions bomboni_proto/src/google/protobuf/mod.rs

This file was deleted.

4 changes: 0 additions & 4 deletions bomboni_proto/src/google/rpc/mod.rs

This file was deleted.

37 changes: 36 additions & 1 deletion bomboni_proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
pub mod google;
mod protobuf;
mod rpc;
pub mod serde;

/// Includes generated protobuf code.
/// Base path is specified with OUT_DIR environment variable.
#[macro_export]
macro_rules! include_proto {
($package: tt) => {
include!(concat!(env!("OUT_DIR"), concat!("/", $package, ".rs")));
};
}

/// Includes generated protobuf file descriptor set.
#[macro_export]
macro_rules! include_file_descriptor_set {
() => {
include_file_descriptor_set!("fd");
};
($name:tt) => {
include_bytes!(concat!(env!("OUT_DIR"), concat!("/", $name, ".fd")));
};
}

#[allow(unused_qualifications)]
pub mod google {
pub mod protobuf {
pub use super::super::protobuf::*;
crate::include_proto!("google.protobuf");
crate::include_proto!("google.protobuf.plus");
}
pub mod rpc {
pub use super::super::rpc::*;
crate::include_proto!("google.rpc");
crate::include_proto!("google.rpc.plus");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::google::protobuf::Any;
use prost::{DecodeError, EncodeError, Message, Name};

use super::Any;

impl Any {
pub fn new(type_url: String, value: Vec<u8>) -> Self {
Any { type_url, value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
};
use thiserror::Error;

use super::Duration;
use crate::google::protobuf::Duration;

#[derive(Error, Debug)]
pub enum DurationError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::google::protobuf::Empty;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use super::Empty;

impl Empty {
pub fn new() -> Self {
Empty {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::serde::helpers as serde_helpers;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use super::FieldMask;
use crate::google::protobuf::FieldMask;

impl FieldMask {
pub fn new(paths: Vec<String>) -> Self {
Expand Down
6 changes: 6 additions & 0 deletions bomboni_proto/src/protobuf/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod any;
mod duration;
mod empty;
mod field_mask;
mod timestamp;
mod wrappers;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

use thiserror::Error;

use super::Timestamp;
use crate::google::protobuf::Timestamp;

#[derive(Error, Debug)]
pub enum TimestampError {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions bomboni_proto/src/rpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod status;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::google::protobuf::Any;

use super::{Code, Status};
use crate::google::rpc::{Code, Status};

impl Status {
pub fn new(code: Code, message: String, details: Vec<Any>) -> Self {
Expand Down
1 change: 0 additions & 1 deletion bomboni_proto/src/serde/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;

use std::str::FromStr;

pub fn is_default<T>(value: &T) -> bool
Expand Down
18 changes: 11 additions & 7 deletions bomboni_proto/tests/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ use crate::tools::{
},
CommandRequest, ServingStatus,
};
use bomboni_proto::include_proto;

#[allow(clippy::module_inception)]
#[allow(unused_qualifications, clippy::module_inception)]
pub mod tools {
use super::*;
include_proto!("tools");
include_proto!("tools.plus");
pub mod command {
include!("./proto/tools.command.rs");
include!("./proto/tools.command.plus.rs");
use super::*;
include_proto!("tools.command");
include_proto!("tools.command.plus");
}
pub mod perms {
include!("./proto/tools.perms.rs");
include!("./proto/tools.perms.plus.rs");
use super::*;
include_proto!("tools.perms");
include_proto!("tools.perms.plus");
}
include!("./proto/tools.rs");
include!("./proto/tools.plus.rs");
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions bomboni_proto/tests/proto/.gitignore

This file was deleted.

0 comments on commit f0b6b21

Please sign in to comment.