File tree Expand file tree Collapse file tree 7 files changed +41
-1
lines changed Expand file tree Collapse file tree 7 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -4995,6 +4995,7 @@ version = "0.0.0"
49954995dependencies = [
49964996 " addr2line" ,
49974997 " alloc" ,
4998+ " build_helper" ,
49984999 " cfg-if 0.1.10" ,
49995000 " compiler_builtins" ,
50005001 " core" ,
@@ -5662,6 +5663,7 @@ dependencies = [
56625663name = " unwind"
56635664version = " 0.0.0"
56645665dependencies = [
5666+ " build_helper" ,
56655667 " cc" ,
56665668 " cfg-if 0.1.10" ,
56675669 " compiler_builtins" ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::env;
22use std:: path:: { Path , PathBuf } ;
33use std:: process:: Command ;
44
5- use build_helper:: { output, tracked_env_var_os} ;
5+ use build_helper:: { maybe_static_library , output, tracked_env_var_os} ;
66
77fn detect_llvm_link ( ) -> ( & ' static str , & ' static str ) {
88 // Force the link mode we want, preferring static by default, but
@@ -307,4 +307,6 @@ fn main() {
307307 if target. contains ( "windows-gnu" ) {
308308 println ! ( "cargo:rustc-link-lib=static:-bundle=pthread" ) ;
309309 }
310+
311+ maybe_static_library ( "RUSTC_STATIC_CLANG_RT_PATH" , "clang_rt" ) ;
310312}
Original file line number Diff line number Diff line change @@ -84,3 +84,6 @@ heap_size = 0x8000000
8484name = " stdbenches"
8585path = " benches/lib.rs"
8686test = true
87+
88+ [build-dependencies ]
89+ build_helper = { path = " ../../src/build_helper" }
Original file line number Diff line number Diff line change 11use std:: env;
22
3+ use build_helper:: maybe_static_library;
4+
35fn main ( ) {
46 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
57 let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
@@ -47,4 +49,6 @@ fn main() {
4749 }
4850 println ! ( "cargo:rustc-env=STD_ENV_ARCH={}" , env:: var( "CARGO_CFG_TARGET_ARCH" ) . unwrap( ) ) ;
4951 println ! ( "cargo:rustc-cfg=backtrace_in_libstd" ) ;
52+
53+ maybe_static_library ( "RUSTC_STATIC_CLANG_RT_PATH" , "clang_rt" ) ;
5054}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ compiler_builtins = "0.1.0"
2020cfg-if = " 0.1.8"
2121
2222[build-dependencies ]
23+ build_helper = { path = " ../../src/build_helper" }
2324cc = " 1.0.69"
2425
2526[features ]
Original file line number Diff line number Diff line change 11use std:: env;
22
3+ use build_helper:: maybe_static_library;
4+
35fn main ( ) {
46 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
57 let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
68
9+ if maybe_static_library ( "RUSTC_STATIC_UNWIND_PATH" , "unwind" ) {
10+ return ;
11+ }
12+
713 if target. contains ( "android" ) {
814 let build = cc:: Build :: new ( ) ;
915
Original file line number Diff line number Diff line change @@ -203,3 +203,25 @@ fn fail(s: &str) -> ! {
203203 println ! ( "\n \n {}\n \n " , s) ;
204204 std:: process:: exit ( 1 ) ;
205205}
206+
207+ /// if you need for some reason to statically inject some library, like clang_rt
208+ /// here a good place. Anyway, you should use only thin .a file on macOS.
209+ /// You may extract it like:
210+ /// lipo -thin x86_64 -output libclang_rt.a /path/to/llvm/lib/../libclang_rt.osx.a
211+ ///
212+ /// It returns true, when it had injected static library.
213+ pub fn maybe_static_library ( env_path_name : & str , library_name : & str ) -> bool {
214+ println ! ( "cargo:rerun-if-env-changed={}" , env_path_name) ;
215+
216+ if let Ok ( path) = env:: var ( env_path_name) {
217+ let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
218+ println ! ( "cargo:rerun-if-env-changed=TARGET" ) ;
219+
220+ println ! ( "cargo:rustc-link-search=native={}" , path) ;
221+ println ! ( "cargo:rustc-link-search=native={}/{}" , path, target) ;
222+ println ! ( "cargo:rustc-link-lib=static={}" , library_name) ;
223+ return true ;
224+ }
225+
226+ return false ;
227+ }
You can’t perform that action at this time.
0 commit comments