| 1 | //! Builds the Settings window (`macos/Settings.swift`) on macOS, as `leaf-settings` next to the
|
| 2 | //! `leaf` binary, where leaf looks for it.
|
| 3 |
|
| 4 | use std::path::PathBuf;
|
| 5 | use std::process::Command;
|
| 6 |
|
| 7 | fn main() {
|
| 8 | println!("cargo:rerun-if-changed=macos/Settings.swift");
|
| 9 | println!("cargo:rerun-if-changed=macos/Settings-Info.plist");
|
| 10 | if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("macos") {
|
| 11 | return;
|
| 12 | }
|
| 13 | // OUT_DIR is target/<profile>/build/leaf-<hash>/out.
|
| 14 | let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
| 15 | let Some(bin_dir) = out.ancestors().nth(3) else { return };
|
| 16 | let status = Command::new("swiftc")
|
| 17 | .args(["-O", "-parse-as-library", "-swift-version", "5", "macos/Settings.swift", "-o"])
|
| 18 | .arg(bin_dir.join("leaf-settings"))
|
| 19 | // Gives the window's process a name ("Leaf Settings") in the menu bar and Dock.
|
| 20 | .args(["-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist"])
|
| 21 | .args(["-Xlinker", "macos/Settings-Info.plist"])
|
| 22 | .status();
|
| 23 | match status {
|
| 24 | Ok(s) if s.success() => {}
|
| 25 | Ok(s) => println!("cargo:warning=building the Settings window failed ({s}); Settings… won't open"),
|
| 26 | Err(e) => println!("cargo:warning=can't run swiftc ({e}); the Settings window won't be built"),
|
| 27 | }
|
| 28 | }
|