Skip to content

refactor: centralize dependencies and feature-gate stacks-common #6238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions Cargo.lock

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

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ members = [

# Dependencies we want to keep the same between workspace members
[workspace.dependencies]
ed25519-dalek = { version = "2.1.1", features = ["serde", "rand_core"] }
ed25519-dalek = { version = "2.1.1", default-features = false }
hashbrown = { version = "0.15.2", features = ["serde"] }
lazy_static = "1.4.0"
rand_core = "0.6.4"
rand = "0.8"
rand_chacha = "0.3.1"
tikv-jemallocator = "0.5.4"
serde = "1"
serde_derive = "1"
serde_json = { version = "1.0", features = ["arbitrary_precision", "unbounded_depth"] }
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] }
tikv-jemallocator = "0.5.4"
thiserror = "1.0.65"
toml = "0.5.6"

# Use a bit more than default optimization for
# dev builds to speed up test execution
# dev builds to speed up test execution
[profile.dev]
opt-level = 1

# Use release-level optimization for dependencies
# This slows down "first" builds on development environments,
# but won't impact subsequent builds.
# but won't impact subsequent builds.
[profile.dev.package."*"]
opt-level = 3

Expand Down
86 changes: 44 additions & 42 deletions stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,73 +30,75 @@ name = "stacks_common"
path = "./src/libcommon.rs"

[dependencies]
rand = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1"
sha3 = "0.10.1"
chrono = "0.4.19"
curve25519-dalek = { version = "4.1.3", features = ["serde"] }
ed25519-dalek = { workspace = true }
hashbrown = { workspace = true }
lazy_static = { workspace = true }
rand = { workspace = true, optional = true }
ripemd = "0.1.1"
lazy_static = "1.4.0"
slog = { version = "2.5.2", features = ["max_level_trace"] }
serde = { workspace = true , features = ["derive"] }
serde_derive = { workspace = true }
serde_json = { workspace = true }
sha3 = "0.10.1"
slog = { workspace = true }
slog-term = "2.6.0"

# Optional dependencies
slog-json = { version = "2.3.0", optional = true }
chrono = "0.4.19"
hashbrown = { workspace = true }
rusqlite = { workspace = true, optional = true }
getrandom = { version = "0.2", default-features = false, optional = true }

[target.'cfg(unix)'.dependencies]
nix = "0.23"
nix = {version = "0.23", optional = true}

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [
"consoleapi",
"handleapi",
"synchapi",
"winbase",
] }

[target.'cfg(windows)'.dev-dependencies]
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] }

[dependencies.serde_json]
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]

[dependencies.ed25519-dalek]
workspace = true

[dependencies.curve25519-dalek]
version = "4.1.3"
features = ["serde"]

[dependencies.time]
version = "0.2.23"
features = ["std"]
], optional = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
secp256k1 = { version = "0.24.3", features = ["serde", "recovery"] }
rusqlite = { workspace = true, optional = true }

[target.'cfg(target_family = "wasm")'.dependencies]
libsecp256k1 = { version = "0.7.0" }
libsecp256k1 = { version = "0.7.0", default-features = false, features = ["hmac"] }

[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
sha2 = { version = "0.10", features = ["asm"] }

[target.'cfg(any(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")), any(target_os="windows")))'.dependencies]
sha2 = { version = "0.10" }

[dev-dependencies]
rand_core = { workspace = true }
proptest = "1.6.0"

[target.'cfg(windows)'.dev-dependencies]
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] }

[build-dependencies]
toml = { workspace = true }

[features]
default = ["developer-mode"]
default = ["developer-mode", "ctrlc-handler", "http-parser", "rand"]
developer-mode = []
# Enables graceful shutdown handling for Ctrl+C (SIGINT) signals.
# This pulls in the `nix` or `winapi` dependency.
ctrlc-handler = ["dep:nix", "dep:winapi"]
# Enables a lightweight, internal HTTP/1.x parser.
http-parser = []
slog_json = ["slog-json"]
rusqlite = ["dep:rusqlite"]
testing = []
rusqlite = ["dep:rusqlite", "rand"]
# Enables the rand module. This flag must be off on deterministic
# platforms such as CosmWasm
rand = ["dep:rand"]
serde = []
testing = ["rand"]
bech32_std = []
bech32_strict = []

[build-dependencies]
toml = "0.5.6"

[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
sha2 = { version = "0.10", features = ["asm"] }

[target.'cfg(any(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")), any(target_os="windows")))'.dependencies]
sha2 = { version = "0.10" }
# Wasm-specific features for easier configuration
wasm-web = ["rand", "getrandom/js", "libsecp256k1/static-context"]
wasm-deterministic = ["getrandom/custom"]
20 changes: 0 additions & 20 deletions stacks-common/src/deps_common/bitcoin/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub mod hash;

use std::{error, fmt};

use secp256k1;

use crate::deps_common::bitcoin::network;
use crate::deps_common::bitcoin::network::serialize;

Expand Down Expand Up @@ -50,8 +48,6 @@ pub trait BitArray {
/// if appropriate.
#[derive(Debug)]
pub enum Error {
/// secp-related error
Secp256k1(secp256k1::Error),
/// Serialization error
Serialize(serialize::Error),
/// Network error
Expand All @@ -65,7 +61,6 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Secp256k1(ref e) => fmt::Display::fmt(e, f),
Error::Serialize(ref e) => fmt::Display::fmt(e, f),
Error::Network(ref e) => fmt::Display::fmt(e, f),
Error::SpvBadProofOfWork => f.write_str("target correct but not attained"),
Expand All @@ -77,28 +72,13 @@ impl fmt::Display for Error {
impl error::Error for Error {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Error::Secp256k1(ref e) => Some(e),
Error::Serialize(ref e) => Some(e),
Error::Network(ref e) => Some(e),
Error::SpvBadProofOfWork | Error::SpvBadTarget => None,
}
}
}

#[doc(hidden)]
impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Error {
Error::Secp256k1(e)
}
}

#[doc(hidden)]
impl From<serialize::Error> for Error {
fn from(e: serialize::Error) -> Error {
Error::Serialize(e)
}
}

#[doc(hidden)]
impl From<network::Error> for Error {
fn from(e: network::Error) -> Error {
Expand Down
15 changes: 12 additions & 3 deletions stacks-common/src/libcommon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ extern crate slog;
#[macro_use]
extern crate serde_derive;

#[cfg(unix)]
#[cfg(all(unix, feature = "ctrlc-handler"))]
extern crate nix;

#[cfg(windows)]
#[cfg(all(windows, feature = "ctrlc-handler"))]
extern crate winapi;

#[macro_use]
Expand All @@ -29,7 +29,16 @@ pub mod types;

pub mod address;

pub mod deps_common;
pub mod deps_common {
pub mod bech32;
pub mod bitcoin;

#[cfg(all(not(target_family = "wasm"), feature = "ctrlc-handler"))]
pub mod ctrlc;

#[cfg(feature = "http-parser")]
pub mod httparse;
}

pub mod bitvec;

Expand Down
2 changes: 1 addition & 1 deletion stacks-common/src/util/chunked_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ mod test {
use std::io;
use std::io::Read;

use rand::RngCore;
use rand::RngCore as _;

use super::*;

Expand Down
Loading