2024-07-01 07:53:23 -06:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-06-30 15:37:20 -06:00
|
|
|
use cxx_build::CFG;
|
|
|
|
|
2024-07-01 07:53:23 -06:00
|
|
|
const ADDITIONAL_BACKEND_LINK_LIBRARIES: [&str; 2] = ["spdlog", "fmt"];
|
|
|
|
|
2024-06-30 15:37:20 -06:00
|
|
|
fn main() {
|
2024-07-01 07:53:23 -06:00
|
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
let build_profile = env::var("PROFILE").unwrap();
|
|
|
|
|
|
|
|
// Build the backend implementation through CMake
|
2024-06-30 15:37:20 -06:00
|
|
|
let backend_path = cmake::Config::new(".")
|
|
|
|
.uses_cxx11()
|
|
|
|
.generator("Ninja")
|
2024-07-01 07:53:23 -06:00
|
|
|
.profile(match build_profile.as_ref() {
|
|
|
|
"release" => "Release",
|
|
|
|
_ => "Debug",
|
|
|
|
})
|
2024-06-30 15:37:20 -06:00
|
|
|
.build_target("tgi_trtllm_backend_impl")
|
|
|
|
.build();
|
|
|
|
|
2024-07-01 07:53:23 -06:00
|
|
|
// Build the FFI layer calling the backend above
|
2024-06-30 15:37:20 -06:00
|
|
|
CFG.include_prefix = "backends/trtllm";
|
|
|
|
cxx_build::bridge("src/lib.rs")
|
2024-07-01 07:53:23 -06:00
|
|
|
.static_flag(true)
|
2024-06-30 15:37:20 -06:00
|
|
|
.file("src/ffi.cpp")
|
|
|
|
.std("c++20")
|
|
|
|
.compile("tgi_trtllm_backend");
|
|
|
|
|
2024-07-01 07:53:23 -06:00
|
|
|
println!("cargo:rerun-if-changed=CMakeLists.txt");
|
2024-06-30 15:37:20 -06:00
|
|
|
println!("cargo:rerun-if-changed=include/backend.h");
|
|
|
|
println!("cargo:rerun-if-changed=lib/backend.cpp");
|
2024-07-01 07:53:23 -06:00
|
|
|
println!("cargo:rerun-if-changed=src/ffi.cpp");
|
|
|
|
|
|
|
|
// Additional transitive CMake dependencies
|
|
|
|
for dependency in ADDITIONAL_BACKEND_LINK_LIBRARIES {
|
|
|
|
let dep_folder = out_dir
|
|
|
|
.join("build")
|
|
|
|
.join("_deps")
|
|
|
|
.join(format!("{}-build", dependency));
|
|
|
|
|
|
|
|
let dep_name = match build_profile.as_ref() {
|
|
|
|
"debug" => format!("{}d", dependency),
|
|
|
|
_ => String::from(dependency),
|
|
|
|
};
|
|
|
|
println!("cargo:warning={}", dep_folder.display());
|
|
|
|
println!("cargo:rustc-link-search=native={}", dep_folder.display());
|
|
|
|
println!("cargo:rustc-link-lib=static={}", dep_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit linkage information
|
|
|
|
// - tgi_trtllm_backend (i.e. FFI layer - src/ffi.cpp)
|
|
|
|
println!(r"cargo:rustc-link-search=native={}", backend_path.display());
|
|
|
|
println!("cargo:rustc-link-lib=static=tgi_trtllm_backend");
|
|
|
|
|
|
|
|
// - tgi_trtllm_backend_impl (i.e. C++ code base to run inference include/backend.h)
|
|
|
|
println!(
|
|
|
|
r"cargo:rustc-link-search=native={}/build",
|
|
|
|
backend_path.display()
|
|
|
|
);
|
|
|
|
println!("cargo:rustc-link-lib=static=tgi_trtllm_backend_impl");
|
2024-06-30 15:37:20 -06:00
|
|
|
}
|