From 95db062bc811cba2b72bada2de6622c6f61cc19e Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 4 Jun 2024 16:32:45 +0800 Subject: [PATCH] chore: update build.rs --- build.rs | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/build.rs b/build.rs index d961c6d..ef8e487 100644 --- a/build.rs +++ b/build.rs @@ -28,55 +28,38 @@ static ET_LIBS: [&str; 16] = [ ]; fn main() { - // find available lib / object files in the executorch cmake-out - // all libs should whole-archive link - // libs: - // extension_data_loader - // mpsdelegate - // qnn_executorch_backend : shared - // portable_ops_lib - // extension_module : shared - // xnnpack_backend - // XNNPACK - // cpuinfo - // pthreadpool - // vulkan_backend - // optimized_kernels - // optimized_ops_lib - // optimized_native_cpu_ops_lib - // quantized_kernels - // quantized_ops_lib - // custom_ops - // - - // from env EXECUTORCH_INSTALL_PREFIX default "executorch/cmake-out/lib" let base_path_str = std::env::var("EXECUTORCH_INSTALL_PREFIX").unwrap_or_else(|_| "executorch/cmake-out".to_string()); - let base_path = Path::new(&base_path_str).join("lib"); + let lib_path = Path::new(&base_path_str).join("lib"); - // find path in executorch/cmake-out/lib/*.{so,dylib,dll,a} - let mut lib_paths: Vec<&str> = Vec::new(); + let mut lib_paths: Vec = Vec::new(); for lib in ET_LIBS { - let path = match lib { + let filename = match lib { "extension_module" => format!("lib{}.{}", lib, SO_EXT), "qnn_executorch_backend" => format!("lib{}.{}", lib, SO_EXT), _ => format!("lib{}.a", lib), }; - if base_path.join(&path).exists() { - lib_paths.push(lib.trim_start_matches("lib")); + if lib_path.join(&filename).exists() { + lib_paths.push(filename); } } assert!(!lib_paths.is_empty(), "No lib files found in executorch/cmake-out/lib"); let mut config = cpp_build::Config::new(); - config.flag_if_supported("-std=c++17"); + config.flag("-std=c++17"); for lib in lib_paths { - // POSIX systems - config.flag_if_supported(&format!("--whole-archive -l{} --no-whole-archive", lib)); - // Darwin systems - config.flag_if_supported(&format!("-force_load,{}", lib)); + config.flag(&format!("-Wl,--whole-archive -l{} -Wl,--no-whole-archive", lib.trim_start_matches("lib").trim_end_matches(".a"))); + // if lib.ends_with(SO_EXT) { + // // println!("cargo:rustc-link-lib=dylib={}", lib.trim_start_matches("lib").trim_end_matches(SO_EXT)); + // } else { + // config.flag(&format!("--whole-archive -l{} --no-whole-archive", lib)); + // // println!("cargo:rustc-link-lib=static={}", lib.trim_start_matches("lib").trim_end_matches(".a")); + // } } + // println!("cargo:rustc-link-search=native={}", lib_path.display()); + config.flag(&format!("-L{}", lib_path.display())); + config.build("src/lib.rs"); }