p2p: make arti dependency optional via feature flag #575
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Fixes #542
Make the arti (embedded Tor) dependency tree optional behind an
artiCargo feature flag incuprate-p2p-transportandcuprated. The feature is enabled by default, so existing behavior is unchanged.Why
The arti dependency tree is substantial (dozens of crates including OpenSSL, SQLite, cryptographic libraries). Making it optional allows faster builds and smaller binaries when embedded Tor support is not needed.
We left the default behaviour to be the current behaviour (i.e. Arti is included).
Type/Build Command/Number of dependencies/Executable size
Without Arti/cargo build --release -p cuprated --no-default-features/432/16M
With Arti/cargo build --release -p cuprated/711/33M
The executable size went from 33M to 16M when Arti was excluded. Arti more than doubles the executable size.
Where
p2p/p2p-transport/Cargo.toml— newartifeature, arti/tor-* deps made optionalp2p/p2p-transport/src/lib.rs—mod arti,mod disabled, and their re-exports gated behind#[cfg(feature = "arti")]binaries/cuprated/Cargo.toml— newartifeature (default-enabled),arti-client/tor-hsservice/tor-persist/tor-rtcompatmade optionalbinaries/cuprated/src/tor.rs—TorMode::Artivariant,TorContextarti fields, and arti initialization/transport functions gatedbinaries/cuprated/src/p2p.rs— arti imports andTorMode::Artimatch arms gatedbinaries/cuprated/src/config.rs—TorMode::Artiarms intor_p2p_config()anddry_run_check()gatedbinaries/cuprated/src/config/p2p.rs— removed dead arti imports (arti_client::*,tor_rtcompat::*,cuprate_p2p_transport::{Arti, ArtiClientConfig, ArtiServerConfig})How
All arti/tor-* dependencies are marked
optional = truein bothCargo.tomlfiles and grouped under anartifeature. Incuprate-p2p-transport, the existingstaticfeature now depends onarti(static = ["arti", "arti-client/static"]). Incuprated,artiis default-enabled and also activatescuprate-p2p-transport/arti.All source code that references arti types (
TorMode::Arti,TorClient,OnionService,ArtiClientConfig, etc.) is gated with#[cfg(feature = "arti")]. This includes the enum variant itself, struct fields, function definitions, imports, and match arms.No test modifications were needed. There are no tests in
cuprate-p2p-transport, and thecupratedconfig tests (documented_config,test_read_from_path,test_check_file_permissions) don't reference arti-specific types. The serde round-trip tests work with the feature off becauseTorModedefaults toOff, so theArtivariant is never serialized or deserialized.Verified:
cargo check -p cuprated --no-default-featuresbuilds without articargo check -p cupratedbuilds with arti (default)cargo tree -p cuprated --no-default-features | grep artireturns emptycargo clippy -p cuprate-p2p-transport --all-features -- -D warningspassescargo clippy -p cuprate-p2p-transport --no-default-features -- -D warningspassescargo test -p cuprated --no-default-features -- config::testpassescargo test -p cuprated -- config::testpassesAll the CI checks were also run. They had a few warnings that were also present when run on the main branch. Some of these warnings (missing imports, type name instead of Self) have also been corrected in this PR.