optim: use build config instead of copying metal file to target folder

This commit is contained in:
hlhr202 2024-05-29 10:42:25 +08:00
parent 3f27c17fdf
commit 8872109d04
4 changed files with 4 additions and 17 deletions

View file

@ -85,7 +85,7 @@ pub unsafe fn set_log_callback(
whisper_rs_sys::whisper_log_set(log_callback, user_data); whisper_rs_sys::whisper_log_set(log_callback, user_data);
#[cfg(feature = "metal")] #[cfg(feature = "metal")]
{ {
whisper_rs_sys::ggml_metal_log_set_callback(log_callback, user_data); whisper_rs_sys::ggml_backend_metal_log_set_callback(log_callback, user_data);
} }
} }
} }

View file

@ -40,7 +40,7 @@ pub fn install_whisper_log_trampoline() {
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_log_trampoline), std::ptr::null_mut()); whisper_rs_sys::whisper_log_set(Some(whisper_cpp_log_trampoline), std::ptr::null_mut());
#[cfg(feature = "metal")] #[cfg(feature = "metal")]
{ {
whisper_rs_sys::ggml_metal_log_set_callback( whisper_rs_sys::ggml_backend_metal_log_set_callback(
Some(whisper_cpp_log_trampoline), Some(whisper_cpp_log_trampoline),
std::ptr::null_mut(), std::ptr::null_mut(),
); );

View file

@ -40,7 +40,7 @@ pub fn install_whisper_tracing_trampoline() {
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_tracing_trampoline), std::ptr::null_mut()); whisper_rs_sys::whisper_log_set(Some(whisper_cpp_tracing_trampoline), std::ptr::null_mut());
#[cfg(feature = "metal")] #[cfg(feature = "metal")]
{ {
whisper_rs_sys::ggml_metal_log_set_callback( whisper_rs_sys::ggml_backend_metal_log_set_callback(
Some(whisper_cpp_tracing_trampoline), Some(whisper_cpp_tracing_trampoline),
std::ptr::null_mut(), std::ptr::null_mut(),
); );

View file

@ -141,6 +141,7 @@ fn main() {
if cfg!(feature = "metal") { if cfg!(feature = "metal") {
config.define("WHISPER_METAL", "ON"); config.define("WHISPER_METAL", "ON");
config.define("WHISPER_METAL_NDEBUG", "ON"); config.define("WHISPER_METAL_NDEBUG", "ON");
config.define("WHISPER_METAL_EMBED_LIBRARY", "ON");
} else { } else {
// Metal is enabled by default, so we need to explicitly disable it // Metal is enabled by default, so we need to explicitly disable it
config.define("WHISPER_METAL", "OFF"); config.define("WHISPER_METAL", "OFF");
@ -174,20 +175,6 @@ fn main() {
// for whatever reason this file is generated during build and triggers cargo complaining // for whatever reason this file is generated during build and triggers cargo complaining
_ = std::fs::remove_file("bindings/javascript/package.json"); _ = std::fs::remove_file("bindings/javascript/package.json");
if cfg!(feature = "metal") {
// copy metal shader to the root of the crate
let _ = std::fs::copy(
out.join("whisper.cpp").join("ggml-metal.metal"),
out.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.join("ggml-metal.metal"),
);
}
} }
// From https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2462 // From https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2462