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
fn main() {
// The Swift runtime, which every platform needs.
println!("cargo:rustc-link-lib=dylib=swiftCore");
// Not `-lswift_Concurrency`. Its install name is `@rpath/libswift_Concurrency.dylib`
// — it lives only in the dyld shared cache, with no file on disk — so a binary
// that link-references it needs `/usr/lib/swift` on its `LC_RPATH`. A build
// script's `cargo::rustc-link-arg` applies to its own package's targets and not
// to a dependent's, so the rpath this crate adds for itself does not reach
// anyone who depends on it: an external consumer linked fine and then died in
// dyld with "Library not loaded".
//
// The symbols are not lost by dropping it. Every concurrency entry point this
// crate calls is resolved with `dlsym` or arrives through SwiftUI, which links
// the library itself — so the process has it either way, and nothing names it
// in a load command that the loader then has to find on a path.
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
println!("cargo:rustc-link-lib=framework=SwiftUI");
// SwiftUI needs a host UI framework *loaded* — but it declares that
// dependency itself, so dyld brings it in whether or not this binary names
// it. On the Mac AppKit is linked anyway: `window.rs` calls `NSApp.run()`,
// and the offscreen capture path calls AppKit functions directly.
//
// On iOS nothing here needs a UIKit symbol at link time. Classes are
// reached through `dlsym`, and the one genuine extern — `UIApplicationMain`
// — lives behind the `uikit-entry` feature. Naming the framework anyway
// would put it in the load commands of an application that never calls into
// it, which is misleading about what drives the interface: `App.main()`
// does, and it needs no UIKit of ours.
println!("cargo:rerun-if-changed=build.rs");
match std::env::var("CARGO_CFG_TARGET_OS").as_deref() {
Ok("macos") => println!("cargo:rustc-link-lib=framework=AppKit"),
_ => {
if std::env::var("CARGO_FEATURE_UIKIT_ENTRY").is_ok() {
println!("cargo:rustc-link-lib=framework=UIKit");
}
}
}
// Capture on non-Mac platforms goes through CoreGraphics and ImageIO
// instead of `NSBitmapImageRep`; both are present everywhere.
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=CoreGraphics");
println!("cargo:rustc-link-lib=framework=ImageIO");
// For compiling shader source at run time, which is the only way to get a
// shader onto a device: the offline Metal compiler ships with Xcode alone.
println!("cargo:rustc-link-lib=framework=Metal");
}