Skip to content

Commit 8d16eeb

Browse files
committed
Auto merge of #71775 - petrochenkov:crtcfg, r=matthewjasper
Enable `cfg` predicate for `target_feature = "crt-static"` only if the target supports it That's what all other `target_feature`s do.
2 parents b326953 + 33b6631 commit 8d16eeb

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
@@ -598,16 +598,11 @@ impl Session {
598598

599599
/// Check whether this compile session and crate type use static crt.
600600
pub fn crt_static(&self, crate_type: Option<CrateType>) -> bool {
601-
// If the target does not opt in to crt-static support, use its default.
602-
if self.target.target.options.crt_static_respected {
603-
self.crt_static_feature(crate_type)
604-
} else {
605-
self.target.target.options.crt_static_default
601+
if !self.target.target.options.crt_static_respected {
602+
// If the target does not opt in to crt-static support, use its default.
603+
return self.target.target.options.crt_static_default;
606604
}
607-
}
608605

609-
/// Check whether this compile session and crate type use `crt-static` feature.
610-
pub fn crt_static_feature(&self, crate_type: Option<CrateType>) -> bool {
611606
let requested_features = self.opts.cg.target_feature.split(',');
612607
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
613608
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)