-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
213 lines (184 loc) · 7.45 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
extern crate cmake;
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
))]
extern crate pkg_config;
fn main() {
// Build the static library with CMake.
let mut config = cmake::Config::new("rtaudio");
config.define("BUILD_SHARED_LIBS", "OFF");
config.define("RTAUDIO_BUILD_STATIC_LIBS", "ON");
#[cfg(target_os = "linux")]
{
println!("cargo:rustc-link-lib=dylib=stdc++");
#[cfg(feature = "alsa")]
{
config.define("RTAUDIO_API_ALSA", "ON");
match pkg_config::Config::new().statik(false).probe("alsa") {
Err(pkg_config::Error::Failure { command, output }) => panic!(
"Pkg-config failed - usually this is because alsa development headers are not installed.\n\n\
For Fedora users:\n# dnf install alsa-lib-devel\n\n\
For Debian/Ubuntu users:\n# apt-get install libasound2-dev\n\n\
pkg_config details:\n{}\n", pkg_config::Error::Failure { command, output }),
Err(e) => panic!("{}", e),
Ok(alsa_library) => {
for lib in alsa_library.libs {
println!("cargo:rustc-link-lib={}", lib);
}
}
};
}
#[cfg(not(feature = "alsa"))]
config.define("RTAUDIO_API_ALSA", "OFF");
#[cfg(feature = "pulse")]
{
config.define("RTAUDIO_API_PULSE", "ON");
match pkg_config::Config::new().statik(false).probe("libpulse-simple") {
Err(pkg_config::Error::Failure { command, output }) => panic!(
"Pkg-config failed - usually this is because pulse development headers are not installed.\n\n\
For Debian/Ubuntu users:\n# apt-get install libpulse-dev\n\n\
pkg_config details:\n{}\n", pkg_config::Error::Failure { command, output }),
Err(e) => panic!("{}", e),
Ok(pulse_library) => {
for lib in pulse_library.libs {
println!("cargo:rustc-link-lib={}", lib);
}
}
};
}
#[cfg(not(feature = "pulse"))]
config.define("RTAUDIO_API_PULSE", "OFF");
#[cfg(feature = "jack_linux")]
{
config.define("RTAUDIO_API_JACK", "ON");
match pkg_config::Config::new().statik(false).probe("jack") {
Err(pkg_config::Error::Failure { command, output }) => panic!(
"Pkg-config failed - usually this is because jack development headers are not installed.\n\n\
For Debian/Ubuntu users:\n# apt-get install libjack-dev\n\n\
pkg_config details:\n{}\n", pkg_config::Error::Failure { command, output }),
Err(e) => panic!("{}", e),
Ok(jack_library) => {
for lib in jack_library.libs {
println!("cargo:rustc-link-lib={}", lib);
}
}
};
}
#[cfg(not(feature = "jack_linux"))]
config.define("RTAUDIO_API_JACK", "OFF");
}
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
{
println!("cargo:rustc-link-lib=dylib=stdc++");
match pkg_config::Config::new().statik(false).probe("libossaudio") {
Err(pkg_config::Error::Failure { command, output }) => panic!(
"Pkg-config failed - usually this is because oss audio development headers are not installed.\n\n\
pkg_config details:\n{}\n", pkg_config::Error::Failure { command, output }),
Err(e) => panic!("{}", e),
Ok(oss_library) => {
for oss in oss_library.libs {
println!("cargo:rustc-link-lib={}", lib);
}
}
};
#[cfg(feature = "oss")]
config.define("RTAUDIO_API_OSS", "ON");
#[cfg(not(feature = "oss"))]
config.define("RTAUDIO_API_OSS", "OFF");
}
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-lib=dylib=c++");
#[cfg(feature = "coreaudio")]
{
config.define("RTAUDIO_API_CORE", "ON");
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=CoreAudio");
}
#[cfg(not(feature = "coreaudio"))]
config.define("RTAUDIO_API_CORE", "OFF");
// TODO: Jack support on MacOS
// How do you install and link the Jack library files?
config.define("RTAUDIO_API_JACK", "OFF");
/*
#[cfg(feature = "jack_macos")]
config.define("RTAUDIO_API_JACK", "ON");
#[cfg(not(feature = "jack_macos"))]
config.define("RTAUDIO_API_JACK", "OFF");
*/
}
#[cfg(target_os = "windows")]
{
println!("cargo:rustc-link-lib=winmm");
println!("cargo:rustc-link-lib=ole32");
println!("cargo:rustc-link-lib=user32");
#[cfg(feature = "ds")]
{
config.define("RTAUDIO_API_DS", "ON");
println!("cargo:rustc-link-lib=dsound");
}
#[cfg(not(feature = "ds"))]
config.define("RTAUDIO_API_DS", "OFF");
#[cfg(feature = "asio")]
config.define("RTAUDIO_API_ASIO", "ON");
#[cfg(not(feature = "asio"))]
config.define("RTAUDIO_API_ASIO", "OFF");
#[cfg(feature = "wasapi")]
{
config.define("RTAUDIO_API_WASAPI", "ON");
println!("cargo:rustc-link-lib=ksuser");
println!("cargo:rustc-link-lib=mfplat");
println!("cargo:rustc-link-lib=mfuuid");
println!("cargo:rustc-link-lib=wmcodecdspuuid");
}
#[cfg(not(feature = "wasapi"))]
config.define("RTAUDIO_API_WASAPI", "OFF");
}
let dst = config.build();
// Sometimes the path can be called lib64
let libdir_path = ["lib", "lib64"]
.iter()
.map(|dir| dst.clone().join(dir))
.find(|path| path.exists())
.unwrap_or_else(|| {
panic!(
"Could not find rtaudio static lib path. Check `target/debug/build/rtaudio-sys-*/out` for a lib or lib64 folder."
);
});
// Tell cargo to link to the compiled library.
println!(
"cargo:rustc-link-search=native={}",
libdir_path.to_str().unwrap()
);
#[cfg(not(target_os = "windows"))]
{
println!("cargo:rustc-link-lib=static=rtaudio");
}
#[cfg(target_os = "windows")]
{
#[cfg(debug_assertions)]
println!("cargo:rustc-link-lib=static=rtaudiod");
#[cfg(not(debug_assertions))]
println!("cargo:rustc-link-lib=static=rtaudio");
}
/*
let mut headers_path = dst;
headers_path.push("include/rtaudio/rtaudio_c.h");
// Generate Rust bindings from the C header.
let bindings = bindgen::Builder::default()
.header(headers_path.to_str().unwrap())
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
bindings
.write_to_file(out_path)
.expect("Couldn't write bindings!");
*/
}