@@ -31,15 +31,7 @@ enum Os {
3131 Unknown ,
3232}
3333
34- fn main ( ) {
35- println ! ( "cargo:rerun-if-changed=build.rs" ) ;
36- println ! ( "cargo:rerun-if-changed=src/sys" ) ;
37- println ! ( "cargo:rerun-if-changed=include" ) ;
38- println ! ( "cargo:rerun-if-changed=CTranslate2" ) ;
39- add_search_paths ( "LIBRARY_PATH" ) ;
40- println ! ( "cargo:rerun-if-env-changed=CMAKE_INCLUDE_PATH" ) ;
41- add_search_paths ( "CMAKE_LIBRARY_PATH" ) ;
42-
34+ fn build_ctranslate2 ( ) {
4335 let mut cmake = Config :: new ( "CTranslate2" ) ;
4436 match env:: var ( "CMAKE_PARALLEL" ) {
4537 Ok ( job_n) => {
@@ -198,6 +190,57 @@ fn main() {
198190
199191 let ctranslate2 = cmake. build ( ) ;
200192 link_libraries ( ctranslate2. join ( "build" ) ) ;
193+ }
194+
195+ fn link_system_libraries ( ) {
196+ println ! ( "cargo:rustc-link-lib=ctranslate2" ) ;
197+ if cfg ! ( target_arch = "x86_64" ) {
198+ println ! ( "cargo:rustc-link-lib=cpu_features" ) ;
199+ }
200+ if cfg ! ( feature = "cuda" ) {
201+ println ! ( "cargo:rustc-link-lib=static=cudart_static" ) ;
202+ }
203+ if cfg ! ( feature = "cudnn" ) {
204+ println ! ( "cargo:rustc-link-lib=cudnn" ) ;
205+ }
206+ if !cfg ! ( feature = "cuda-dynamic-loading" ) {
207+ if cfg ! ( target_os = "windows" ) {
208+ println ! ( "cargo:rustc-link-lib=static=cublas" ) ;
209+ println ! ( "cargo:rustc-link-lib=static=cublasLt" ) ;
210+ } else {
211+ println ! ( "cargo:rustc-link-lib=static=cublas_static" ) ;
212+ println ! ( "cargo:rustc-link-lib=static=cublasLt_static" ) ;
213+ println ! ( "cargo:rustc-link-lib=static=culibos" ) ;
214+ }
215+ }
216+ if cfg ! ( feature = "accelerate" ) {
217+ println ! ( "cargo:rustc-link-lib=framework=Accelerate" ) ;
218+ }
219+ if cfg ! ( feature = "dnnl" ) {
220+ println ! ( "cargo:rustc-link-lib=dnnl" ) ;
221+ }
222+ if cfg ! ( feature = "openmp-runtime-comp" ) {
223+ println ! ( "cargo:rustc-link-lib=gomp" ) ;
224+ }
225+ if cfg ! ( feature = "openmp-runtime-intel" ) {
226+ println ! ( "cargo:rustc-link-lib=iomp5" ) ;
227+ }
228+ }
229+
230+ fn main ( ) {
231+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
232+ println ! ( "cargo:rerun-if-changed=src/sys" ) ;
233+ println ! ( "cargo:rerun-if-changed=include" ) ;
234+ println ! ( "cargo:rerun-if-changed=CTranslate2" ) ;
235+ add_search_paths ( "LIBRARY_PATH" ) ;
236+ println ! ( "cargo:rerun-if-env-changed=CMAKE_INCLUDE_PATH" ) ;
237+ add_search_paths ( "CMAKE_LIBRARY_PATH" ) ;
238+
239+ if cfg ! ( feature = "system" ) {
240+ link_system_libraries ( ) ;
241+ } else {
242+ build_ctranslate2 ( )
243+ }
201244
202245 cxx_build:: bridges ( [
203246 "src/sys/types.rs" ,
0 commit comments