use bindgen;
use std::{
env, fs,
path::{Path, PathBuf},
};
fn main() {
match env::consts::OS {
"linux" => linux(),
"macos" => macos(),
_ => (),
};
}
fn linux() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
fs::copy(
"./SpeechSDK/linux/lib/x64/libMicrosoft.CognitiveServices.Speech.core.so",
Path::new(&out_path).join(
"libMicrosoft.CognitiveServices.Speech.core.so"
)
).unwrap();
println!("cargo:rustc-link-search=native={}", out_path.display());
println!(
"cargo:rustc-link-lib=dylib=Microsoft.CognitiveServices.Speech.core"
);
let bindings = bindgen::Builder::default()
.header("c_api/wrapper.h")
.clang_arg("-ISpeechSDK/linux/include/c_api/")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
fn macos() {
println!("cargo:rustc-link-search=framework={}", "SpeechSDK/macos");
println!("cargo:rustc-link-lib=framework=MicrosoftCognitiveServicesSpeech");
let bindings = bindgen::Builder::default()
.header("c_api/wrapper.h")
.clang_arg("-ISpeechSDK/macos/MicrosoftCognitiveServicesSpeech.framework/Headers")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}