sdforge 0.3.1

Multi-protocol SDK framework with unified macro configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
[workspace]
members = ["."]
resolver = "2"

[workspace.package]
version = "0.3.1"
edition = "2021"
authors = ["Kirky.X"]
license = "MIT"
repository = "https://github.com/Kirky-X/sdforge"

[workspace.dependencies]
# 核心依赖
serde = { version = "~1.0", default-features = false, features = ["std", "derive"] }
serde_json = { version = "~1.0", default-features = false, features = ["std"] }
thiserror = { version = "~2.0", default-features = false }
log = { version = "~0.4", default-features = false, features = ["std"] }

# 过程宏依赖
proc-macro2 = { version = "~1.0", default-features = false, features = ["proc-macro"] }
syn = { version = "~2.0", default-features = false, features = ["full", "extra-traits", "parsing", "printing", "clone-impls", "proc-macro"] }
quote = { version = "~1.0", default-features = false, features = ["proc-macro"] }

# HTTP 依赖
axum = { version = "~0.8.9", default-features = false, features = ["http1", "json", "form", "matched-path", "original-uri", "query", "tokio", "tower-log", "tracing", "ws"] }
tower = { version = "~0.5", default-features = false, features = ["log", "util", "timeout", "limit", "load-shed", "retry"] }
tower-http = { version = "~0.7", default-features = false, features = ["cors", "limit", "timeout", "set-header", "compression-gzip", "compression-deflate"] }
inventory = { version = "~0.3", default-features = false }

# 异步依赖
tokio = { version = "~1.52", default-features = false, features = ["rt-multi-thread", "macros", "sync", "time", "net"] }
futures-util = { version = "~0.3", default-features = false, features = ["std", "async-await", "async-await-macro"] }
tokio-stream = { version = "~0.1", default-features = false }

# 工具依赖
uuid = { version = "~1.23", default-features = false, features = ["std", "v4"] }
chrono = { version = "~0.4", default-features = false, features = ["std", "serde", "clock"] }
regex = { version = "~1.12", default-features = false, features = ["std", "perf"] }
validator = { version = "~0.20", default-features = false, features = ["derive"] }
once_cell = { version = "~1.21", default-features = false, features = ["std"] }

# 安全依赖
hmac = { version = "~0.13", default-features = false }
sha2 = { version = "~0.11", default-features = false }
subtle = { version = "~2.6", default-features = false }
rand = { version = "~0.10", default-features = false, features = ["std", "std_rng"] }
hex = { version = "~0.4", default-features = false, features = ["alloc"] }
base64 = { version = "~0.22", default-features = false, features = ["std", "alloc"] }

# 配置依赖
toml = { version = "~1.1", default-features = false, features = ["parse", "display"] }

# 缓存依赖 - oxcache 0.3.2 用 minimal feature 提供内存后端 + 序列化 + tracing
oxcache = { version = "0.3.2", default-features = false, features = ["minimal"] }
http = { version = "~1.4", default-features = false, features = ["std"] }
bincode = { version = "~2.0", default-features = false, features = ["std", "serde"] }

# WebSocket 依赖
axum-extra = { version = "~0.12", default-features = false, features = ["typed-header"] }

# gRPC 依赖
tonic = { version = "~0.14", default-features = false, features = ["transport", "codegen", "router"] }
prost = { version = "~0.14", default-features = false, features = ["derive"] }
tonic-prost = { version = "~0.14", default-features = false }

# 流控依赖 - limiteron 0.2.1 提供统一限流/封禁/配额/熔断
limiteron = { version = "~0.2", default-features = false }

# OpenAPI 依赖
utoipa = { version = "~5.5", default-features = false, features = ["macros"] }

# CLI 依赖 - clap 4.6 提供命令行解析(derive feature 用于过程宏派生)
# string feature 启用 Str: From<String>,支持运行时配置程序名(MED-4)
clap = { version = "~4.6", default-features = false, features = ["std", "derive", "help", "usage", "error-context", "suggestions", "string"] }

# Swagger UI 依赖 - utoipa-swagger-ui 8.0 配合 utoipa 5.5 提供交互式 API 文档
utoipa-swagger-ui = { version = "~8.0", default-features = false, features = ["axum"] }

# CLI Markdown 文档依赖 - clap-markdown 0.1 从 clap::Command 生成 Markdown 命令手册
clap-markdown = { version = "~0.1", default-features = false }

# 其他依赖
url = { version = "~2.5", default-features = false }
simd-json = { version = "~0.17", default-features = false, features = ["serde_impl"] }

# 开发依赖
tempfile = { version = "~3.27", default-features = false }
serial_test = { version = "~3.5", default-features = false }
axum-test = { version = "~21", default-features = false, features = ["ws"] }
reqwest = { version = "~0.13", default-features = false, features = ["json"] }
criterion = { version = "~0.8", default-features = false }
trybuild = { version = "~1.0", default-features = false }
proptest = { version = "~1.11", default-features = false, features = ["std", "alloc", "bit-set"] }
pretty_assertions = { version = "~1.4", default-features = false, features = ["std"] }


[package]
name = "sdforge"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
keywords = ["api", "http", "mcp", "macro", "framework"]
categories = ["web-programming", "development-tools"]
description = "Multi-protocol SDK framework with unified macro configuration"
documentation = "https://docs.rs/sdforge"

[lib]
path = "src/lib.rs"

# Performance verification examples — require `cache` feature for SyncCache.
# Declared with required-features so `cargo test --features http --workspace`
# does not attempt to compile them without the cache feature enabled.
[[example]]
name = "perf_regex_cache"
required-features = ["cache"]
[[example]]
name = "perf_lru_eviction"
required-features = ["cache"]
[[example]]
name = "perf_prefix_index"
required-features = ["cache"]
[[example]]
name = "perf_batch_ops"
required-features = ["cache"]

# CLI 基础示例 — 演示 #[service_api(cli=true)] + CliBuilder 集成
[[example]]
name = "basic_cli"
required-features = ["cli"]

# Swagger UI 示例 — 演示 swagger_ui_router() + axum serve
[[example]]
name = "swagger_demo"
required-features = ["docs"]

[dependencies]
# Core dependencies (always required)
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
log = { workspace = true }
sdforge-macros = { version = "0.3.0", path = "./macros" }

# HTTP dependencies
axum = { workspace = true, optional = true }
tower = { workspace = true, optional = true }
tower-http = { workspace = true, optional = true }
inventory = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true, features = ["typed-header"] }

# MCP dependencies (migrated from mcp-sdk 0.0.3 to official rmcp 2.1.0)
rmcp = { version = "~2.1", optional = true, default-features = false, features = ["server"] }
anyhow = { version = "1.0", optional = true, default-features = false, features = ["std"] }

# Streaming dependencies
tokio-stream = { workspace = true, optional = true }
futures-util = { workspace = true, optional = true }

# gRPC dependencies
tonic = { workspace = true, optional = true }
prost = { workspace = true, optional = true }
tonic-prost = { workspace = true, optional = true }

# OpenAPI dependencies
utoipa = { workspace = true, optional = true }

# CLI dependencies - clap 用于命令行参数解析
clap = { workspace = true, optional = true }

# Docs dependencies - Swagger UI 和 Markdown 文档生成
utoipa-swagger-ui = { workspace = true, optional = true }
clap-markdown = { workspace = true, optional = true }

# Feature dependencies
chrono = { workspace = true, optional = true }

# Validation dependencies
validator = { workspace = true, optional = true }
regex = { workspace = true, optional = true }
once_cell = { workspace = true, optional = true }

# Security dependencies
uuid = { workspace = true, optional = true }
hmac = { workspace = true, optional = true }
sha2 = { workspace = true, optional = true }
subtle = { workspace = true, optional = true }
rand = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
base64 = { workspace = true, optional = true }

# Configuration dependencies
toml = { workspace = true, optional = true }

# Cache dependencies - oxcache 0.3.2 用 memory feature 提供缓存后端
oxcache = { workspace = true, optional = true }
http = { workspace = true, optional = true }

# Serialization for SyncCache storage values
bincode = { workspace = true, optional = true }

# SIMD-accelerated JSON (optional, requires SIMD support)
simd-json = { workspace = true, optional = true }

# Rate limiting dependencies - limiteron 0.2.1 提供统一流控
limiteron = { workspace = true, optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["test-util"] }
tokio-stream = { workspace = true }
once_cell = { workspace = true }
sdforge-macros = { version = "0.3.1", path = "./macros", default-features = false }
tempfile = { workspace = true }
serial_test = { workspace = true }
axum-test = { workspace = true }
reqwest = { workspace = true }
criterion = { workspace = true }
trybuild = { workspace = true }
proptest = { workspace = true }
url = { workspace = true }

[features]
default = ["http"]

# HTTP 特性 - 启用时编译 axum 等
http = [
    "axum",
    "tower",
    "tower-http",
    "inventory",
    "tokio",
    "axum-extra",
    "toml",
    "regex",
    "once_cell",
    "validator",
    "uuid",
]

# MCP 特性 (migrated to official rmcp SDK 2.1.0)
# http crate needed for MCP 2026-07-28 stateless HTTP header parsing (Mcp-Method/Mcp-Name)
mcp = ["rmcp", "inventory", "anyhow", "dep:http"]

# Streaming 特性
streaming = ["http", "tokio-stream", "futures-util", "chrono"]

# Timestamp 特性
timestamp = ["chrono"]

# Rate limiting 特性 - 继承 limiteron 0.2.1 核心流控能力(tower-middleware/ban-manager/quota-control/circuit-breaker)
# 依赖 http (axum) 因 RateLimiter::check_request 需要 axum::http::Request<Body>
ratelimit = [
    "http",
    "dep:limiteron",
    "limiteron/tower-middleware",
    "limiteron/ban-manager",
    "limiteron/quota-control",
    "limiteron/circuit-breaker",
]

# Security 特性
security = [
    "http",
    "uuid",
    "hmac",
    "sha2",
    "chrono",
    "tokio",
    "subtle",
    "once_cell",
    "rand",
    "regex",
    "oxcache/minimal",
    "bincode",
    "cache",
    "hex",
    "base64",
    "ratelimit",
]

# WebSocket 特性
websocket = ["http", "streaming", "axum-extra", "chrono"]

# gRPC 特性
grpc = ["http", "tonic", "prost", "tonic-prost"]

# OpenAPI 特性 - 自动生成 OpenAPI 3.1 规范
openapi = ["utoipa", "http"]

# CLI 特性 - clap 集成,与 HTTP/MCP 并列的第三种服务入口
# 依赖 http(复用 axum 类型)+ clap(derive feature)
cli = ["http", "dep:clap"]

# Docs 特性 - 统一文档输出(Swagger UI + CLI/MCP Markdown)
# 依赖 openapi(复用 OpenAPI 生成)+ utoipa-swagger-ui + clap-markdown + cli(docs 子命令需要 CLI 框架)
docs = ["openapi", "dep:utoipa-swagger-ui", "dep:clap-markdown", "cli"]

# Cache 特性 - oxcache 0.3.2 用 minimal feature 提供缓存后端
cache = ["dep:http", "oxcache/minimal"]

# Logging 特性
logging = ["chrono", "tokio"]

# SIMD JSON 特性 - 使用 SIMD 加速的 JSON 序列化/反序列化
simd-json = ["dep:simd-json"]

# Full 特性
full = [
    "http",
    "mcp",
    "streaming",
    "timestamp",
    "security",
    "cache",
    "websocket",
    "grpc",
    "logging",
    "openapi",
    "cli",
    "docs",
]
hex = ["dep:hex"]

[build-dependencies]
tonic-build = { version = "0.14", default-features = false }
tonic-prost-build = { version = "0.14", default-features = false }

[package.metadata.docs.rs]
all-features = true

[[bench]]
name = "axiom_bench"
path = "src/benches/sdforge_bench.rs"
harness = false

# Cache tests
[[test]]
name = "cache_tests"
path = "tests/integration/cache_tests.rs"

# Integration tests
[[test]]
name = "feature_combinations"
path = "tests/integration/feature_combinations.rs"

[[test]]
name = "grpc_tests"
path = "tests/integration/grpc_tests.rs"

[[test]]
name = "http_integration"
path = "tests/integration/http_integration.rs"

[[test]]
name = "mcp_integration"
path = "tests/integration/mcp_integration.rs"

[[test]]
name = "mcp_protocol_tests"
path = "tests/integration/mcp_protocol_tests.rs"

[[test]]
name = "security_headers_tests"
path = "tests/integration/security_headers_tests.rs"

[[test]]
name = "security_middleware_tests"
path = "tests/integration/security_middleware_tests.rs"

[[test]]
name = "security_tests"
path = "tests/integration/security_tests.rs"

[[test]]
name = "streaming_tests"
path = "tests/integration/streaming_tests.rs"

[[test]]
name = "uat_tests"
path = "tests/integration/uat_tests.rs"

[[test]]
name = "websocket_integration_tests"
path = "tests/integration/websocket_integration_tests.rs"

[[test]]
name = "websocket_tests"
path = "tests/integration/websocket_tests.rs"

[[test]]
name = "integration_http_mcp"
path = "tests/integration_http_mcp.rs"

[[test]]
name = "http_tests"
path = "tests/integration/http_tests.rs"

# Unit tests
[[test]]
name = "config_tests"
path = "tests/unit/config_tests.rs"

[[test]]
name = "core_tests"
path = "tests/unit/core_tests.rs"

[[test]]
name = "edge_case_tests"
path = "tests/unit/edge_case_tests.rs"

[[test]]
name = "http_version_routing_tests"
path = "tests/unit/http_version_routing_tests.rs"

[[test]]
name = "mcp_tool_instance_tests"
path = "tests/unit/mcp_tool_instance_tests.rs"

[[test]]
name = "error_handling_tests"
path = "tests/integration/error_handling_tests.rs"

# OpenAPI integration tests
[[test]]
name = "openapi_tests"
path = "tests/integration/openapi_tests.rs"
required-features = ["http", "openapi"]

# CLI integration tests — verify #[service_api(cli = true)] + CliBuilder pipeline
[[test]]
name = "cli_tests"
path = "tests/integration/cli_tests.rs"
required-features = ["cli"]

# Docs integration tests — verify generate_docs / write_docs / swagger_ui_router
[[test]]
name = "docs_tests"
path = "tests/integration/docs_tests.rs"
required-features = ["docs"]

[[test]]
name = "macro_tests"
path = "tests/macros/macro_tests.rs"

[profile.release]
lto = true
codegen-units = 1
opt-level = "z"

[profile.dev]
debug = true

[profile.dev.package."*"]
opt-level = 2