File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 292
292
# build native code.
293
293
#android-ndk = "/path/to/ndk"
294
294
295
+ # Force static or dynamic linkage of the standard library for this target. If
296
+ # this target is a host for rustc, this will also affect the linkage of the
297
+ # compiler itself. This is useful for building rustc on targets that normally
298
+ # only use static libraries. If unset, the target's default linkage is used.
299
+ #crt-static = false
300
+
295
301
# The root location of the MUSL installation directory. The library directory
296
302
# will also need to contain libunwind.a for an unwinding implementation. Note
297
303
# that this option only makes sense for MUSL targets that produce statically
Original file line number Diff line number Diff line change @@ -242,6 +242,15 @@ fn main() {
242
242
cmd. arg ( "-C" ) . arg ( "target-feature=+crt-static" ) ;
243
243
}
244
244
245
+ if let Ok ( s) = env:: var ( "RUSTC_CRT_STATIC" ) {
246
+ if s == "true" {
247
+ cmd. arg ( "-C" ) . arg ( "target-feature=+crt-static" ) ;
248
+ }
249
+ if s == "false" {
250
+ cmd. arg ( "-C" ) . arg ( "target-feature=-crt-static" ) ;
251
+ }
252
+ }
253
+
245
254
// Force all crates compiled by this compiler to (a) be unstable and (b)
246
255
// allow the `rustc_private` feature to link to other unstable crates
247
256
// also in the sysroot.
Original file line number Diff line number Diff line change @@ -503,6 +503,10 @@ impl<'a> Builder<'a> {
503
503
cargo. env ( "RUSTC_METADATA_SUFFIX" , "rustc" ) ;
504
504
}
505
505
506
+ if let Some ( x) = self . crt_static ( target) {
507
+ cargo. env ( "RUSTC_CRT_STATIC" , x. to_string ( ) ) ;
508
+ }
509
+
506
510
// Enable usage of unstable features
507
511
cargo. env ( "RUSTC_BOOTSTRAP" , "1" ) ;
508
512
self . add_rust_test_threads ( & mut cargo) ;
Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ pub struct Target {
143
143
pub cc : Option < PathBuf > ,
144
144
pub cxx : Option < PathBuf > ,
145
145
pub ndk : Option < PathBuf > ,
146
+ pub crt_static : Option < bool > ,
146
147
pub musl_root : Option < PathBuf > ,
147
148
pub qemu_rootfs : Option < PathBuf > ,
148
149
}
@@ -275,6 +276,7 @@ struct TomlTarget {
275
276
cc : Option < String > ,
276
277
cxx : Option < String > ,
277
278
android_ndk : Option < String > ,
279
+ crt_static : Option < bool > ,
278
280
musl_root : Option < String > ,
279
281
qemu_rootfs : Option < String > ,
280
282
}
@@ -446,6 +448,7 @@ impl Config {
446
448
}
447
449
target. cxx = cfg. cxx . clone ( ) . map ( PathBuf :: from) ;
448
450
target. cc = cfg. cc . clone ( ) . map ( PathBuf :: from) ;
451
+ target. crt_static = cfg. crt_static . clone ( ) ;
449
452
target. musl_root = cfg. musl_root . clone ( ) . map ( PathBuf :: from) ;
450
453
target. qemu_rootfs = cfg. qemu_rootfs . clone ( ) . map ( PathBuf :: from) ;
451
454
Original file line number Diff line number Diff line change @@ -656,6 +656,12 @@ impl Build {
656
656
base
657
657
}
658
658
659
+ /// Returns if this target should statically link the C runtime, if specified
660
+ fn crt_static ( & self , target : Interned < String > ) -> Option < bool > {
661
+ self . config . target_config . get ( & target)
662
+ . and_then ( |t| t. crt_static )
663
+ }
664
+
659
665
/// Returns the "musl root" for this `target`, if defined
660
666
fn musl_root ( & self , target : Interned < String > ) -> Option < & Path > {
661
667
self . config . target_config . get ( & target)
You can’t perform that action at this time.
0 commit comments