forked from shadowmint/llama-cpp-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
53 lines (46 loc) · 1.67 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::env;
use std::path::PathBuf;
use cmake::Config;
#[cfg(target_os = "macos")]
fn make_config() -> Config {
let mut cfg = Config::new("external/llama.cpp");
cfg.build_target("preinstall")
.define("BUILD_SHARED_LIBS", "true")
.define("LLAMA_METAL", "ON")
.define("LLAMA_BUILD_EXAMPLES", "OFF")
.define("LLAMA_BUILD_TESTS", "OFF")
.define("LLAMA_BUILD_TESTS", "OFF");
cfg
}
#[cfg(not(target_os = "macos"))]
fn make_config() -> Config {
let mut cfg = Config::new("external/llama.cpp");
cfg.build_target("preinstall")
.define("BUILD_SHARED_LIBS", "true")
.define("LLAMA_BUILD_EXAMPLES", "OFF")
.define("LLAMA_BUILD_TESTS", "OFF");
cfg
}
fn main() {
let mut config = make_config();
let dst = config
.very_verbose(true)
.build();
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=dylib=llama");
println!("cargo:rerun-if-changed=external/llama.cpp/llama.h");
println!("cargo:rerun-if-changed=external/llama.cpp/common/common.h");
println!("cargo:rerun-if-changed=external/llama.cpp/common/sampling.h");
let bindings = bindgen::Builder::default()
.clang_arg("-Iexternal/llama.cpp")
.header("external/llama.cpp/llama.h")
.allowlist_function("llama_.*")
.allowlist_type("llama_.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.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!");
}