Skip to content

Commit

Permalink
docs(network): remove protoc from prerequisites on papyrus readme (#492)
Browse files Browse the repository at this point in the history
* docs(network): remove protoc installation from documentation

* build(protobuf): build proto files without protoc
  • Loading branch information
AlonLStarkWare authored Sep 3, 2024
1 parent 530c04e commit c771d67
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 78 deletions.
97 changes: 82 additions & 15 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 15 additions & 36 deletions crates/papyrus_protobuf/build.rs
Original file line number Diff line number Diff line change
@@ -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::<u32>().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(())
}
1 change: 0 additions & 1 deletion docs/papyrus/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 0 additions & 26 deletions docs/papyrus/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c771d67

Please sign in to comment.