Skip to content
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

refactor: rework wasm conditional compilation #1704

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ version = "2.15.1"

[workspace.dependencies]
clarity = { git = "https://github.com/stacks-network/stacks-core.git", branch="feat/clarity-wasm-develop", package = "clarity", default-features = false }
pox-locking = { git = "https://github.com/stacks-network/stacks-core.git", branch="feat/clarity-wasm-develop", package = "pox-locking", default-features = false }
reqwest = { version = "0.12", default-features = false, features = [
"json",
"rustls-tls",
Expand Down
25 changes: 12 additions & 13 deletions components/clarinet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ categories = [

[dependencies]
colored = { workspace = true }
clap = { version = "4.4.8", features = ["derive"], optional = true }
clap_complete = { version = "4.4.4", optional = true }
toml = { version = "0.5.6", features = ["preserve_order"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde_derive = "1"
tokio = { version = "1.35.1", features = ["full"] }
crossterm = "0.27.0"
ratatui = { version = "0.27.0", default-features = false, features = ["crossterm"] }
segment = { version = "0.2.4", optional = true }
mac_address = { version = "1.1.2", optional = true }
tower-lsp = { version = "0.19.0", optional = true }
similar = "2.1.0"
crossbeam-channel = "0.5.6"

clarity-repl = { package = "clarity-repl", path = "../clarity-repl", features = [
"cli",
] }
clarinet-files = { path = "../clarinet-files", features = ["cli"] }
clarity-lsp = { path = "../clarity-lsp", features = ["cli"] }
clarity-repl = { package = "clarity-repl", path = "../clarity-repl" }
clarinet-files = { path = "../clarinet-files" }
clarity-lsp = { path = "../clarity-lsp" }
clarinet-format = { path = "../clarinet-format" }
clarinet-deployments = { path = "../clarinet-deployments", features = ["cli"] }
clarinet-deployments = { path = "../clarinet-deployments" }
hiro-system-kit = { path = "../hiro-system-kit" }
stacks-network = { path = "../stacks-network" }

[target.'cfg(unix)'.dependencies]
nix = "=0.24.2"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { version = "4.4.8", features = ["derive"] }
clap_complete = { version = "4.4.4" }
tower-lsp = { version = "0.19.0" }
segment = { version = "0.2.4", optional = true }
mac_address = { version = "1.1.2", optional = true }

[target.'cfg(windows)'.dependencies]
fwdansi = "1.1.0"
winapi = { version = "0.3.9", features = [
Expand Down Expand Up @@ -78,6 +78,5 @@ name = "clarinet"
path = "src/bin.rs"

[features]
default = ["cli", "telemetry"]
cli = ["clap", "clap_complete", "tower-lsp"]
default = ["telemetry"]
telemetry = ["segment", "mac_address"]
4 changes: 2 additions & 2 deletions components/clarinet-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod deployments;
pub mod generate;

pub mod devnet;
#[cfg(feature = "cli")]
#[cfg(not(target_arch = "wasm32"))]
pub mod frontend;
#[cfg(feature = "cli")]
#[cfg(not(target_arch = "wasm32"))]
pub mod lsp;
41 changes: 13 additions & 28 deletions components/clarinet-deployments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,27 @@ edition = "2021"

[dependencies]
colored = { workspace = true }
base64 = "0.21.3"
serde = "1"
serde_json = "1.0.123"
serde_derive = "1"
serde_yaml = "0.8.23"
rand = "0.8.5"

clarity-repl = { path = "../clarity-repl", default-features = false, optional = true }
clarinet-files = { path = "../clarinet-files", default-features = false }
stacks-rpc-client = { path = "../stacks-rpc-client", optional = true }
clarinet-utils = { path = "../clarinet-utils", optional = true }
stacks-codec = { path = "../stacks-codec", optional = true }

# CLI
reqwest = { workspace = true }
bitcoin = { version = "0.31.2", optional = true }
bitcoincore-rpc = { version = "0.18.0", optional = true }
bitcoincore-rpc-json = { version = "0.18.0", optional = true }
base58 = { version = "0.2.0", optional = true }
base64 = "0.21.3"
libsecp256k1 = { version = "0.7.0", optional = true }

clarity = { workspace = true }

[features]
default = ["cli"]
cli = ["clarity-repl/sdk", "clarinet-files/cli", "stacks-codec", "onchain"]
wasm = ["clarity-repl/wasm", "clarinet-files/wasm"]
onchain = [
"stacks-rpc-client",
"bitcoin",
"bitcoincore-rpc",
"bitcoincore-rpc-json",
"base58",
"libsecp256k1",
"clarinet-utils",
]
clarity-repl = { path = "../clarity-repl", default-features = false }
clarinet-files = { path = "../clarinet-files" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bitcoin = "0.31.2"
bitcoincore-rpc = "0.18.0"
bitcoincore-rpc-json = "0.18.0"
base58 = "0.2.0"
libsecp256k1 = "0.7.0"
clarinet-utils = { path = "../clarinet-utils" }
stacks-codec = { path = "../stacks-codec" }
stacks-rpc-client = { path = "../stacks-rpc-client" }

[lib]
name = "clarinet_deployments"
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate serde;
extern crate serde_derive;

pub mod diagnostic_digest;
#[cfg(feature = "onchain")]
#[cfg(not(target_arch = "wasm32"))]
pub mod onchain;
pub mod requirements;
pub mod types;
Expand Down
36 changes: 12 additions & 24 deletions components/clarinet-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,27 @@ description = "Clarinet manifests files helpers"
license = "GPL-3.0"

[dependencies]
dirs = "6.0"
libsecp256k1 = "0.7.0"
serde = "1"
serde_derive = "1"
serde_json = "1.0.114"
toml = { version = "0.5.6", features = ["preserve_order"] }
url = { version = "2.2.2", features = ["serde"] }
bitcoin = { version = "0.31.2", optional = true }
libsecp256k1 = "0.7.0"
dirs = "6.0"

clarity = { workspace = true }

clarinet-utils = { version = "1", path = "../clarinet-utils" }
clarity-repl = { path = "../clarity-repl", default-features = false, optional = true }

# wasm
js-sys = { version = "0.3", optional = true }
serde-wasm-bindgen = { version = "0.6.4", optional = true }
wasm-bindgen = { workspace = true, optional = true }
wasm-bindgen-futures = { workspace = true, optional = true }
serde_json = "1.0.114"
web-sys = { workspace = true, features = ["console"], optional = true }
clarity-repl = { path = "../clarity-repl", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bitcoin = { version = "0.31.2" }

[features]
default = ["cli"]
cli = ["bitcoin", "clarity-repl/sdk"]
wasm = [
"js-sys",
"web-sys",
"serde-wasm-bindgen",
"wasm-bindgen",
"wasm-bindgen-futures",
"clarity-repl/wasm",
]
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3" }
serde-wasm-bindgen = { version = "0.6.4" }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
web-sys = { workspace = true, features = ["console"] }

[lib]
name = "clarinet_files"
Expand Down
10 changes: 5 additions & 5 deletions components/clarinet-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ mod project_manifest;

pub use network_manifest::{BitcoinNetwork, StacksNetwork};

#[cfg(feature = "wasm")]
#[cfg(target_arch = "wasm32")]
mod wasm_fs_accessor;
#[cfg(feature = "wasm")]
#[cfg(target_arch = "wasm32")]
pub use wasm_fs_accessor::WASMFileSystemAccessor;

pub use network_manifest::{
Expand Down Expand Up @@ -103,7 +103,7 @@ impl FileLocation {
let url = Url::from_str(url_string)
.map_err(|e| format!("unable to parse {} as a url\n{:?}", url_string, e))?;

#[cfg(not(feature = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
if url.scheme() == "file" {
let path = url
.to_file_path()
Expand Down Expand Up @@ -317,7 +317,7 @@ impl FileLocation {
let bytes = match &self {
FileLocation::FileSystem { path } => FileLocation::fs_read_content(path),
FileLocation::Url { url } => match url.scheme() {
#[cfg(not(feature = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
"file" => {
let path = url
.to_file_path()
Expand Down Expand Up @@ -351,7 +351,7 @@ impl FileLocation {

pub fn to_url_string(&self) -> Result<String, String> {
match self {
#[cfg(not(feature = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
FileLocation::FileSystem { path } => {
let file_path = self.to_string();
let url = Url::from_file_path(file_path)
Expand Down
6 changes: 3 additions & 3 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub const DEFAULT_SUBNET_MNEMONIC: &str = "twice kind fence tip hidden tilt acti
pub const DEFAULT_DOCKER_SOCKET: &str = "unix:///var/run/docker.sock";
#[cfg(windows)]
pub const DEFAULT_DOCKER_SOCKET: &str = "npipe:////./pipe/docker_engine";
#[cfg(target_family = "wasm")]
#[cfg(target_arch = "wasm32")]
pub const DEFAULT_DOCKER_SOCKET: &str = "/var/run/docker.sock";
pub const DEFAULT_DOCKER_PLATFORM: &str = "linux/amd64";

Expand Down Expand Up @@ -1149,7 +1149,7 @@ pub fn compute_addresses(
(stx_address.to_string(), btc_address, miner_secret_key_hex)
}

#[cfg(not(feature = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
fn compute_btc_address(public_key: &PublicKey, network: &BitcoinNetwork) -> String {
let public_key = bitcoin::PublicKey::from_slice(&public_key.serialize_compressed())
.expect("Unable to recreate public key");
Expand Down Expand Up @@ -1186,7 +1186,7 @@ pub fn is_in_reward_phase(
}
}

#[cfg(feature = "wasm")]
#[cfg(target_arch = "wasm32")]
fn compute_btc_address(_public_key: &PublicKey, _network: &BitcoinNetwork) -> String {
"__not_implemented__".to_string()
}
22 changes: 5 additions & 17 deletions components/clarinet-format/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ name = "clarinet-format"
version = "0.1.0"
edition = "2021"

[dependencies]
clarity = { workspace = true}
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clarity = { workspace = true, features = ["canonical", "developer-mode", "devtools", "log"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
clarity = { workspace = true, features = ["wasm", "developer-mode", "devtools"] }

[dev-dependencies]
pretty_assertions = "1.3"
Expand All @@ -14,21 +17,6 @@ divan = "0.1"
name = "formatter"
harness = false

[features]
default = ["cli"]
cli = [
"clarity/canonical",
"clarity/developer-mode",
"clarity/devtools",
"clarity/log",
]
wasm = [
"clarity/wasm",
"clarity/developer-mode",
"clarity/devtools",
]


[lib]
name = "clarinet_format"
path = "src/lib.rs"
Expand Down
26 changes: 7 additions & 19 deletions components/clarinet-sdk-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,25 @@ name = "clarinet_sdk"
path = "src/lib.rs"

[dependencies]
console_error_panic_hook = { version = "0.1", optional = true }
console_error_panic_hook = { version = "0.1" }
gloo-utils = { version = "0.2.0", features = ["serde"] }
js-sys = { version = "0.3", optional = true }
js-sys = { version = "0.3" }
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
serde-wasm-bindgen = { version = "0.6.4", optional = true }
wasm-bindgen = { workspace = true, optional = true }
wasm-bindgen-futures = { workspace = true, optional = true }
web-sys = { workspace = true, features = ["console"], optional = true }
serde-wasm-bindgen = { version = "0.6.4" }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
web-sys = { workspace = true, features = ["console"] }

clarinet-files = { path = "../clarinet-files", default-features = false }
clarity-repl = { path = "../clarity-repl", default-features = false, optional = true }
clarity-repl = { path = "../clarity-repl", default-features = false }
clarinet-deployments = { path = "../clarinet-deployments", default-features = false }

[dev-dependencies]
wasm-bindgen-test = "0.3.0"
clarity = { workspace = true }

[features]
default = ["wasm"]
wasm = [
"wasm-bindgen",
"wasm-bindgen-futures",
"serde-wasm-bindgen",
"js-sys",
"web-sys",
"console_error_panic_hook",
"clarinet-deployments/wasm",
"clarity-repl/wasm",
"clarinet-files/wasm",
]
web = [
"clarity-repl/web",
]
Expand Down
9 changes: 3 additions & 6 deletions components/clarity-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ version.workspace = true
edition = "2021"

[dependencies]
clarinet-files = { path = "../clarinet-files", default-features = false, optional = true }
clarinet-files = { path = "../clarinet-files", default-features = false }
clarity-repl = { path = "../clarity-repl", default-features = false }
clap = { version = "4.4.8", features = ["derive"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde_derive = "1"

[features]
default = ["cli"]
cli = ["clarity-repl/cli", "clarinet-files/cli", "clap"]
lib = ["clarity-repl/cli"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { version = "4.4.8", features = ["derive"] }

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
Loading
Loading