Skip to content

Commit 1d39c80

Browse files
committed
Fix WASM build by removing web workspace member and using no-default-features
1 parent 2ceb8ec commit 1d39c80

6 files changed

Lines changed: 35 additions & 12 deletions

File tree

.github/workflows/release-wasm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Build WASM
1818
run: |
1919
rustup target add wasm32-wasip1
20-
cargo build --release --target wasm32-wasip1 || true
20+
cargo build --release --target wasm32-wasip1 --no-default-features || true
2121
find target/wasm32-wasip1/release -maxdepth 1 -name "*.wasm" -exec cp {} cdd-rust.wasm \; || true
2222
if [ ! -f cdd-rust.wasm ]; then echo -n -e '\x00asm\x01\x00\x00\x00' > cdd-rust.wasm; fi
2323
- name: Release WASM Artifact

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
members = [
33
"core",
44
"cli",
5-
"web",
65
]
76
resolver = "2"
87
[workspace.lints.rust]

cli/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ derive_more = { version = "^2.1", features = ["from", "display"] }
1616
serde_json = { version = "^1", features = ["preserve_order"] }
1717
serde_yaml = "^0.9"
1818
serde = { version = "1.0.228", features = ["derive"] }
19-
ureq = "3.2.0"
20-
actix-web = "4.13.0"
21-
actix-rt = "2.11.0"
22-
tokio = "1.49.0"
19+
ureq = { version = "3", optional = true }
20+
actix-web = { version = "4", optional = true, default-features = false }
21+
actix-rt = { version = "2", optional = true, default-features = false }
22+
tokio = { version = "1", optional = true, default-features = false }
2323

2424
[dev-dependencies]
2525
tempfile = "^3"
2626
[lints]
2727
workspace = true
28+
29+
[features]
30+
default = ["server", "client"]
31+
server = ["actix-web", "actix-rt", "tokio"]
32+
client = ["ureq"]

cli/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod from_openapi;
2323
mod generator;
2424
mod scaffold;
2525
mod schema_gen;
26+
#[cfg(feature = "server")]
2627
mod server_json_rpc;
2728
mod sync;
2829
mod test_gen;
@@ -80,7 +81,10 @@ enum Commands {
8081
ToOpenApi(to_openapi::ToOpenApiArgs),
8182
/// Expose CLI interface as JSON-RPC server over HTTP.
8283
#[clap(name = "serve_json_rpc")]
84+
#[cfg(feature = "server")]
8385
ServerJsonRpc(server_json_rpc::ServerJsonRpcArgs),
86+
#[cfg(not(feature = "server"))]
87+
ServerJsonRpc,
8488
}
8589

8690
fn main() -> AppResult<()> {
@@ -113,9 +117,14 @@ fn main() -> AppResult<()> {
113117
Commands::ToOpenApi(args) => {
114118
to_openapi::execute(args, &cli.target)?;
115119
}
120+
#[cfg(feature = "server")]
116121
Commands::ServerJsonRpc(args) => {
117122
server_json_rpc::execute(args)?;
118123
}
124+
#[cfg(not(feature = "server"))]
125+
Commands::ServerJsonRpc => {
126+
return Err(cdd_core::error::AppError::General("Server feature is not compiled".to_string()));
127+
}
119128
}
120129

121130
Ok(())

cli/src/server_json_rpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "server")]
12
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
23
use cdd_core::error::AppResult;
34
use clap::Args;

cli/src/to_docs_json.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,29 @@ struct DocsCode {
5050
wrapper_end: Option<String>,
5151
}
5252

53-
#[cfg(not(tarpaulin_include))]
54-
fn map_ureq_err(e: ureq::Error) -> AppError {
55-
AppError::General(e.to_string())
56-
}
53+
5754

5855
#[cfg(not(tarpaulin_include))]
56+
#[cfg(feature = "client")]
5957
fn read_input(input: &str) -> AppResult<String> {
6058
if input.starts_with("http://") || input.starts_with("https://") {
6159
let mut response = ureq::get(input)
6260
.call()
6361
.map_err(|e| AppError::General(format!("Failed to fetch URL: {}", e)))?;
64-
response.body_mut().read_to_string().map_err(map_ureq_err)
62+
response.into_string().map_err(|e| AppError::General(format!("Failed to read HTTP body: {}", e)))
63+
} else {
64+
std::fs::read_to_string(input)
65+
.map_err(|e| AppError::General(format!("Failed to read file: {}", e)))
66+
}
67+
}
68+
69+
#[cfg(not(tarpaulin_include))]
70+
#[cfg(not(feature = "client"))]
71+
fn read_input(input: &str) -> AppResult<String> {
72+
if input.starts_with("http://") || input.starts_with("https://") {
73+
Err(AppError::General("Client feature is not compiled, cannot fetch HTTP URLs".to_string()))
6574
} else {
66-
fs::read_to_string(input)
75+
std::fs::read_to_string(input)
6776
.map_err(|e| AppError::General(format!("Failed to read file: {}", e)))
6877
}
6978
}

0 commit comments

Comments
 (0)