@@ -8,22 +8,30 @@ fn sdk_path(target: &str) -> Result<String, std::io::Error> {
8
8
}
9
9
10
10
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
+ }
26
33
} ;
34
+
27
35
let output = Command :: new ( "xcrun" )
28
36
. args ( & [ "--sdk" , sdk, "--show-sdk-path" ] )
29
37
. output ( ) ?
@@ -52,42 +60,46 @@ fn build(sdk_path: Option<&str>, target: &str) {
52
60
// Since iOS 10.0 and macOS 10.12, all the functionality in AudioUnit
53
61
// moved to AudioToolbox, and the AudioUnit headers have been simple
54
62
// 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" ) {
61
64
// On macOS, the symbols are present in the AudioToolbox framework,
62
65
// but only on macOS 10.12 and above.
63
66
//
64
67
// However, unlike on iOS, the AudioUnit framework on macOS
65
68
// contains a dylib with the desired symbols, that we can link to
66
69
// (in later versions just re-exports from AudioToolbox).
67
70
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" ) ;
68
79
}
69
- headers. push ( "AudioUnit/AudioUnit.h" ) ;
70
80
}
71
81
72
82
#[ cfg( feature = "audio_toolbox" ) ]
73
83
{
74
84
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
+ }
76
88
}
77
89
78
90
#[ cfg( feature = "core_audio" ) ]
79
91
{
80
92
println ! ( "cargo:rustc-link-lib=framework=CoreAudio" ) ;
81
93
82
- if target. contains ( "apple-ios" ) {
83
- headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
84
- } else {
94
+ if target. contains ( "apple-darwin" ) {
85
95
headers. push ( "CoreAudio/CoreAudio.h" ) ;
86
96
87
97
#[ cfg( feature = "audio_server_plugin" ) ]
88
98
{
89
99
headers. push ( "CoreAudio/AudioServerPlugIn.h" ) ;
90
100
}
101
+ } else {
102
+ headers. push ( "CoreAudio/CoreAudioTypes.h" ) ;
91
103
}
92
104
}
93
105
@@ -100,9 +112,11 @@ fn build(sdk_path: Option<&str>, target: &str) {
100
112
101
113
#[ cfg( feature = "open_al" ) ]
102
114
{
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
+ }
106
120
}
107
121
108
122
#[ cfg( all( feature = "core_midi" ) ) ]
@@ -123,21 +137,23 @@ fn build(sdk_path: Option<&str>, target: &str) {
123
137
// See https://github.com/rust-lang/rust-bindgen/issues/1211
124
138
// Technically according to the llvm mailing list, the argument to clang here should be
125
139
// -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,
132
148
} ;
133
149
builder = builder. size_t_is_usize ( true ) ;
134
150
135
- builder = builder. clang_args ( & [ & format ! ( "--target={}" , target ) ] ) ;
151
+ builder = builder. clang_args ( & [ & format ! ( "--target={}" , clang_target ) ] ) ;
136
152
137
153
if let Some ( sdk_path) = sdk_path {
138
154
builder = builder. clang_args ( & [ "-isysroot" , sdk_path] ) ;
139
155
}
140
- if target. contains ( "apple-ios " ) {
156
+ if ! target. contains ( "apple-darwin " ) {
141
157
// time.h as has a variable called timezone that conflicts with some of the objective-c
142
158
// calls from NSCalendar.h in the Foundation framework. This removes that one variable.
143
159
builder = builder. blocklist_item ( "timezone" ) ;
@@ -159,7 +175,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
159
175
// Generate the bindings.
160
176
builder = builder. trust_clang_mangling ( false ) . derive_default ( true ) ;
161
177
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 ( ) ) ;
163
179
164
180
// Write them to the crate root.
165
181
bindings
@@ -169,8 +185,8 @@ fn build(sdk_path: Option<&str>, target: &str) {
169
185
170
186
fn main ( ) {
171
187
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. " ) ;
174
190
}
175
191
176
192
let directory = sdk_path ( & target) . ok ( ) ;
0 commit comments