返回 CodeWhale
build.rs
根目录 / crates / tui / build.rs
1 use std::path::PathBuf;
2
3 fn main() {
4 // Shared target directories may reuse this executable in another worktree.
5 let manifest_dir = PathBuf::from(
6 std::env::var_os("CARGO_MANIFEST_DIR").expect("Cargo sets CARGO_MANIFEST_DIR"),
7 );
8 println!("cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR");
9 codewhale_build_support::declare_rerun_conditions(&manifest_dir);
10 build_computer_use_helper(&manifest_dir);
11 codewhale_build_support::emit_build_version(&manifest_dir, env!("CARGO_PKG_VERSION"));
12 }
13
14 /// Ship native computer-use support with macOS binaries. Requiring clang on
15 /// the customer's machine would make the built-in plugin a source-only demo.
16 fn build_computer_use_helper(manifest_dir: &std::path::Path) {
17 if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("macos") {
18 return;
19 }
20 let source = manifest_dir.join("plugins/computer-use/src/backends/darwin-accessibility.m");
21 println!("cargo:rerun-if-changed={}", source.display());
22 println!(
23 "cargo:rerun-if-changed={}",
24 source.with_file_name("darwin-recording.h").display()
25 );
26 println!(
27 "cargo:rerun-if-changed={}",
28 source.with_file_name("darwin-ocr.h").display()
29 );
30 println!("cargo:rerun-if-env-changed=CODEWHALE_CU_SIGN_IDENTITY");
31 let arch = match std::env::var("CARGO_CFG_TARGET_ARCH").as_deref() {
32 Ok("aarch64") => "arm64",
33 Ok("x86_64") => "x86_64",
34 other => panic!("unsupported macOS computer-use architecture: {other:?}"),
35 };
36 let output = PathBuf::from(std::env::var_os("OUT_DIR").expect("Cargo sets OUT_DIR"))
37 .join("computer-use-accessibility");
38 let compiled = std::process::Command::new("xcrun")
39 .args([
40 "clang",
41 "-fobjc-arc",
42 "-Os",
43 "-arch",
44 arch,
45 "-mmacosx-version-min=13.0",
46 "-framework",
47 "Cocoa",
48 "-framework",
49 "ApplicationServices",
50 "-framework",
51 "ScreenCaptureKit",
52 "-framework",
53 "AVFoundation",
54 "-framework",
55 "CoreMedia",
56 "-framework",
57 "Vision",
58 ])
59 .arg(&source)
60 .arg("-o")
61 .arg(&output)
62 .output()
63 .expect("macOS builds require Xcode Command Line Tools to package Computer Use");
64 assert!(
65 compiled.status.success(),
66 "Computer Use helper compilation failed: {}",
67 String::from_utf8_lossy(&compiled.stderr)
68 );
69 // Developer builds use ad-hoc signing; release builders can supply the
70 // same Developer ID as the app. No keychain lookup or credential copying.
71 let identity = std::env::var("CODEWHALE_CU_SIGN_IDENTITY").unwrap_or_else(|_| "-".into());
72 let signed = std::process::Command::new("codesign")
73 .args([
74 "--force",
75 if identity == "-" {
76 "--timestamp=none"
77 } else {
78 "--timestamp"
79 },
80 "--options",
81 "runtime",
82 "--identifier",
83 "net.codewhale.computer-use.helper",
84 "--sign",
85 ])
86 .arg(&identity)
87 .arg(&output)
88 .output()
89 .expect("macOS builds require codesign to package Computer Use");
90 assert!(
91 signed.status.success(),
92 "Computer Use helper signing failed: {}",
93 String::from_utf8_lossy(&signed.stderr)
94 );
95 }
96
96 lines RUST