-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
63 lines (55 loc) · 2.4 KB
/
build.rs
File metadata and controls
63 lines (55 loc) · 2.4 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
//! Build script — macOS only.
//!
//! Links `vendor/Syphon.framework.prebuilt/Syphon.framework` into the
//! final binary. A pre-built framework is committed to the tree (see
//! `vendor/Syphon.framework.prebuilt/README.md` for provenance) so
//! PatchWork builds with only Command Line Tools installed — no full
//! Xcode required.
//!
//! On non-macOS targets this script is a no-op so cross-compilation
//! from non-mac hosts still works for the non-Syphon parts of the tree.
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if !cfg!(target_os = "macos") {
return;
}
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let framework_dir = manifest_dir
.join("vendor")
.join("Syphon.framework.prebuilt");
let framework_bin = framework_dir
.join("Syphon.framework")
.join("Versions/A/Syphon");
// Rebuild-trigger: if someone re-vendors the binary, relink.
println!("cargo:rerun-if-changed={}", framework_bin.display());
if !framework_bin.exists() {
panic!(
"vendored Syphon.framework missing — expected at {}\n\n\
The framework should be committed to vendor/Syphon.framework.prebuilt/. \
See that directory's README.md for how to regenerate.",
framework_bin.display()
);
}
// Tell rustc where to find the framework at link time.
println!(
"cargo:rustc-link-search=framework={}",
framework_dir.display()
);
println!("cargo:rustc-link-lib=framework=Syphon");
// Runtime rpath: tried in order at launch; first hit wins.
// 1. Absolute dev path — so `cargo run` finds the vendored
// framework without installing anything.
// 2. Standard Apple convention — `.app/Contents/Frameworks/`.
// 3. `cargo-packager`'s convention — it puts `resources`
// entries at `.app/Contents/Resources/…` instead of
// `Contents/Frameworks/`. Packaging copies the vendored
// framework to `Contents/Resources/Frameworks/Syphon.framework`,
// so this rpath resolves in the packaged `.app`.
println!(
"cargo:rustc-link-arg=-Wl,-rpath,{}",
framework_dir.display()
);
println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../Frameworks");
println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../Resources/Frameworks");
}