From c771d67013a4e0a5660c14d0293ce31902b78ead Mon Sep 17 00:00:00 2001 From: Alon-Lukatch-Starkware Date: Tue, 3 Sep 2024 15:49:47 +0300 Subject: [PATCH] docs(network): remove protoc from prerequisites on papyrus readme (#492) * docs(network): remove protoc installation from documentation * build(protobuf): build proto files without protoc --- Cargo.lock | 97 +++++++++++++++++++++++++----- Cargo.toml | 1 + crates/papyrus_protobuf/Cargo.toml | 1 + crates/papyrus_protobuf/build.rs | 51 +++++----------- docs/papyrus/CONTRIBUTING.md | 1 - docs/papyrus/README.adoc | 26 -------- 6 files changed, 99 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65a3ce1160..7857865ce0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3432,7 +3432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35bd3cf68c183738046838e300353e4716c674dc5e56890de4826801a6622a28" dependencies = [ "futures-io", - "rustls", + "rustls 0.21.12", ] [[package]] @@ -3966,7 +3966,7 @@ dependencies = [ "http", "hyper", "log", - "rustls", + "rustls 0.21.12", "rustls-native-certs", "tokio", "tokio-rustls", @@ -4397,7 +4397,7 @@ dependencies = [ "tokio-util", "tracing", "url", - "webpki-roots", + "webpki-roots 0.25.4", ] [[package]] @@ -5008,7 +5008,7 @@ dependencies = [ "quinn", "rand 0.8.5", "ring 0.16.20", - "rustls", + "rustls 0.21.12", "socket2 0.5.7", "thiserror", "tokio", @@ -5101,8 +5101,8 @@ dependencies = [ "libp2p-identity", "rcgen", "ring 0.16.20", - "rustls", - "rustls-webpki", + "rustls 0.21.12", + "rustls-webpki 0.101.7", "thiserror", "x509-parser", "yasna", @@ -6422,6 +6422,7 @@ dependencies = [ "primitive-types", "prost", "prost-build", + "protoc-prebuilt", "rand 0.8.5", "rand_chacha 0.3.1", "starknet-types-core", @@ -7249,6 +7250,16 @@ dependencies = [ "prost", ] +[[package]] +name = "protoc-prebuilt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d85d4641fe3b8c6e853dfd09fe35379bc6b6e66bd692ac29ed4f7087de69ed5" +dependencies = [ + "ureq", + "zip", +] + [[package]] name = "psl-types" version = "2.0.11" @@ -7407,7 +7418,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls", + "rustls 0.21.12", "thiserror", "tokio", "tracing", @@ -7423,7 +7434,7 @@ dependencies = [ "rand 0.8.5", "ring 0.16.20", "rustc-hash", - "rustls", + "rustls 0.21.12", "slab", "thiserror", "tinyvec", @@ -7791,7 +7802,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.12", "rustls-pemfile", "serde", "serde_json", @@ -7807,7 +7818,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.25.4", "winreg", ] @@ -8030,10 +8041,25 @@ checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.8", - "rustls-webpki", + "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.23.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +dependencies = [ + "log", + "once_cell", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.6", + "subtle", + "zeroize", +] + [[package]] name = "rustls-native-certs" version = "0.6.3" @@ -8055,6 +8081,12 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -8065,6 +8097,17 @@ dependencies = [ "untrusted 0.9.0", ] +[[package]] +name = "rustls-webpki" +version = "0.102.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +dependencies = [ + "ring 0.17.8", + "rustls-pki-types", + "untrusted 0.9.0", +] + [[package]] name = "rustversion" version = "1.0.16" @@ -9636,7 +9679,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.12", "tokio", ] @@ -9672,11 +9715,11 @@ checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" dependencies = [ "futures-util", "log", - "rustls", + "rustls 0.21.12", "tokio", "tokio-rustls", "tungstenite", - "webpki-roots", + "webpki-roots 0.25.4", ] [[package]] @@ -9894,7 +9937,7 @@ dependencies = [ "httparse", "log", "rand 0.8.5", - "rustls", + "rustls 0.21.12", "sha1", "thiserror", "url", @@ -10011,6 +10054,21 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +dependencies = [ + "base64 0.22.1", + "log", + "once_cell", + "rustls 0.23.12", + "rustls-pki-types", + "url", + "webpki-roots 0.26.3", +] + [[package]] name = "url" version = "2.5.0" @@ -10248,6 +10306,15 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "webpki-roots" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "which" version = "4.4.2" diff --git a/Cargo.toml b/Cargo.toml index 627b66779f..84f26f225f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,6 +157,7 @@ prometheus-parse = "0.2.4" prost = "0.12.1" prost-build = "0.12.1" prost-types = "0.12.1" +protoc-prebuilt = "0.3.0" pyo3 = "0.19.1" pyo3-log = "0.8.1" quote = "1.0.26" diff --git a/crates/papyrus_protobuf/Cargo.toml b/crates/papyrus_protobuf/Cargo.toml index dc25349a9f..ba64e61d25 100644 --- a/crates/papyrus_protobuf/Cargo.toml +++ b/crates/papyrus_protobuf/Cargo.toml @@ -28,6 +28,7 @@ papyrus_test_utils.workspace = true [build-dependencies] prost-build.workspace = true +protoc-prebuilt.workspace = true [package.metadata.cargo-machete] # The `rand` and `rand_chacha` crates are used in the `testing` feature, which is optional. diff --git a/crates/papyrus_protobuf/build.rs b/crates/papyrus_protobuf/build.rs index 91475765f3..b6ed6bca55 100644 --- a/crates/papyrus_protobuf/build.rs +++ b/crates/papyrus_protobuf/build.rs @@ -1,41 +1,20 @@ use std::env; -use std::io::{Error, ErrorKind, Result}; -use std::process::Command; +use std::io::Result; fn main() -> Result<()> { println!("Building"); - let protoc = env::var("PROTOC").unwrap_or("protoc".to_string()); - - let protoc_version = String::from_utf8_lossy( - &Command::new(protoc).arg("--version").output().expect("Protoc is not installed.").stdout, - ) - .to_string(); - - let parts: Vec<&str> = protoc_version.split_whitespace().collect(); - let protoc_version_str = parts.get(1).expect("Failed to determine protoc version"); - let mut protoc_version_parts = protoc_version_str - .split('.') - .map(|part| part.parse::().expect("Error parsing protoc version")); - let major = protoc_version_parts.next().expect("Protoc version did not have a major number"); - let minor = protoc_version_parts.next().unwrap_or_default(); - - if major < 3 || (major == 3 && minor < 15) { - Err(Error::new( - ErrorKind::Other, - "protoc version is too old. version 3.15.x or greater is needed.", - )) - } else { - prost_build::compile_protos( - &[ - "src/proto/p2p/proto/class.proto", - "src/proto/p2p/proto/event.proto", - "src/proto/p2p/proto/header.proto", - "src/proto/p2p/proto/state.proto", - "src/proto/p2p/proto/transaction.proto", - "src/proto/p2p/proto/consensus.proto", - ], - &["src/proto/"], - )?; - Ok(()) - } + let (protoc_bin, _) = protoc_prebuilt::init("27.0").unwrap(); + env::set_var("PROTOC", protoc_bin); + prost_build::compile_protos( + &[ + "src/proto/p2p/proto/class.proto", + "src/proto/p2p/proto/event.proto", + "src/proto/p2p/proto/header.proto", + "src/proto/p2p/proto/state.proto", + "src/proto/p2p/proto/transaction.proto", + "src/proto/p2p/proto/consensus.proto", + ], + &["src/proto/"], + )?; + Ok(()) } diff --git a/docs/papyrus/CONTRIBUTING.md b/docs/papyrus/CONTRIBUTING.md index 9678574379..57cce3dba0 100644 --- a/docs/papyrus/CONTRIBUTING.md +++ b/docs/papyrus/CONTRIBUTING.md @@ -47,7 +47,6 @@ Then, you will need to install - [Ganache 7.4.3](https://www.npmjs.com/package/ganache) - You'll need to install 7.4.3 and not a version above it. We'll relax this in the future. - You'll need Ganache only for the tests of the [papyrus_base_layer](../../crates/papyrus_base_layer/) crate. -- Protoc - follow the installation instructions in our [Prerequisites](../papyrus/README.adoc#Prerequisites). ### CI Your code will need to pass [CI](../.github/workflows/ci.yml) before it can be merged. This means your code will need to: diff --git a/docs/papyrus/README.adoc b/docs/papyrus/README.adoc index 07474f0986..3d921b726b 100644 --- a/docs/papyrus/README.adoc +++ b/docs/papyrus/README.adoc @@ -46,32 +46,6 @@ Use it at your own risk. * https://www.rust-lang.org/tools/install[Rust] must be installed. Minimum supported version is `1.76`. * You must have access to an Ethereum node. For example, you can use a node provider such as Infura. -* link: https://grpc.io/docs/protoc-installation[Protoc] - - You'll need Protoc only for compiling the link:../crates/papyrus_network/[papyrus_network] crate. - - Make sure you have version 15 or higher installed. If not: - 1. Remove your current Protoc installation: -+ -[source,bash] ----- -sudo apt remove protoc/protobuf-compiler ----- - - 2. Install version 15 or higher (replace DIR with your preferred installation directory): -+ -[source,bash] ----- -DIR="$HOME/.local" -curl -L "https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protoc-25.1-linux-x86_64.zip" -o protoc.zip -unzip ./protoc.zip -d $DIR -rm ./protoc.zip ----- - - 3. Add DIR to your PATH if it's not already there: -+ -[source,bash] ----- -export PATH=$PATH:$DIR/bin ----- [discrete] ==== Procedure