Add coreml feature flag and build.rs updates
This commit is contained in:
parent
93ac3fdb73
commit
77cdbd6187
3 changed files with 34 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ hound = "3.5.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
simd = []
|
simd = []
|
||||||
|
coreml = ["whisper-rs-sys/coreml"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["simd"]
|
features = ["simd"]
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ include = [
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[features]
|
||||||
|
coreml = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
||||||
30
sys/build.rs
30
sys/build.rs
|
|
@ -14,10 +14,17 @@ fn main() {
|
||||||
// Link macOS Accelerate framework for matrix calculations
|
// Link macOS Accelerate framework for matrix calculations
|
||||||
if target.contains("apple") {
|
if target.contains("apple") {
|
||||||
println!("cargo:rustc-link-lib=framework=Accelerate");
|
println!("cargo:rustc-link-lib=framework=Accelerate");
|
||||||
|
#[cfg(feature = "coreml")]
|
||||||
|
{
|
||||||
|
println!("cargo:rustc-link-lib=framework=Foundation");
|
||||||
|
println!("cargo:rustc-link-lib=framework=CoreML");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("cargo:rustc-link-search={}", env::var("OUT_DIR").unwrap());
|
println!("cargo:rustc-link-search={}", env::var("OUT_DIR").unwrap());
|
||||||
println!("cargo:rustc-link-lib=static=whisper");
|
println!("cargo:rustc-link-lib=static=whisper");
|
||||||
|
#[cfg(feature = "coreml")]
|
||||||
|
println!("cargo:rustc-link-lib=static=whisper.coreml");
|
||||||
println!("cargo:rerun-if-changed=wrapper.h");
|
println!("cargo:rerun-if-changed=wrapper.h");
|
||||||
|
|
||||||
if env::var("WHISPER_DONT_GENERATE_BINDINGS").is_ok() {
|
if env::var("WHISPER_DONT_GENERATE_BINDINGS").is_ok() {
|
||||||
|
|
@ -63,6 +70,20 @@ fn main() {
|
||||||
_ = std::fs::create_dir("build");
|
_ = std::fs::create_dir("build");
|
||||||
env::set_current_dir("build").expect("Unable to change directory to whisper.cpp build");
|
env::set_current_dir("build").expect("Unable to change directory to whisper.cpp build");
|
||||||
|
|
||||||
|
#[cfg(feature = "coreml")]
|
||||||
|
let code = std::process::Command::new("cmake")
|
||||||
|
.arg("..")
|
||||||
|
.arg("-DCMAKE_BUILD_TYPE=Release")
|
||||||
|
.arg("-DBUILD_SHARED_LIBS=OFF")
|
||||||
|
.arg("-DWHISPER_ALL_WARNINGS=OFF")
|
||||||
|
.arg("-DWHISPER_ALL_WARNINGS_3RD_PARTY=OFF")
|
||||||
|
.arg("-DWHISPER_BUILD_TESTS=OFF")
|
||||||
|
.arg("-DWHISPER_BUILD_EXAMPLES=OFF")
|
||||||
|
.arg("-DWHISPER_COREML=1")
|
||||||
|
.status()
|
||||||
|
.expect("Failed to generate build script");
|
||||||
|
|
||||||
|
#[cfg(not(feature = "coreml"))]
|
||||||
let code = std::process::Command::new("cmake")
|
let code = std::process::Command::new("cmake")
|
||||||
.arg("..")
|
.arg("..")
|
||||||
.arg("-DCMAKE_BUILD_TYPE=Release")
|
.arg("-DCMAKE_BUILD_TYPE=Release")
|
||||||
|
|
@ -106,6 +127,15 @@ fn main() {
|
||||||
)
|
)
|
||||||
.expect("Failed to copy libwhisper.a");
|
.expect("Failed to copy libwhisper.a");
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "coreml")]
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
std::fs::copy(
|
||||||
|
"libwhisper.coreml.a",
|
||||||
|
format!("{}/libwhisper.coreml.a", env::var("OUT_DIR").unwrap()),
|
||||||
|
)
|
||||||
|
.expect("Failed to copy libwhisper.coreml.a");
|
||||||
|
}
|
||||||
|
|
||||||
// clean the whisper build directory to prevent Cargo from complaining during crate publish
|
// clean the whisper build directory to prevent Cargo from complaining during crate publish
|
||||||
env::set_current_dir("..").expect("Unable to change directory to whisper.cpp");
|
env::set_current_dir("..").expect("Unable to change directory to whisper.cpp");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue