| 1 |
// Copyright © 2018 Mozilla Foundation |
| 2 |
// |
| 3 |
// This program is made available under an ISC-style license. See the |
| 4 |
// accompanying file LICENSE for details. |
| 5 |
|
| 6 |
#[cfg(not(feature = "gecko-in-tree"))] |
| 7 |
extern crate cmake; |
| 8 |
#[cfg(not(feature = "gecko-in-tree"))] |
| 9 |
extern crate pkg_config; |
| 10 |
|
| 11 |
use std::env; |
| 12 |
use std::fs; |
| 13 |
use std::path::Path; |
| 14 |
use std::process::Command; |
| 15 |
|
| 16 |
macro_rules! t { |
| 17 |
($e:expr) => { |
| 18 |
match $e { |
| 19 |
Ok(e) => e, |
| 20 |
Err(e) => panic!("{} failed with {}", stringify!($e), e), |
| 21 |
} |
| 22 |
}; |
| 23 |
} |
| 24 |
|
| 25 |
#[cfg(feature = "gecko-in-tree")] |
| 26 |
fn main() {} |
| 27 |
|
| 28 |
#[cfg(not(feature = "gecko-in-tree"))] |
| 29 |
fn main() { |
| 30 |
if env::var("LIBCUBEB_SYS_USE_PKG_CONFIG").is_ok() |
| 31 |
&& pkg_config::find_library("libcubeb").is_ok() |
| 32 |
{ |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
if !Path::new("libcubeb/.git").exists() { |
| 37 |
let _ = Command::new("git") |
| 38 |
.args(["submodule", "update", "--init", "--recursive"]) |
| 39 |
.status(); |
| 40 |
} |
| 41 |
|
| 42 |
let target = env::var("TARGET").unwrap(); |
| 43 |
let windows = target.contains("windows"); |
| 44 |
let darwin = target.contains("darwin"); |
| 45 |
let freebsd = target.contains("freebsd"); |
| 46 |
let android = target.contains("android"); |
| 47 |
let mut cfg = cmake::Config::new("libcubeb"); |
| 48 |
|
| 49 |
if darwin { |
| 50 |
let cmake_osx_arch = if target.contains("aarch64") { |
| 51 |
// Apple Silicon |
| 52 |
"arm64" |
| 53 |
} else { |
| 54 |
// Assuming Intel (x86_64) |
| 55 |
"x86_64" |
| 56 |
}; |
| 57 |
cfg.define("CMAKE_OSX_ARCHITECTURES", cmake_osx_arch); |
| 58 |
} |
| 59 |
|
| 60 |
let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap()); |
| 61 |
t!(fs::create_dir_all(env::var("OUT_DIR").unwrap())); |
| 62 |
|
| 63 |
env::remove_var("DESTDIR"); |
| 64 |
let dst = cfg |
| 65 |
.define("BUILD_SHARED_LIBS", "OFF") |
| 66 |
.define("BUILD_TESTS", "OFF") |
| 67 |
.define("BUILD_TOOLS", "OFF") |
| 68 |
.build(); |
| 69 |
|
| 70 |
println!("cargo:rustc-link-lib=static=cubeb"); |
| 71 |
if windows { |
| 72 |
println!("cargo:rustc-link-lib=dylib=avrt"); |
| 73 |
println!("cargo:rustc-link-lib=dylib=ksuser"); |
| 74 |
println!("cargo:rustc-link-lib=dylib=ole32"); |
| 75 |
println!("cargo:rustc-link-lib=dylib=user32"); |
| 76 |
println!("cargo:rustc-link-lib=dylib=winmm"); |
| 77 |
println!("cargo:rustc-link-search=native={}/lib", dst.display()); |
| 78 |
} else if darwin { |
| 79 |
println!("cargo:rustc-link-lib=framework=AudioUnit"); |
| 80 |
println!("cargo:rustc-link-lib=framework=CoreAudio"); |
| 81 |
println!("cargo:rustc-link-lib=framework=CoreServices"); |
| 82 |
println!("cargo:rustc-link-lib=dylib=c++"); |
| 83 |
println!("cargo:rustc-link-search=native={}/lib", dst.display()); |
| 84 |
} else { |
| 85 |
if freebsd || android { |
| 86 |
println!("cargo:rustc-link-lib=dylib=c++"); |
| 87 |
} else { |
| 88 |
println!("cargo:rustc-link-lib=dylib=stdc++"); |
| 89 |
} |
| 90 |
println!("cargo:rustc-link-search=native={}/lib", dst.display()); |
| 91 |
println!("cargo:rustc-link-search=native={}/lib64", dst.display()); |
| 92 |
|
| 93 |
// Ignore the result of find_library. We don't care if the |
| 94 |
// libraries are missing. |
| 95 |
let _ = pkg_config::find_library("alsa"); |
| 96 |
let _ = pkg_config::find_library("libpulse"); |
| 97 |
let _ = pkg_config::find_library("jack"); |
| 98 |
let _ = pkg_config::find_library("speexdsp"); |
| 99 |
if android { |
| 100 |
println!("cargo:rustc-link-lib=dylib=OpenSLES"); |
| 101 |
} |
| 102 |
} |
| 103 |
} |