-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from SkyFan2002/master
Support static link as a feature
- Loading branch information
Showing
8 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target/ | ||
**/*.rs.bk | ||
Cargo.lock | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "faiss-sys/faiss"] | ||
path = faiss-sys/faiss | ||
url = https://github.com/Enet4/faiss.git | ||
branch = c_api_head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
fn main() { | ||
#[cfg(feature = "static")] | ||
static_link_faiss(); | ||
#[cfg(not(feature = "static"))] | ||
println!("cargo:rustc-link-lib=faiss_c"); | ||
} | ||
|
||
#[cfg(feature = "static")] | ||
fn static_link_faiss() { | ||
let mut cfg = cmake::Config::new("faiss"); | ||
cfg.define("FAISS_ENABLE_C_API", "ON") | ||
.define("BUILD_SHARED_LIBS", "OFF") | ||
.define("CMAKE_BUILD_TYPE", "Release") | ||
.define("FAISS_ENABLE_GPU", "OFF") | ||
.define("FAISS_ENABLE_PYTHON", "OFF") | ||
.define("BUILD_TESTING", "OFF") | ||
.very_verbose(true); | ||
let dst = cfg.build(); | ||
let faiss_location = dst.join("lib"); | ||
let faiss_c_location = dst.join("build/c_api"); | ||
println!( | ||
"cargo:rustc-link-search=native={}", | ||
faiss_location.display() | ||
); | ||
println!( | ||
"cargo:rustc-link-search=native={}", | ||
faiss_c_location.display() | ||
); | ||
println!("cargo:rustc-link-lib=static=faiss_c"); | ||
println!("cargo:rustc-link-lib=static=faiss"); | ||
link_cxx(); | ||
println!("cargo:rustc-link-lib=gomp"); | ||
println!("cargo:rustc-link-lib=blas"); | ||
println!("cargo:rustc-link-lib=lapack"); | ||
} | ||
|
||
#[cfg(feature = "static")] | ||
fn link_cxx() { | ||
let cxx = match std::env::var("CXXSTDLIB") { | ||
Ok(s) if s.is_empty() => None, | ||
Ok(s) => Some(s), | ||
Err(_) => { | ||
let target = std::env::var("TARGET").unwrap(); | ||
if target.contains("msvc") { | ||
None | ||
} else if target.contains("apple") | ||
| target.contains("freebsd") | ||
| target.contains("openbsd") | ||
{ | ||
Some("c++".to_string()) | ||
} else { | ||
Some("stdc++".to_string()) | ||
} | ||
} | ||
}; | ||
if let Some(cxx) = cxx { | ||
println!("cargo:rustc-link-lib={}", cxx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters