forked from Nanle-code/StarForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
244 lines (230 loc) · 8.27 KB
/
Copy pathbuild.rs
File metadata and controls
244 lines (230 loc) · 8.27 KB
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
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{generate_to, Shell};
use std::env;
use std::fs;
use std::path::Path;
#[derive(Parser)]
#[command(name = "starforge", version = "0.1.0")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Wallet,
New,
Contract,
Inspect,
Deploy,
Info,
Tx,
Network,
Completions,
Shell,
Monitor,
Tutorial,
Benchmark,
Test,
Gas,
Plugin,
Template,
Upgrade,
Man,
#[command(external_subcommand)]
#[allow(dead_code)]
External(Vec<String>),
}
const SUBCOMMAND_INFO: &[(&str, &str)] = &[
("ai-debug", "AI-powered contract debugging assistant"),
("ai-navigate", "AI-driven code navigation and search"),
("ai-quality-gate", "Configurable code quality gates"),
("ai", "Local LLM assistant for Soroban contracts"),
(
"wallet",
"Manage test wallets (create, list, fund, show, remove)",
),
("nl", "Natural language command interface"),
("new", "Generate Soroban project boilerplate"),
("contract", "Contract operations (invoke, inspect, etc.)"),
(
"generate",
"Generate smart contracts from natural language prompts",
),
("complete", "Smart contract completion assistant"),
(
"debug",
"Debug Soroban contracts with breakpoints, stepping, and inspection",
),
(
"inspect",
"Deep contract storage inspection (state, key, storage)",
),
("deploy", "Deploy a compiled Soroban contract (.wasm)"),
(
"deployments",
"Deployment history, rollback, verification, and dashboard",
),
("info", "Show starforge config and environment info"),
("prompts", "Manage AI prompt templates and versioning"),
(
"explain",
"Analyze and explain smart contract code using AI",
),
(
"config",
"Manage starforge configuration (telemetry, network)",
),
("telemetry", "Manage telemetry settings directly"),
("tx", "Fetch transaction for the account"),
(
"network",
"View or switch the active network (testnet/mainnet)",
),
("node", "Local Soroban devnet (Docker quickstart)"),
(
"completions",
"Generate shell completions for bash, zsh, and fish",
),
(
"autocomplete",
"Smart autocomplete — suggest and record commands",
),
(
"shell",
"Interactive REPL for local Soroban contract testing",
),
(
"monitor",
"Live monitoring (contract events or wallet threshold)",
),
("tutorial", "Interactive CLI tutorials"),
("benchmark", "Performance benchmarking utilities"),
("test", "Contract testing utilities for Soroban wasm"),
("gas", "Gas analysis and optimization helpers"),
("cost", "AI-assisted deployment cost management"),
("plugin", "Manage third-party plugins"),
(
"privacy",
"Privacy protection, anonymization, consent, and reporting",
),
("project", "AI-driven project management"),
(
"template",
"Manage community contract templates from the marketplace",
),
("registry", "Interact with the remote template registry"),
("multisig", "Manage multi-signature transactions"),
("upgrade", "Contract upgrade management"),
("governance", "Contract upgrade governance"),
("orchestrate", "Multi-contract deployment orchestration"),
(
"pipeline",
"Visual pipeline builder for contract deployment workflows",
),
("security", "Security hardening, validation, and monitoring"),
(
"audit",
"Run a comprehensive security audit on a Soroban contract",
),
("ai-audit", "AI-powered security audit"),
("ai-test", "AI-driven testing assistance"),
("ai-property-test", "AI property-based testing"),
("ai-feedback", "AI feedback and learning system"),
("ai-search", "AI code search and discovery"),
("ai-recommend", "AI best practice recommendations"),
("ai-route", "Intelligent AI model selection and routing"),
("ai-plan", "AI project planning assistant"),
("ai-accessibility", "AI accessibility features"),
("ai-contract-suggest", "AI contract function suggestions"),
("ai-doc-qa", "AI documentation Q&A"),
("schedule", "Schedule deployments for future execution"),
(
"simulate",
"Local network simulation and testing environment",
),
("backup", "Backup and disaster recovery"),
("lint", "Static analysis and linting for Soroban contracts"),
(
"diagnostics",
"Run connectivity diagnostics for Ledger/Trezor devices",
),
("template-vcs", "Template version control"),
(
"perf",
"Contract performance monitoring and metrics dashboard",
),
("advanced-perf", "Advanced contract performance analysis"),
("docs", "Contract documentation portal"),
("analytics", "Contract deployment analytics and reporting"),
("approval", "Approval workflow for contract deployments"),
("feature-flags", "Manage feature flags for AI features"),
("migrate", "Contract storage migration tools"),
("collab", "AI-driven collaboration tools"),
("verify", "Run formal verification on a contract"),
("help", "AI contextual help"),
("ai-telemetry", "AI usage telemetry and analytics"),
(
"optimize",
"Analyse and optimize compiled WASM / Rust contract source",
),
("ai-security-training", "AI-driven security training"),
(
"contract-monitor",
"Contract health monitoring and alerting",
),
("man", "Generate or install man pages"),
];
fn main() {
let _outdir = match env::var_os("OUT_DIR") {
None => return,
Some(_outdir) => _outdir,
};
let mut cmd = Cli::command();
let project_root = env::var("CARGO_MANIFEST_DIR").unwrap();
// ── Shell completions ─────────────────────────────────────────────────
let completions_dir = Path::new(&project_root).join("completions");
fs::create_dir_all(&completions_dir).unwrap();
for &shell in &[Shell::Bash, Shell::Zsh, Shell::Fish] {
generate_to(shell, &mut cmd, "starforge", &completions_dir)
.expect("Failed to generate completions");
}
// ── Man pages ─────────────────────────────────────────────────────────
let man_dir = Path::new(&project_root).join("man");
fs::create_dir_all(&man_dir).unwrap();
// Main starforge(1) page
let main_cmd = Cli::command();
let man = clap_mangen::Man::new(main_cmd)
.title("starforge".to_string())
.section("1".to_string())
.source("StarForge".to_string())
.manual("User Manual".to_string());
man.generate_to(&man_dir)
.expect("Failed to generate starforge.1 man page");
// Per-subcommand pages
for &(name, about) in SUBCOMMAND_INFO {
if name == "help" || name == "external" {
continue;
}
let full_name = format!("starforge-{}", name);
let full_name_static: &'static str = Box::leak(full_name.into_boxed_str());
let sub_cmd = clap::Command::new(full_name_static)
.about(about)
.version("0.1.0");
let man = clap_mangen::Man::new(sub_cmd)
.title(full_name_static)
.section("1".to_string())
.source("StarForge".to_string())
.manual("User Manual".to_string());
man.generate_to(&man_dir)
.unwrap_or_else(|e| panic!("Failed to generate {} man page: {}", full_name_static, e));
}
// ── rustc version capture ─────────────────────────────────────────────
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let output = std::process::Command::new(rustc)
.arg("--version")
.output()
.expect("Failed to get rustc version");
let version = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=RUSTC_VERSION={}", version.trim());
println!("cargo:rerun-if-changed=build.rs");
}