@@ -8,22 +8,30 @@ fn sdk_path(target: &str) -> Result<String, std::io::Error> {
88 }
99
1010 use std:: process:: Command ;
11-
12- let sdk = if target. contains ( "apple-darwin" ) {
13- "macosx"
14- } else if target == "x86_64-apple-ios"
15- || target == "i386-apple-ios"
16- || target == "aarch64-apple-ios-sim"
17- {
18- "iphonesimulator"
19- } else if target == "aarch64-apple-ios"
20- || target == "armv7-apple-ios"
21- || target == "armv7s-apple-ios"
22- {
23- "iphoneos"
24- } else {
25- unreachable ! ( ) ;
11+ let sdk = match target {
12+ "aarch64-apple-darwin" | "x86_64-apple-darwin" => {
13+ "macosx"
14+ } ,
15+ "x86_64-apple-ios" | "i386-apple-ios" | "aarch64-apple-ios-sim" => {
16+ "iphonesimulator"
17+ } ,
18+ "aarch64-apple-ios" | "armv7-apple-ios" | "armv7s-apple-ios" => {
19+ "iphoneos"
20+ } ,
21+ "aarch64-apple-visionos-sim" => "xrsimulator" ,
22+ "aarch64-apple-visionos" => "xros" ,
23+
24+ "aarch64-apple-tvos-sim" | "x86_64-apple-tvos" => "appletvsimulator" ,
25+ "aarch64-apple-tvos" => "appletvos" ,
26+
27+ "aarch64-apple-watchos" | "armv7k-apple-watchos" | "arm64_32-apple-watchos" => "watchos" ,
28+ "aarch64-apple-watchos-sim" | "x86_64-apple-watchos-sim" => "watchsimulator" ,
29+
30+ target => {
31+ panic ! ( "{} is not supported!" , target) ;
32+ }
2633 } ;
34+
2735 let output = Command :: new ( "xcrun" )
2836 . args ( & [ "--sdk" , sdk, "--show-sdk-path" ] )
2937 . output ( ) ?
@@ -52,42 +60,45 @@ fn build(sdk_path: Option<&str>, target: &str) {
5260 // Since iOS 10.0 and macOS 10.12, all the functionality in AudioUnit
5361 // moved to AudioToolbox, and the AudioUnit headers have been simple
5462 // wrappers ever since.
55- if target. contains ( "apple-ios" ) {
56- // On iOS, the AudioUnit framework does not have (and never had) an
57- // actual dylib to link to, it is just a few header files.
58- // The AudioToolbox framework contains the symbols instead.
59- println ! ( "cargo:rustc-link-lib=framework=AudioToolbox" ) ;
60- } else {
63+ if target. contains ( "apple-darwin" ) {
6164 // On macOS, the symbols are present in the AudioToolbox framework,
6265 // but only on macOS 10.12 and above.
6366 //
6467 // However, unlike on iOS, the AudioUnit framework on macOS
6568 // contains a dylib with the desired symbols, that we can link to
6669 // (in later versions just re-exports from AudioToolbox).
6770 println ! ( "cargo:rustc-link-lib=framework=AudioUnit" ) ;
71+ headers. push ( "AudioUnit/AudioUnit.h" ) ;
72+ } else if !target. contains ( "apple-watchos" ) {
73+ // On iOS, the AudioUnit framework does not have (and never had) an
74+ // actual dylib to link to, it is just a few header files.
75+ // The AudioToolbox framework contains the symbols instead.
76+ println ! ( "cargo:rustc-link-lib=framework=AudioToolbox" ) ;
77+ headers. push ( "AudioUnit/AudioUnit.h" ) ;
6878 }
69- headers. push ( "AudioUnit/AudioUnit.h" ) ;
7079 }
7180
7281 #[ cfg( feature = "audio_toolbox" ) ]
7382 {
7483 println ! ( "cargo:rustc-link-lib=framework=AudioToolbox" ) ;
75- headers. push ( "AudioToolbox/AudioToolbox.h" ) ;
84+ if !target. contains ( "apple-watchos" ) {
85+ headers. push ( "AudioToolbox/AudioToolbox.h" ) ;
86+ }
7687 }
7788
7889 #[ cfg( feature = "core_audio" ) ]
7990 {
8091 println ! ( "cargo:rustc-link-lib=framework=CoreAudio" ) ;
8192
82- if target. contains ( "apple-ios" ) {
83- headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
84- } else {
93+ if target. contains ( "apple-darwin" ) {
8594 headers. push ( "CoreAudio/CoreAudio.h" ) ;
8695
8796 #[ cfg( feature = "audio_server_plugin" ) ]
8897 {
8998 headers. push ( "CoreAudio/AudioServerPlugIn.h" ) ;
9099 }
100+ } else {
101+ headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
91102 }
92103 }
93104
@@ -100,9 +111,11 @@ fn build(sdk_path: Option<&str>, target: &str) {
100111
101112 #[ cfg( feature = "open_al" ) ]
102113 {
103- println ! ( "cargo:rustc-link-lib=framework=OpenAL" ) ;
104- headers. push ( "OpenAL/al.h" ) ;
105- headers. push ( "OpenAL/alc.h" ) ;
114+ if target. contains ( "apple-tvos" ) || target. contains ( "apple-ios" ) || target. contains ( "apple-darwin" ) {
115+ println ! ( "cargo:rustc-link-lib=framework=OpenAL" ) ;
116+ headers. push ( "OpenAL/al.h" ) ;
117+ headers. push ( "OpenAL/alc.h" ) ;
118+ }
106119 }
107120
108121 #[ cfg( all( feature = "core_midi" ) ) ]
@@ -123,21 +136,23 @@ fn build(sdk_path: Option<&str>, target: &str) {
123136 // See https://github.com/rust-lang/rust-bindgen/issues/1211
124137 // Technically according to the llvm mailing list, the argument to clang here should be
125138 // -arch arm64 but it looks cleaner to just change the target.
126- let target = if target == "aarch64-apple-ios" {
127- "arm64-apple-ios"
128- } else if target == "aarch64-apple-darwin" {
129- "arm64-apple-darwin"
130- } else {
131- target
139+ // The full list of clang targtes may be:
140+ // https://github.com/llvm/llvm-project/blob/7476c20c481cbccbdb89139fb94620e083015932/llvm/include/llvm/BinaryFormat/MachO.def#L123-L138
141+ let clang_target = match target {
142+ "aarch64-apple-ios" => "arm64-apple-ios" ,
143+ "aarch64-apple-visionos" => "arm64-apple-xros" ,
144+ "aarch64-apple-visionos-sim" => "aarch64-apple-xros-simulator" ,
145+ "aarch64-apple-darwin" => "arm64-apple-darwin" ,
146+ target => target,
132147 } ;
133148 builder = builder. size_t_is_usize ( true ) ;
134149
135- builder = builder. clang_args ( & [ & format ! ( "--target={}" , target ) ] ) ;
150+ builder = builder. clang_args ( & [ & format ! ( "--target={}" , clang_target ) ] ) ;
136151
137152 if let Some ( sdk_path) = sdk_path {
138153 builder = builder. clang_args ( & [ "-isysroot" , sdk_path] ) ;
139154 }
140- if target. contains ( "apple-ios " ) {
155+ if ! target. contains ( "apple-darwin " ) {
141156 // time.h as has a variable called timezone that conflicts with some of the objective-c
142157 // calls from NSCalendar.h in the Foundation framework. This removes that one variable.
143158 builder = builder. blocklist_item ( "timezone" ) ;
@@ -159,7 +174,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
159174 // Generate the bindings.
160175 builder = builder. trust_clang_mangling ( false ) . derive_default ( true ) ;
161176
162- let bindings = builder. generate ( ) . expect ( "unable to generate bindings" ) ;
177+ let bindings = builder. generate ( ) . expect ( format ! ( "unable to generate bindings for {target}" ) . as_str ( ) ) ;
163178
164179 // Write them to the crate root.
165180 bindings
@@ -169,8 +184,8 @@ fn build(sdk_path: Option<&str>, target: &str) {
169184
170185fn main ( ) {
171186 let target = std:: env:: var ( "TARGET" ) . unwrap ( ) ;
172- if !( target. contains ( "apple-darwin" ) || target . contains ( "apple-ios" ) ) {
173- panic ! ( "coreaudio-sys requires macos or ios target" ) ;
187+ if !target. contains ( "apple" ) {
188+ panic ! ( "coreaudio-sys requires an apple target. " ) ;
174189 }
175190
176191 let directory = sdk_path ( & target) . ok ( ) ;
0 commit comments