Skip to content

Commit

Permalink
Skipping protobuf code generation on docs.rs (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Lambrecht <[email protected]>
  • Loading branch information
maxlambrecht authored Mar 7, 2024
1 parent 7e18d55 commit 68f5dc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
25 changes: 16 additions & 9 deletions spiffe/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use std::fs;
use std::{env, fs};

fn main() -> Result<(), anyhow::Error> {
let mut proto_config = prost_build::Config::new();
proto_config.bytes(["."]);
tonic_build::configure()
.build_client(true)
.out_dir("src/proto")
.compile_with_config(proto_config, &["src/proto/workload.proto"], &["src/proto"])?;

fs::rename("src/proto/_.rs", "src/proto/workload.rs")?;
// Check if this is a docs.rs build
let is_docs_rs = env::var_os("DOCS_RS").is_some();

if !is_docs_rs {
let mut proto_config = prost_build::Config::new();
proto_config.bytes(["."]);
tonic_build::configure()
.build_client(true)
.out_dir("src/proto")
.compile_with_config(proto_config, &["src/proto/workload.proto"], &["src/proto"])?;

fs::rename("src/proto/_.rs", "src/proto/workload.rs")?;
} else {
println!("cargo:warning=Skipping protobuf code generation on docs.rs.");
}

Ok(())
}
29 changes: 19 additions & 10 deletions spire-api/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use std::env;

fn main() -> Result<(), anyhow::Error> {
let mut proto_config = prost_build::Config::new();
proto_config.bytes(["."]);
tonic_build::configure()
.build_client(true)
.out_dir("src/proto")
.compile_with_config(
proto_config,
&["spire-api-sdk/proto/spire/api/agent/delegatedidentity/v1/delegatedidentity.proto"],
&["spire-api-sdk/proto"],
)?;
// Check if this is a docs.rs build
let is_docs_rs = env::var_os("DOCS_RS").is_some();

if !is_docs_rs {
let mut proto_config = prost_build::Config::new();
proto_config.bytes(["."]);
tonic_build::configure()
.build_client(true)
.out_dir("src/proto")
.compile_with_config(
proto_config,
&["spire-api-sdk/proto/spire/api/agent/delegatedidentity/v1/delegatedidentity.proto"],
&["spire-api-sdk/proto"],
)?;
} else {
println!("cargo:warning=Skipping protobuf code generation on docs.rs.");
}

Ok(())
}

0 comments on commit 68f5dc6

Please sign in to comment.