File tree 7 files changed +41
-1
lines changed
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"
4995
4995
dependencies = [
4996
4996
" addr2line" ,
4997
4997
" alloc" ,
4998
+ " build_helper" ,
4998
4999
" cfg-if 0.1.10" ,
4999
5000
" compiler_builtins" ,
5000
5001
" core" ,
@@ -5662,6 +5663,7 @@ dependencies = [
5662
5663
name = " unwind"
5663
5664
version = " 0.0.0"
5664
5665
dependencies = [
5666
+ " build_helper" ,
5665
5667
" cc" ,
5666
5668
" cfg-if 0.1.10" ,
5667
5669
" compiler_builtins" ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::env;
2
2
use std:: path:: { Path , PathBuf } ;
3
3
use std:: process:: Command ;
4
4
5
- use build_helper:: { output, tracked_env_var_os} ;
5
+ use build_helper:: { maybe_static_library , output, tracked_env_var_os} ;
6
6
7
7
fn detect_llvm_link ( ) -> ( & ' static str , & ' static str ) {
8
8
// Force the link mode we want, preferring static by default, but
@@ -307,4 +307,6 @@ fn main() {
307
307
if target. contains ( "windows-gnu" ) {
308
308
println ! ( "cargo:rustc-link-lib=static:-bundle=pthread" ) ;
309
309
}
310
+
311
+ maybe_static_library ( "RUSTC_STATIC_CLANG_RT_PATH" , "clang_rt" ) ;
310
312
}
Original file line number Diff line number Diff line change @@ -84,3 +84,6 @@ heap_size = 0x8000000
84
84
name = " stdbenches"
85
85
path = " benches/lib.rs"
86
86
test = true
87
+
88
+ [build-dependencies ]
89
+ build_helper = { path = " ../../src/build_helper" }
Original file line number Diff line number Diff line change 1
1
use std:: env;
2
2
3
+ use build_helper:: maybe_static_library;
4
+
3
5
fn main ( ) {
4
6
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5
7
let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
@@ -47,4 +49,6 @@ fn main() {
47
49
}
48
50
println ! ( "cargo:rustc-env=STD_ENV_ARCH={}" , env:: var( "CARGO_CFG_TARGET_ARCH" ) . unwrap( ) ) ;
49
51
println ! ( "cargo:rustc-cfg=backtrace_in_libstd" ) ;
52
+
53
+ maybe_static_library ( "RUSTC_STATIC_CLANG_RT_PATH" , "clang_rt" ) ;
50
54
}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ compiler_builtins = "0.1.0"
20
20
cfg-if = " 0.1.8"
21
21
22
22
[build-dependencies ]
23
+ build_helper = { path = " ../../src/build_helper" }
23
24
cc = " 1.0.69"
24
25
25
26
[features ]
Original file line number Diff line number Diff line change 1
1
use std:: env;
2
2
3
+ use build_helper:: maybe_static_library;
4
+
3
5
fn main ( ) {
4
6
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5
7
let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
6
8
9
+ if maybe_static_library ( "RUSTC_STATIC_UNWIND_PATH" , "unwind" ) {
10
+ return ;
11
+ }
12
+
7
13
if target. contains ( "android" ) {
8
14
let build = cc:: Build :: new ( ) ;
9
15
Original file line number Diff line number Diff line change @@ -203,3 +203,25 @@ fn fail(s: &str) -> ! {
203
203
println ! ( "\n \n {}\n \n " , s) ;
204
204
std:: process:: exit ( 1 ) ;
205
205
}
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