Skip to content

Commit 33b6631

Browse files
committed
Enable cfg predicate for target_feature = "crt-static" only if the target supports it
1 parent 0a675c5 commit 33b6631

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn add_configuration(
4949

5050
cfg.extend(codegen_backend.target_features(sess).into_iter().map(|feat| (tf, Some(feat))));
5151

52-
if sess.crt_static_feature(None) {
52+
if sess.crt_static(None) {
5353
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
5454
}
5555
}

src/librustc_session/session.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,11 @@ impl Session {
553553

554554
/// Check whether this compile session and crate type use static crt.
555555
pub fn crt_static(&self, crate_type: Option<CrateType>) -> bool {
556-
// If the target does not opt in to crt-static support, use its default.
557-
if self.target.target.options.crt_static_respected {
558-
self.crt_static_feature(crate_type)
559-
} else {
560-
self.target.target.options.crt_static_default
556+
if !self.target.target.options.crt_static_respected {
557+
// If the target does not opt in to crt-static support, use its default.
558+
return self.target.target.options.crt_static_default;
561559
}
562-
}
563560

564-
/// Check whether this compile session and crate type use `crt-static` feature.
565-
pub fn crt_static_feature(&self, crate_type: Option<CrateType>) -> bool {
566561
let requested_features = self.opts.cg.target_feature.split(',');
567562
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
568563
let found_positive = requested_features.clone().any(|r| r == "+crt-static");

src/test/ui/crt-static-on-works.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// run-pass
2-
3-
#![allow(stable_features)]
4-
// compile-flags:-C target-feature=+crt-static -Z unstable-options
5-
6-
#![feature(cfg_target_feature)]
2+
// compile-flags:-C target-feature=+crt-static
3+
// only-msvc
74

85
#[cfg(target_feature = "crt-static")]
96
fn main() {}

0 commit comments

Comments
 (0)