-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.rs
More file actions
99 lines (85 loc) · 3.23 KB
/
Copy pathbuild.rs
File metadata and controls
99 lines (85 loc) · 3.23 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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
prost_build::Config::new()
.out_dir(manifest_dir.join("src/protocol"))
.compile_protos(&["src/pb.proto"], &["src/"])?;
let out_dir = env::var("OUT_DIR")?;
let dest_path = PathBuf::from(&out_dir).join("config.rs");
let mut config_file = File::create(&dest_path)?;
let api_url = env::var("BPTIMER_API_URL").unwrap_or_else(|_| String::new());
let api_key = env::var("BPTIMER_API_KEY").unwrap_or_else(|_| String::new());
#[cfg(not(debug_assertions))]
{
if api_url.is_empty() {
panic!("BPTIMER_API_URL environment variable is required for release builds");
}
if api_key.is_empty() {
panic!("BPTIMER_API_KEY environment variable is required for release builds");
}
}
let repo_owner = env::var("GITHUB_REPO_OWNER").unwrap_or_else(|_| "woheedev".to_string());
let repo_name = env::var("GITHUB_REPO_NAME").unwrap_or_else(|_| "bptimer".to_string());
writeln!(
config_file,
"pub const BPTIMER_API_URL: &str = \"{api_url}\";"
)?;
writeln!(
config_file,
"pub const BPTIMER_API_KEY: &str = \"{api_key}\";"
)?;
writeln!(
config_file,
"pub const GITHUB_REPO_OWNER: &str = \"{repo_owner}\";"
)?;
writeln!(
config_file,
"pub const GITHUB_REPO_NAME: &str = \"{repo_name}\";"
)?;
#[cfg(windows)]
{
let icon_path = manifest_dir
.join("..")
.join("web")
.join("static")
.join("favicon.ico");
if icon_path.exists() {
let mut res = winres::WindowsResource::new();
res.set_icon(icon_path.to_str().unwrap());
res.set_language(0x0409); // English (US)
res.compile()?;
}
// Configure Npcap SDK library path for linking
// Auto-detect bundled SDK
let bundled_sdk = manifest_dir.join("sdk").join("Lib").join("x64");
if bundled_sdk.exists() {
println!("cargo:rustc-link-search=native={}", bundled_sdk.display());
}
// Check LIBPCAP_LIBDIR env var as override
if let Ok(libdir) = env::var("LIBPCAP_LIBDIR") {
println!("cargo:rustc-link-search=native={libdir}");
}
// Fallback: try common installation paths
let common_paths = [
"C:\\npcap-sdk\\Lib\\x64",
"C:\\Program Files\\Npcap\\Lib\\x64",
];
for path in &common_paths {
if std::path::Path::new(path).exists() {
println!("cargo:rustc-link-search=native={}", path);
}
}
println!("cargo:rustc-link-lib=wpcap");
println!("cargo:rustc-link-lib=Packet");
}
println!("cargo:rerun-if-changed=src/pb.proto");
println!("cargo:rerun-if-env-changed=BPTIMER_API_URL");
println!("cargo:rerun-if-env-changed=BPTIMER_API_KEY");
println!("cargo:rerun-if-env-changed=GITHUB_REPO_OWNER");
println!("cargo:rerun-if-env-changed=GITHUB_REPO_NAME");
println!("cargo:rerun-if-env-changed=LIBPCAP_LIBDIR");
Ok(())
}