add more automation to build script
This commit is contained in:
parent
6df5ed5ab6
commit
cc2822e7e5
2 changed files with 35 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ description = "Rust bindings for whisper.cpp (FFI bindings)"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
documentation = "https://docs.rs/whisper-rs-sys"
|
documentation = "https://docs.rs/whisper-rs-sys"
|
||||||
repository = "https://github.com/tazz4843/whisper-rs"
|
repository = "https://github.com/tazz4843/whisper-rs"
|
||||||
|
links = "whisper"
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
|
|
|
||||||
36
sys/build.rs
36
sys/build.rs
|
|
@ -12,11 +12,39 @@ fn main() {
|
||||||
.header("wrapper.h")
|
.header("wrapper.h")
|
||||||
.clang_arg("-I./whisper.cpp")
|
.clang_arg("-I./whisper.cpp")
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||||
.generate()
|
.generate();
|
||||||
.expect("Unable to generate bindings");
|
|
||||||
|
|
||||||
|
match bindings {
|
||||||
|
Ok(b) => {
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
bindings
|
b.write_to_file(out_path.join("bindings.rs"))
|
||||||
.write_to_file(out_path.join("bindings.rs"))
|
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("cargo:warning=Unable to generate bindings: {}", e);
|
||||||
|
println!("cargo:warning=Using bundled bindings.rs, which may be out of date");
|
||||||
|
// copy src/bindings.rs to OUT_DIR
|
||||||
|
std::fs::copy(
|
||||||
|
"src/bindings.rs",
|
||||||
|
env::var("OUT_DIR").unwrap() + "/bindings.rs",
|
||||||
|
)
|
||||||
|
.expect("Unable to copy bindings.rs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// build libwhisper.a
|
||||||
|
env::set_current_dir("whisper.cpp").expect("Unable to change directory");
|
||||||
|
let code = std::process::Command::new("make")
|
||||||
|
.arg("libwhisper.a")
|
||||||
|
.status()
|
||||||
|
.expect("Failed to build libwhisper.a");
|
||||||
|
if code.code() != Some(0) {
|
||||||
|
panic!("Failed to build libwhisper.a");
|
||||||
|
}
|
||||||
|
// move libwhisper.a to where Cargo expects it (OUT_DIR)
|
||||||
|
std::fs::copy(
|
||||||
|
"libwhisper.a",
|
||||||
|
format!("{}/libwhisper.a", env::var("OUT_DIR").unwrap()),
|
||||||
|
)
|
||||||
|
.expect("Failed to copy libwhisper.a");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue