@@ -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,101 @@ 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 ! ( all(
207+ not( feature = "cuda-dynamic-loading" ) ,
208+ not( target_os = "macos" )
209+ ) ) {
210+ if cfg ! ( target_os = "windows" ) {
211+ println ! ( "cargo:rustc-link-lib=static=cublas" ) ;
212+ println ! ( "cargo:rustc-link-lib=static=cublasLt" ) ;
213+ } else {
214+ println ! ( "cargo:rustc-link-lib=static=cublas_static" ) ;
215+ println ! ( "cargo:rustc-link-lib=static=cublasLt_static" ) ;
216+ println ! ( "cargo:rustc-link-lib=static=culibos" ) ;
217+ }
218+ }
219+ if cfg ! ( feature = "accelerate" ) {
220+ println ! ( "cargo:rustc-link-lib=framework=Accelerate" ) ;
221+ }
222+ if cfg ! ( feature = "ruy" ) {
223+ println ! ( "cargo:rustc-link-lib=cpuinfo" ) ;
224+ println ! ( "cargo:rustc-link-lib=clog" ) ;
225+ println ! ( "cargo:rustc-link-lib=ruy_allocator" ) ;
226+ println ! ( "cargo:rustc-link-lib=ruy_apply_multiplier" ) ;
227+ println ! ( "cargo:rustc-link-lib=ruy_block_map" ) ;
228+ println ! ( "cargo:rustc-link-lib=ruy_blocking_counter" ) ;
229+ println ! ( "cargo:rustc-link-lib=ruy_context" ) ;
230+ println ! ( "cargo:rustc-link-lib=ruy_context_get_ctx" ) ;
231+ println ! ( "cargo:rustc-link-lib=ruy_cpuinfo" ) ;
232+ println ! ( "cargo:rustc-link-lib=ruy_ctx" ) ;
233+ println ! ( "cargo:rustc-link-lib=ruy_denormal" ) ;
234+ println ! ( "cargo:rustc-link-lib=ruy_frontend" ) ;
235+ println ! ( "cargo:rustc-link-lib=ruy_prepacked_cache" ) ;
236+ println ! ( "cargo:rustc-link-lib=ruy_prepare_packed_matrices" ) ;
237+ println ! ( "cargo:rustc-link-lib=ruy_profiler_instrumentation" ) ;
238+ println ! ( "cargo:rustc-link-lib=ruy_system_aligned_alloc" ) ;
239+ println ! ( "cargo:rustc-link-lib=ruy_thread_pool" ) ;
240+ println ! ( "cargo:rustc-link-lib=ruy_trmul" ) ;
241+ println ! ( "cargo:rustc-link-lib=ruy_tune" ) ;
242+ println ! ( "cargo:rustc-link-lib=ruy_wait" ) ;
243+ if cfg ! ( any( target_arch = "arm" , target_arch = "aarch64" ) ) {
244+ println ! ( "cargo:rustc-link-lib=ruy_kernel_arm" ) ;
245+ println ! ( "cargo:rustc-link-lib=ruy_pack_arm" ) ;
246+ }
247+ if cfg ! ( target_feature = "avx" ) {
248+ println ! ( "cargo:rustc-link-lib=ruy_have_built_path_for_avx" ) ;
249+ println ! ( "cargo:rustc-link-lib=ruy_kernel_avx" ) ;
250+ println ! ( "cargo:rustc-link-lib=ruy_pack_avx" ) ;
251+ }
252+ if cfg ! ( target_feature = "avx2" ) {
253+ println ! ( "cargo:rustc-link-lib=ruy_have_built_path_for_avx2_fma" ) ;
254+ println ! ( "cargo:rustc-link-lib=ruy_kernel_avx2_fma" ) ;
255+ println ! ( "cargo:rustc-link-lib=ruy_pack_avx2_fma" ) ;
256+ }
257+ if cfg ! ( target_feature = "avx512f" ) {
258+ println ! ( "cargo:rustc-link-lib=ruy_have_built_path_for_avx512" ) ;
259+ println ! ( "cargo:rustc-link-lib=ruy_kernel_avx512" ) ;
260+ println ! ( "cargo:rustc-link-lib=ruy_pack_avx512" ) ;
261+ }
262+ }
263+ if cfg ! ( feature = "dnnl" ) {
264+ println ! ( "cargo:rustc-link-lib=dnnl" ) ;
265+ }
266+ if cfg ! ( feature = "openmp-runtime-comp" ) {
267+ println ! ( "cargo:rustc-link-lib=gomp" ) ;
268+ }
269+ if cfg ! ( feature = "openmp-runtime-intel" ) {
270+ println ! ( "cargo:rustc-link-lib=iomp5" ) ;
271+ }
272+ }
273+
274+ fn main ( ) {
275+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
276+ println ! ( "cargo:rerun-if-changed=src/sys" ) ;
277+ println ! ( "cargo:rerun-if-changed=include" ) ;
278+ println ! ( "cargo:rerun-if-changed=CTranslate2" ) ;
279+ add_search_paths ( "LIBRARY_PATH" ) ;
280+ println ! ( "cargo:rerun-if-env-changed=CMAKE_INCLUDE_PATH" ) ;
281+ add_search_paths ( "CMAKE_LIBRARY_PATH" ) ;
282+
283+ if cfg ! ( feature = "system" ) {
284+ link_system_libraries ( ) ;
285+ } else {
286+ build_ctranslate2 ( )
287+ }
201288
202289 cxx_build:: bridges ( [
203290 "src/sys/types.rs" ,
0 commit comments