Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
73 lines (64 loc) · 2.49 KB
/
Copy pathbuild.rs
File metadata and controls
73 lines (64 loc) · 2.49 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
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/provider/apple_intelligence_bridge.swift");
if env::var_os("CARGO_FEATURE_APPLE_INTELLIGENCE").is_none() {
return;
}
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
if target_os != "macos" || target_arch != "aarch64" {
panic!(
"the `apple-intelligence` feature requires the aarch64-apple-darwin target \
(got target_os={target_os}, target_arch={target_arch})",
);
}
// Locate the macOS SDK via xcrun. If xcrun is missing, the user needs Xcode CLT.
let sdk_path_out = Command::new("xcrun")
.args(["-sdk", "macosx", "--show-sdk-path"])
.output()
.expect(
"failed to invoke `xcrun`; install the Xcode Command Line Tools \
(`xcode-select --install`) to build the apple-intelligence feature",
);
if !sdk_path_out.status.success() {
panic!(
"`xcrun -sdk macosx --show-sdk-path` failed: {}",
String::from_utf8_lossy(&sdk_path_out.stderr)
);
}
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let lib_path = out_dir.join("libapple_intelligence_bridge.a");
let src_path = "src/provider/apple_intelligence_bridge.swift";
let status = Command::new("xcrun")
.args([
"-sdk",
"macosx",
"swiftc",
"-emit-library",
"-static",
"-parse-as-library",
"-O",
"-target",
"arm64-apple-macos26.0",
"-module-name",
"AppleIntelligenceBridge",
"-o",
])
.arg(&lib_path)
.arg(src_path)
.status()
.expect("failed to invoke `xcrun swiftc`");
if !status.success() {
panic!("swiftc failed to build the Apple Intelligence bridge");
}
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rustc-link-lib=static=apple_intelligence_bridge");
println!("cargo:rustc-link-lib=framework=FoundationModels");
println!("cargo:rustc-link-lib=framework=Foundation");
// Pull in the system Swift runtime (ABI-stable since macOS 10.14.4).
println!("cargo:rustc-link-search=/usr/lib/swift");
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
}