From 1aab9f71bb7811a122d73d2588fe4e16d8eecc7b Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 13 Feb 2023 18:21:21 +0300 Subject: [PATCH] feat(libp2p): Optional async std libp2p & debug profile (#1454) * feat: Make an async-std optional * build: Profile selection based on label --------- Co-authored-by: Anatoly Laskaris --- .github/workflows/snapshot.yml | 19 ++++++++++++++++--- Cargo.toml | 6 ++++++ crates/libp2p/Cargo.toml | 6 ++++-- crates/libp2p/src/lib.rs | 2 ++ crates/server-config/Cargo.toml | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index eb09e424ff..6541d74e08 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -38,9 +38,22 @@ jobs: repository: fluencelabs/rust-peer ref: ${{ inputs.ref }} + - name: Get PR labels + id: labels + uses: joerick/pr-labels-action@v1.0.7 + - name: Setup Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Set profile + id: profile + run: | + if [[ -n "$GITHUB_PR_LABEL_PROFILING" ]]; then + echo "profile=profiling" >> $GITHUB_OUTPUT + else + echo "profile=release" >> $GITHUB_OUTPUT + fi + - name: Set dependencies if: inputs.cargo-dependencies != '' uses: fluencelabs/github-actions/cargo-set-dependency@main @@ -59,11 +72,11 @@ jobs: publish: false - name: Run cargo build - run: cargo build --release -p particle-node + run: cargo build --profile ${{ steps.profile.outputs.profile }} -p particle-node - name: Calculate SHA256 id: sha - working-directory: ./target/release + working-directory: ./target/${{ steps.profile.outputs.profile }} run: | # Calculate sha256 du -hs particle-node @@ -75,7 +88,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: rust-peer - path: target/release/particle-node + path: target/${{ steps.profile.outputs.profile }}/particle-node container: needs: build diff --git a/Cargo.toml b/Cargo.toml index b1efd7f205..58c1ba4ede 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -134,3 +134,9 @@ debug-assertions = false strip = true lto = false codegen-units = 1 # Reduce number of codegen units to increase optimizations + +[profile.profiling] +inherits = "release" +debug = true +strip = false +lto = false diff --git a/crates/libp2p/Cargo.toml b/crates/libp2p/Cargo.toml index 0fb8d0fcb8..c5b75f7da3 100644 --- a/crates/libp2p/Cargo.toml +++ b/crates/libp2p/Cargo.toml @@ -4,14 +4,16 @@ version = "0.2.0" authors = ["Fluence Labs"] edition = "2021" +[features] +async-std = ["dep:async-std"] + [dependencies] libp2p = { workspace = true } libp2p-noise = { workspace = true } multihash = { version = "0.16.3", features = ["serde-codec"] } futures = { workspace = true } futures-util = "0.3.26" -async-std = { workspace = true } - +async-std = { workspace = true, optional = true } serde = { version = "1.0.152", features = ["derive"] } serde_json = { workspace = true } bs58 = { workspace = true } diff --git a/crates/libp2p/src/lib.rs b/crates/libp2p/src/lib.rs index 853753d43c..8194751da1 100644 --- a/crates/libp2p/src/lib.rs +++ b/crates/libp2p/src/lib.rs @@ -31,6 +31,7 @@ mod macros; pub mod random_multiaddr; mod random_peer_id; mod serde; +#[cfg(feature = "async-std")] mod transport; pub mod types; @@ -38,6 +39,7 @@ pub use self::serde::*; pub use connected_point::*; pub use macros::*; pub use random_peer_id::RandomPeerId; +#[cfg(feature = "async-std")] pub use transport::{build_memory_transport, build_transport, Transport}; // libp2p reexports diff --git a/crates/server-config/Cargo.toml b/crates/server-config/Cargo.toml index ee153225c2..4b09b3e01a 100644 --- a/crates/server-config/Cargo.toml +++ b/crates/server-config/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" config-utils = { workspace = true } fs-utils = { workspace = true } particle-protocol = { workspace = true } -fluence-libp2p = { workspace = true } +fluence-libp2p = { workspace = true, features=["async-std"] } air-interpreter-fs = { workspace = true } peer-metrics = { workspace = true }