-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
62 lines (50 loc) · 2.13 KB
/
build.rs
File metadata and controls
62 lines (50 loc) · 2.13 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
fn main() {
// Re-run build.rs if these env vars change
println!("cargo:rerun-if-env-changed=PKG_VERSION");
println!("cargo:rerun-if-env-changed=SENTRY_DSN");
// Version is passed via PKG_VERSION environment variable.
// This should be set by CI or locally via: PKG_VERSION=$(python scripts/get_version.py)
// Falls back to CARGO_PKG_VERSION if not set.
let version =
std::env::var("PKG_VERSION").unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string());
println!("cargo:rustc-env=PKG_VERSION={}", version);
// Sentry DSN is injected at build time. If not set, defaults to empty string
// which will disable Sentry at runtime.
let sentry_dsn = std::env::var("SENTRY_DSN").unwrap_or_default();
println!("cargo:rustc-env=SENTRY_DSN={}", sentry_dsn);
// Expose build target info for Sentry tags
let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());
println!("cargo:rustc-env=BUILD_TARGET={}", target);
// On Windows, compile the shim binary and place it in OUT_DIR
#[cfg(windows)]
build_shim();
}
#[cfg(windows)]
fn build_shim() {
use std::path::PathBuf;
println!("cargo:rerun-if-env-changed=WINDOWS_SHIM_PATH");
println!("cargo:rerun-if-changed=src/shim/shim.rs");
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let shim_out = out_dir.join("shim.exe");
// If a pre-built shim is provided (e.g., signed), copy it instead of compiling
if let Ok(shim_path) = std::env::var("WINDOWS_SHIM_PATH") {
std::fs::copy(&shim_path, &shim_out).expect("failed to copy shim from WINDOWS_SHIM_PATH");
return;
}
// Otherwise compile it directly
use std::process::Command;
let shim_src = PathBuf::from("src/shim/shim.rs");
let status = Command::new("rustc")
.args([
"--edition=2024",
"-O", // optimize for size
"-o",
shim_out.to_str().unwrap(),
shim_src.to_str().unwrap(),
])
.status()
.expect("failed to run rustc for shim");
if !status.success() {
panic!("failed to compile shim binary");
}
}