Skip to content

Commit

Permalink
build(proto): move build script to separate pkg (#30)
Browse files Browse the repository at this point in the history
It was impossible to publish the `archway-proto` crate because it
depends on the `archway-network` submodule, which is unavailable during
the isolated build process.

Following the same approach as `cosmos-rust` and other projects, moving
the proto compilation from the `build.rs` script in the package to a
standalone binary was necessary.
  • Loading branch information
aelesbao authored Oct 16, 2023
1 parent 86a2f61 commit 3c4d058
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
14 changes: 10 additions & 4 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[workspace]
members = ["packages/*", "contracts/*"]
members = [
"packages/*",
"contracts/*",
"proto-build"
]
resolver = "2"

[workspace.package]
Expand Down
6 changes: 0 additions & 6 deletions packages/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ tonic = { version = "0.9.2", optional = true, default-features = false, features
# [email protected] is the latest version for the cosmos-sdk 0.45.x protos
cosmos-sdk-proto = { version = "0.18.0", default-features = false }

[build-dependencies]
error-chain = "0.12.4"
glob = "0.3.1"
regex = "1.9.3"
tonic-build = "0.9.2"

[features]
default = ["grpc-transport"]
grpc-transport = ["grpc", "tonic/transport", "cosmos-sdk-proto/grpc-transport"]
Expand Down
16 changes: 16 additions & 0 deletions proto-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "proto-build"
version = "0.1.0"
edition = "2021"
description = "Build script for archway-proto"
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
publish = false

[dependencies]
error-chain = "0.12.4"
glob = "0.3.1"
regex = "1.9.3"
tonic-build = "0.9.2"
19 changes: 11 additions & 8 deletions packages/proto/build.rs → proto-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use glob::glob;
use regex::Regex;

const ARCHWAY_DIR: &str = "archway-network";

const OUT_DIR: &str = "src/proto";
const OUT_DIR: &str = "packages/proto/src/proto";

const EXCLUDED_PROTO_PACKAGES: &[&str] = &["google"];

Expand All @@ -26,10 +25,13 @@ error_chain! {

fn main() -> Result<()> {
let archway_dir = format!("{}/{}", workspace_root()?, ARCHWAY_DIR);
compile_proto(archway_dir.as_str())?;
cleanup(OUT_DIR)?;
apply_patches(OUT_DIR)?;
output_protocol_version(OUT_DIR, archway_dir.as_str())?;
let out_dir = format!("{}/{}", workspace_root()?, OUT_DIR);

compile_proto(out_dir.as_str(), archway_dir.as_str())?;
cleanup(out_dir.as_str())?;
apply_patches(out_dir.as_str())?;
output_protocol_version(out_dir.as_str(), archway_dir.as_str())?;

Ok(())
}

Expand All @@ -43,7 +45,7 @@ fn workspace_root() -> Result<String> {
Ok(workspace_root.to_string_lossy().to_string())
}

fn compile_proto(archway_dir: &str) -> Result<()> {
fn compile_proto(out_dir: &str, archway_dir: &str) -> Result<()> {
let archway_proto_dir = format!("{}/proto", archway_dir);
let protos = collect_proto_files(archway_proto_dir.as_str())?;
let includes = &[
Expand All @@ -60,7 +62,8 @@ fn compile_proto(archway_dir: &str) -> Result<()> {
.client_mod_attribute(".", "#[cfg_attr(docsrs, doc(cfg(feature = \"grpc\")))]")
.server_mod_attribute(".", "#[cfg(feature = \"grpc\")]")
.server_mod_attribute(".", "#[cfg_attr(docsrs, doc(cfg(feature = \"grpc\")))]")
.out_dir(OUT_DIR)
.emit_rerun_if_changed(false)
.out_dir(out_dir)
.compile(protos.as_slice(), includes)?;

Ok(())
Expand Down

0 comments on commit 3c4d058

Please sign in to comment.