mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-30 06:29:27 -07:00
PR #888 introduced more files that the installer needs to bundle. Those files in particular are annoying to deal with because now every developer needs a working C crosscompiler to get the installer working. This prompted me to do some other refactoring. Refactor install-dev to not build the wifi tools if there is no crosscompiler, and refactor the installer so that these files are loaded at runtime when built in debug mode. The build script only ever warns if files are missing, and depending on debug/release mode, the get_file!() macro either panics at runtime or fails compiling. Now the installer can be built again without any files, clippy can be run directly without any envvars, and the installer runs atleast for devices that don't need those files. The orbic installer will panic at runtime if the wifi tools haven't been built. Building the installer in release mode still requires all files. Another nicety of loading these files on runtime is that the installer does not need to be recompiled when the daemon has been rebuilt. This should make things like make.sh really obsolete, which bypass the installer for speed.
43 lines
1.6 KiB
Rust
43 lines
1.6 KiB
Rust
use std::path::Path;
|
|
|
|
fn main() {
|
|
println!("cargo::rerun-if-env-changed=FIRMWARE_PROFILE");
|
|
let profile = std::env::var("FIRMWARE_PROFILE").unwrap_or_else(|_| {
|
|
// Default to firmware-devel for debug builds, firmware for release builds
|
|
if std::env::var("PROFILE").as_deref() == Ok("release") {
|
|
"firmware".to_string()
|
|
} else {
|
|
"firmware-devel".to_string()
|
|
}
|
|
});
|
|
let include_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
|
|
.join("../target/armv7-unknown-linux-musleabihf")
|
|
.join(&profile);
|
|
set_binary_var(&include_dir, "FILE_ROOTSHELL", "rootshell");
|
|
set_binary_var(&include_dir, "FILE_RAYHUNTER_DAEMON", "rayhunter-daemon");
|
|
|
|
let wpa_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../tools/build-wpa-supplicant/out");
|
|
set_binary_var(&wpa_dir, "FILE_WPA_SUPPLICANT", "wpa_supplicant");
|
|
set_binary_var(&wpa_dir, "FILE_WPA_CLI", "wpa_cli");
|
|
set_binary_var(&wpa_dir, "FILE_IW", "iw");
|
|
}
|
|
|
|
fn set_binary_var(include_dir: &Path, var: &str, file: &str) {
|
|
println!("cargo::rerun-if-env-changed={var}");
|
|
if std::env::var_os(var).is_some() {
|
|
return;
|
|
}
|
|
let binary = include_dir.join(file);
|
|
println!("cargo::rerun-if-changed={}", binary.display());
|
|
if binary.exists() {
|
|
println!("cargo::rustc-env={var}={}", binary.display());
|
|
} else {
|
|
println!(
|
|
"cargo::warning=Firmware binary {file} not present at {}; \
|
|
installers that need it will fail",
|
|
binary.display()
|
|
);
|
|
println!("cargo::rustc-env={var}=");
|
|
}
|
|
}
|