From 3c4d0580da925d6acd521da100891fd5b99fbd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augusto=20Elesb=C3=A3o?= Date: Mon, 16 Oct 2023 17:59:38 +0200 Subject: [PATCH] build(proto): move build script to separate pkg (#30) 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. --- Cargo.lock | 14 ++++++++++---- Cargo.toml | 6 +++++- packages/proto/Cargo.toml | 6 ------ proto-build/Cargo.toml | 16 ++++++++++++++++ .../proto/build.rs => proto-build/src/main.rs | 19 +++++++++++-------- 5 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 proto-build/Cargo.toml rename packages/proto/build.rs => proto-build/src/main.rs (90%) diff --git a/Cargo.lock b/Cargo.lock index 4312137..4f9371f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,13 +59,9 @@ name = "archway-proto" version = "0.1.0" dependencies = [ "cosmos-sdk-proto", - "error-chain", - "glob", "prost", "prost-types", - "regex", "tonic", - "tonic-build", ] [[package]] @@ -1120,6 +1116,16 @@ dependencies = [ "prost", ] +[[package]] +name = "proto-build" +version = "0.1.0" +dependencies = [ + "error-chain", + "glob", + "regex", + "tonic-build", +] + [[package]] name = "quote" version = "1.0.33" diff --git a/Cargo.toml b/Cargo.toml index 864f802..6ba6239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,9 @@ [workspace] -members = ["packages/*", "contracts/*"] +members = [ + "packages/*", + "contracts/*", + "proto-build" +] resolver = "2" [workspace.package] diff --git a/packages/proto/Cargo.toml b/packages/proto/Cargo.toml index ace9ac2..7a5e1de 100644 --- a/packages/proto/Cargo.toml +++ b/packages/proto/Cargo.toml @@ -30,12 +30,6 @@ tonic = { version = "0.9.2", optional = true, default-features = false, features # cosmos-sdk-proto@0.18.0 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"] diff --git a/proto-build/Cargo.toml b/proto-build/Cargo.toml new file mode 100644 index 0000000..1222e12 --- /dev/null +++ b/proto-build/Cargo.toml @@ -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" diff --git a/packages/proto/build.rs b/proto-build/src/main.rs similarity index 90% rename from packages/proto/build.rs rename to proto-build/src/main.rs index 9eb12a6..c1754e2 100644 --- a/packages/proto/build.rs +++ b/proto-build/src/main.rs @@ -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"]; @@ -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(()) } @@ -43,7 +45,7 @@ fn workspace_root() -> Result { 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 = &[ @@ -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(())