-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbuild.rs
More file actions
111 lines (98 loc) · 3.95 KB
/
build.rs
File metadata and controls
111 lines (98 loc) · 3.95 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
use std::{env, fs, path::PathBuf};
const REQUIRED_MACOS_PACKAGING_FILES: &[&str] = &[
"macos/system-extension/entitlements/agent-app.entitlements",
"macos/system-extension/entitlements/combined-system-extension.entitlements",
"macos/system-extension/plists/agent-packaging-template.plist",
"macos/system-extension/plists/combined-system-extension-template.plist",
"macos/system-extension/profiles/developer-id-profile-template.plist",
];
const TAURI_CONFIG_PATH: &str = "tauri.conf.json";
const SCAFFOLD_ONLY_MARKER: &str = "scaffold_only";
const REQUIRED_TAURI_CONFIG_SNIPPETS: &[&str] = &[
"\"minimumSystemVersion\": \"13.0\"",
"\"macos/system-extension/**/*\"",
"\"entitlements\": \"macos/system-extension/entitlements/agent-app.entitlements\"",
];
fn main() {
println!("cargo:rerun-if-changed={TAURI_CONFIG_PATH}");
for relative_path in REQUIRED_MACOS_PACKAGING_FILES {
println!("cargo:rerun-if-changed={relative_path}");
}
if should_validate_macos_packaging() {
validate_macos_packaging()
.unwrap_or_else(|error| panic!("macOS packaging validation failed: {error}"));
}
tauri_build::build()
}
fn should_validate_macos_packaging() -> bool {
env::var("TARGET")
.map(|target| target.contains("apple-darwin"))
.unwrap_or(false)
|| env::var_os("CLAWDSTRIKE_VALIDATE_MACOS_PACKAGING").is_some()
}
fn validate_macos_packaging() -> Result<(), String> {
let manifest_dir = manifest_dir()?;
let mut missing_files = Vec::new();
for relative_path in REQUIRED_MACOS_PACKAGING_FILES {
if !manifest_dir.join(relative_path).is_file() {
missing_files.push((*relative_path).to_string());
}
}
if !missing_files.is_empty() {
return Err(format!(
"missing required packaging assets: {}",
missing_files.join(", ")
));
}
let tauri_config = fs::read_to_string(manifest_dir.join(TAURI_CONFIG_PATH))
.map_err(|error| format!("failed to read {TAURI_CONFIG_PATH}: {error}"))?;
let missing_config = REQUIRED_TAURI_CONFIG_SNIPPETS
.iter()
.filter(|snippet| !tauri_config.contains(**snippet))
.copied()
.collect::<Vec<_>>();
if !missing_config.is_empty() {
return Err(format!(
"tauri.conf.json is missing required macOS packaging entries: {}",
missing_config.join(", ")
));
}
if env::var_os("CLAWDSTRIKE_REQUIRE_CONCRETE_MACOS_PACKAGING").is_some() {
let files_with_placeholders = REQUIRED_MACOS_PACKAGING_FILES
.iter()
.filter_map(|relative_path| {
fs::read_to_string(manifest_dir.join(relative_path))
.ok()
.filter(|contents| contents.contains("__"))
.map(|_| (*relative_path).to_string())
})
.collect::<Vec<_>>();
if !files_with_placeholders.is_empty() {
return Err(format!(
"release-gated packaging placeholders remain in: {}",
files_with_placeholders.join(", ")
));
}
let files_with_scaffold_marker = REQUIRED_MACOS_PACKAGING_FILES
.iter()
.filter_map(|relative_path| {
fs::read_to_string(manifest_dir.join(relative_path))
.ok()
.filter(|contents| contents.contains(SCAFFOLD_ONLY_MARKER))
.map(|_| (*relative_path).to_string())
})
.collect::<Vec<_>>();
if !files_with_scaffold_marker.is_empty() {
return Err(format!(
"release-gated packaging sources still declare scaffold_only state: {}",
files_with_scaffold_marker.join(", ")
));
}
}
Ok(())
}
fn manifest_dir() -> Result<PathBuf, String> {
env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.map_err(|error| format!("missing CARGO_MANIFEST_DIR: {error}"))
}