Skip to content

Commit 3cb9878

Browse files
committed
Factor out a helper for the getting C runtime linkage
This commit makes no functional changes.
1 parent 5283243 commit 3cb9878

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/librustc/session/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,22 @@ impl Session {
429429
.unwrap_or(self.opts.debug_assertions)
430430
}
431431

432+
pub fn crt_static(&self) -> bool {
433+
let requested_features = self.opts.cg.target_feature.split(',');
434+
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
435+
let found_positive = requested_features.clone().any(|r| r == "+crt-static");
436+
437+
// If the target we're compiling for requests a static crt by default,
438+
// then see if the `-crt-static` feature was passed to disable that.
439+
// Otherwise if we don't have a static crt by default then see if the
440+
// `+crt-static` feature was passed.
441+
if self.target.target.options.crt_static_default {
442+
!found_negative
443+
} else {
444+
found_positive
445+
}
446+
}
447+
432448
pub fn must_not_eliminate_frame_pointers(&self) -> bool {
433449
self.opts.debuginfo != DebugInfoLevel::NoDebugInfo ||
434450
!self.target.target.options.eliminate_frame_pointer

src/librustc_driver/target_features.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
2525
cfg.insert((tf, Some(feat)));
2626
}
2727

28-
let requested_features = sess.opts.cg.target_feature.split(',');
29-
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
30-
let found_positive = requested_features.clone().any(|r| r == "+crt-static");
31-
32-
// If the target we're compiling for requests a static crt by default,
33-
// then see if the `-crt-static` feature was passed to disable that.
34-
// Otherwise if we don't have a static crt by default then see if the
35-
// `+crt-static` feature was passed.
36-
let crt_static = if sess.target.target.options.crt_static_default {
37-
!found_negative
38-
} else {
39-
found_positive
40-
};
41-
42-
if crt_static {
28+
if sess.crt_static() {
4329
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
4430
}
4531
}

0 commit comments

Comments
 (0)