-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.rs
More file actions
55 lines (47 loc) · 1.6 KB
/
build.rs
File metadata and controls
55 lines (47 loc) · 1.6 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
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,
Deploy,
Info,
Tx,
Network,
Completions,
}
fn main() {
let _outdir = match env::var_os("OUT_DIR") {
None => return,
Some(_outdir) => _outdir,
};
let mut cmd = Cli::command();
// Create a directory for completions in the project root for easier access
// or just leave them in OUT_DIR as per standard practice.
// The issue says "Install completions to appropriate system directories".
// We'll generate them to a 'completions' folder in the project root for now.
let project_root = env::var("CARGO_MANIFEST_DIR").unwrap();
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");
}
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");
}