@@ -3,6 +3,7 @@ use std::error::Error;
33use std:: fs:: File ;
44use std:: io:: Write ;
55use std:: path:: Path ;
6+ use std:: process:: Command ;
67
78fn main ( ) -> Result < ( ) , Box < dyn Error > > {
89 let out_dir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR is set for build scripts" ) ;
@@ -29,5 +30,48 @@ fn main() -> Result<(), Box<dyn Error>> {
2930 writeln ! ( f, "pub const USER_AGENT: &str = \" sentry-cli/{arch}\" ;" ) ?;
3031 println ! ( "cargo:rerun-if-changed=build.rs\n " ) ;
3132
33+ if platform == "darwin" {
34+ println ! ( "cargo:rerun-if-changed=src/apple/AssetCatalogReader.swift" ) ;
35+ println ! ( "cargo:rerun-if-changed=src/apple/safeValueForKey.h" ) ;
36+ println ! ( "cargo:rerun-if-changed=src/apple/safeValueForKey.m" ) ;
37+ // Compile Objective-C
38+ let status = Command :: new ( "clang" )
39+ . args ( [
40+ "src/apple/safeValueForKey.m" ,
41+ "-c" ,
42+ "-o" ,
43+ "safeValueForKey.o" ,
44+ "-fobjc-arc" ,
45+ ] )
46+ . status ( )
47+ . expect ( "Failed to compile Objective-C" ) ;
48+
49+ assert ! ( status. success( ) , "clang failed" ) ;
50+
51+ // Compile Swift and link ObjC
52+ let status = Command :: new ( "swiftc" )
53+ . args ( [
54+ "-emit-library" ,
55+ "-static" ,
56+ "-o" ,
57+ "libswiftbridge.a" ,
58+ "src/apple/AssetCatalogReader.swift" ,
59+ "safeValueForKey.o" ,
60+ "-import-objc-header" ,
61+ "src/apple/safeValueForKey.h" ,
62+ ] )
63+ . status ( )
64+ . expect ( "Failed to compile Swift" ) ;
65+
66+ assert ! ( status. success( ) , "swiftc failed" ) ;
67+
68+ println ! ( "cargo:rustc-link-search=native=." ) ;
69+ println ! ( "cargo:rustc-link-lib=static=swiftbridge" ) ;
70+
71+ println ! ( "cargo:rustc-link-arg=-F" ) ;
72+ println ! ( "cargo:rustc-link-arg=/System/Library/PrivateFrameworks" ) ;
73+ println ! ( "cargo:rustc-link-lib=framework=CoreUI" ) ;
74+ }
75+
3276 Ok ( ( ) )
3377}
0 commit comments