-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.rs
More file actions
243 lines (217 loc) · 8.46 KB
/
build.rs
File metadata and controls
243 lines (217 loc) · 8.46 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
use std::fs;
use std::io::Write;
use std::path::Path;
use std::process::Command;
/// Adapter specs to download from OpenECU Alliance GitHub
const ADAPTER_SPECS: &[(&str, &str)] = &[
(
"haltech/haltech-nsp.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/haltech/haltech-nsp.adapter.yaml",
),
(
"ecumaster/ecumaster-emu-csv.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/ecumaster/ecumaster-emu-csv.adapter.yaml",
),
(
"link/link-llg.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/link/link-llg.adapter.yaml",
),
(
"aim/aim-xrk.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/aim/aim-xrk.adapter.yaml",
),
(
"romraider/romraider-csv.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/romraider/romraider-csv.adapter.yaml",
),
(
"speeduino/speeduino-mlg.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/speeduino/speeduino-mlg.adapter.yaml",
),
(
"rusefi/rusefi-mlg.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/rusefi/rusefi-mlg.adapter.yaml",
),
(
"emerald/emerald-lg.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/emerald/emerald-lg.adapter.yaml",
),
(
"megasquirt/megasquirt-tunerstudio.adapter.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/adapters/megasquirt/megasquirt-tunerstudio.adapter.yaml",
),
];
/// Protocol specs to download from OpenECU Alliance GitHub
const PROTOCOL_SPECS: &[(&str, &str)] = &[
(
"haltech/haltech-elite-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/haltech/haltech-elite-broadcast.protocol.yaml",
),
(
"ecumaster/ecumaster-emu-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/ecumaster/ecumaster-emu-broadcast.protocol.yaml",
),
(
"speeduino/speeduino-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/speeduino/speeduino-broadcast.protocol.yaml",
),
(
"rusefi/rusefi-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/rusefi/rusefi-broadcast.protocol.yaml",
),
(
"aem/aem-infinity-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/aem/aem-infinity-broadcast.protocol.yaml",
),
(
"megasquirt/megasquirt-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/megasquirt/megasquirt-broadcast.protocol.yaml",
),
(
"maxxecu/maxxecu-default.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/maxxecu/maxxecu-default.protocol.yaml",
),
(
"syvecs/syvecs-s7-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/syvecs/syvecs-s7-broadcast.protocol.yaml",
),
(
"emtron/emtron-broadcast.protocol.yaml",
"https://raw.githubusercontent.com/ClassicMiniDIY/OECUASpecs/main/protocols/emtron/emtron-broadcast.protocol.yaml",
),
];
fn main() {
// Ensure OpenECU Alliance specs are available
ensure_adapter_specs();
ensure_protocol_specs();
// Only run on Windows
#[cfg(windows)]
{
// Embed icon and version info into Windows executable
// Note: Windows resource embedding requires an .ico file
// Convert assets/icons/windows.png to .ico format if needed:
// magick assets/icons/windows.png -define icon:auto-resize=256,128,64,48,32,16 assets/icons/windows.ico
let mut res = winresource::WindowsResource::new();
res.set_icon("assets/icons/windows.ico")
.set("ProductName", "UltraLog")
.set("FileDescription", "High-performance ECU log viewer")
.set("LegalCopyright", "Copyright (c) 2026 Cole Gentry");
// Only compile if icon exists
if std::path::Path::new("assets/icons/windows.ico").exists() {
res.compile().expect("Failed to compile Windows resources");
}
}
}
/// Ensure adapter specs are available by downloading from OpenECU Alliance
fn ensure_adapter_specs() {
let spec_dir = Path::new("spec/OECUASpecs/adapters");
// Check if specs are already downloaded
let haltech_spec = spec_dir.join("haltech/haltech-nsp.adapter.yaml");
if haltech_spec.exists() {
println!("cargo:rerun-if-changed=spec/OECUASpecs/adapters");
return;
}
println!("cargo:warning=Adapter specs not found, downloading from OpenECU Alliance...");
download_adapter_specs(spec_dir);
}
/// Ensure protocol specs are available
fn ensure_protocol_specs() {
let spec_dir = Path::new("spec/OECUASpecs/protocols");
// Check if submodule is initialized (has the haltech protocol)
let haltech_spec = spec_dir.join("haltech/haltech-elite-broadcast.protocol.yaml");
if haltech_spec.exists() {
println!("cargo:rerun-if-changed=spec/OECUASpecs/protocols");
return;
}
println!("cargo:warning=Protocol specs not found, downloading from GitHub...");
download_specs(spec_dir, PROTOCOL_SPECS);
}
/// Download adapter specs directly from GitHub
fn download_adapter_specs(spec_dir: &Path) {
download_specs(spec_dir, ADAPTER_SPECS);
}
/// Generic spec downloader
fn download_specs(spec_dir: &Path, specs: &[(&str, &str)]) {
// Create directory structure
for (path, _) in specs {
let full_path = spec_dir.join(path);
if let Some(parent) = full_path.parent() {
fs::create_dir_all(parent).ok();
}
}
// Try curl first (available on most systems)
for (path, url) in specs {
let full_path = spec_dir.join(path);
if full_path.exists() {
continue;
}
// Try curl
let result = Command::new("curl")
.args(["-sSL", "-o", full_path.to_str().unwrap(), url])
.status();
if let Ok(status) = result {
if status.success() {
println!(
"cargo:warning=Downloaded {}",
full_path.file_name().unwrap().to_str().unwrap()
);
continue;
}
}
// Try wget as fallback
let result = Command::new("wget")
.args(["-q", "-O", full_path.to_str().unwrap(), url])
.status();
if let Ok(status) = result {
if status.success() {
println!(
"cargo:warning=Downloaded {}",
full_path.file_name().unwrap().to_str().unwrap()
);
continue;
}
}
// Try PowerShell on Windows
#[cfg(windows)]
{
let ps_script = format!(
"Invoke-WebRequest -Uri '{}' -OutFile '{}'",
url,
full_path.to_str().unwrap()
);
let result = Command::new("powershell")
.args(["-Command", &ps_script])
.status();
if let Ok(status) = result {
if status.success() {
println!(
"cargo:warning=Downloaded {}",
full_path.file_name().unwrap().to_str().unwrap()
);
continue;
}
}
}
// If we get here, all download methods failed
// Create a placeholder that will cause a compile error with helpful message
let error_content = format!(
r#"# ERROR: Failed to download spec from OpenECU Alliance
# URL: {}
#
# Please download manually:
# curl -sSL -o {} {}
"#,
url,
full_path.display(),
url
);
if let Ok(mut file) = fs::File::create(&full_path) {
file.write_all(error_content.as_bytes()).ok();
}
println!(
"cargo:warning=Failed to download {}, created placeholder",
path
);
}
println!("cargo:rerun-if-changed={}", spec_dir.display());
}