@@ -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" => "watchos" ,
28+ "aarch64-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,46 @@ 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+ } else {
72+ // On iOS, the AudioUnit framework does not have (and never had) an
73+ // actual dylib to link to, it is just a few header files.
74+ // The AudioToolbox framework contains the symbols instead.
75+ println ! ( "cargo:rustc-link-lib=framework=AudioToolbox" ) ;
76+ }
77+ if !target. contains ( "apple-watchos" ) {
78+ headers. push ( "AudioUnit/AudioUnit.h" ) ;
6879 }
69- headers. push ( "AudioUnit/AudioUnit.h" ) ;
7080 }
7181
7282 #[ cfg( feature = "audio_toolbox" ) ]
7383 {
7484 println ! ( "cargo:rustc-link-lib=framework=AudioToolbox" ) ;
75- headers. push ( "AudioToolbox/AudioToolbox.h" ) ;
85+ if !target. contains ( "apple-watchos" ) {
86+ headers. push ( "AudioToolbox/AudioToolbox.h" ) ;
87+ }
7688 }
7789
7890 #[ cfg( feature = "core_audio" ) ]
7991 {
8092 println ! ( "cargo:rustc-link-lib=framework=CoreAudio" ) ;
8193
82- if target. contains ( "apple-ios" ) {
83- headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
84- } else {
94+ if target. contains ( "apple-darwin" ) {
8595 headers. push ( "CoreAudio/CoreAudio.h" ) ;
8696
8797 #[ cfg( feature = "audio_server_plugin" ) ]
8898 {
8999 headers. push ( "CoreAudio/AudioServerPlugIn.h" ) ;
90100 }
101+ } else {
102+ headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
91103 }
92104 }
93105
@@ -100,9 +112,11 @@ fn build(sdk_path: Option<&str>, target: &str) {
100112
101113 #[ cfg( feature = "open_al" ) ]
102114 {
103- println ! ( "cargo:rustc-link-lib=framework=OpenAL" ) ;
104- headers. push ( "OpenAL/al.h" ) ;
105- headers. push ( "OpenAL/alc.h" ) ;
115+ if target. contains ( "apple-tvos" ) || target. contains ( "apple-ios" ) || target. contains ( "apple-darwin" ) {
116+ println ! ( "cargo:rustc-link-lib=framework=OpenAL" ) ;
117+ headers. push ( "OpenAL/al.h" ) ;
118+ headers. push ( "OpenAL/alc.h" ) ;
119+ }
106120 }
107121
108122 #[ cfg( all( feature = "core_midi" ) ) ]
@@ -123,21 +137,23 @@ fn build(sdk_path: Option<&str>, target: &str) {
123137 // See https://github.com/rust-lang/rust-bindgen/issues/1211
124138 // Technically according to the llvm mailing list, the argument to clang here should be
125139 // -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
140+ // The full list of clang targtes may be:
141+ // https://github.com/llvm/llvm-project/blob/7476c20c481cbccbdb89139fb94620e083015932/llvm/include/llvm/BinaryFormat/MachO.def#L123-L138
142+ let clang_target = match target {
143+ "aarch64-apple-ios" => "arm64-apple-ios" ,
144+ "aarch64-apple-visionos" => "arm64-apple-xros" ,
145+ "aarch64-apple-visionos-sim" => "aarch64-apple-xros-simulator" ,
146+ "aarch64-apple-darwin" => "arm64-apple-darwin" ,
147+ target => target,
132148 } ;
133149 builder = builder. size_t_is_usize ( true ) ;
134150
135- builder = builder. clang_args ( & [ & format ! ( "--target={}" , target ) ] ) ;
151+ builder = builder. clang_args ( & [ & format ! ( "--target={}" , clang_target ) ] ) ;
136152
137153 if let Some ( sdk_path) = sdk_path {
138154 builder = builder. clang_args ( & [ "-isysroot" , sdk_path] ) ;
139155 }
140- if target. contains ( "apple-ios " ) {
156+ if ! target. contains ( "apple-darwin " ) {
141157 // time.h as has a variable called timezone that conflicts with some of the objective-c
142158 // calls from NSCalendar.h in the Foundation framework. This removes that one variable.
143159 builder = builder. blocklist_item ( "timezone" ) ;
@@ -159,7 +175,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
159175 // Generate the bindings.
160176 builder = builder. trust_clang_mangling ( false ) . derive_default ( true ) ;
161177
162- let bindings = builder. generate ( ) . expect ( "unable to generate bindings" ) ;
178+ let bindings = builder. generate ( ) . expect ( format ! ( "unable to generate bindings for {target}" ) . as_str ( ) ) ;
163179
164180 // Write them to the crate root.
165181 bindings
@@ -169,8 +185,8 @@ fn build(sdk_path: Option<&str>, target: &str) {
169185
170186fn main ( ) {
171187 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" ) ;
188+ if !target. contains ( "apple" ) {
189+ panic ! ( "coreaudio-sys requires an apple target. " ) ;
174190 }
175191
176192 let directory = sdk_path ( & target) . ok ( ) ;
0 commit comments