Skip to content

Commit 5013952

Browse files
committed
rustc: Stabilize -C target-feature=+crt-static
This commit stabilizes the `crt-static` feature accepted by the compiler. Note that this does not stabilize the `#[cfg]` attribute for `crt-static` as that's going to be covered by #29717. This only stabilizes a few small pieces: * The `crt-static` feature as accepted by the `-C target-feature` flag, and its connection with the platform-specific definition of `crt-static`. * The semantics of `--print cfg` printing out activated `crt-static` feature, if available. This should be enough to get the benefits of `crt-static` on stable Rust with MSVC and with musl, but sidsteps the issue of stabilizing #29717 first. Closes #37406
1 parent 222971f commit 5013952

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

src/librustc_driver/lib.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,24 @@ impl RustcDefaultCalls {
635635
node: ast::MetaItemKind::Word,
636636
span: DUMMY_SP,
637637
});
638-
if !allow_unstable_cfg && gated_cfg.is_some() {
639-
continue;
638+
639+
// Note that crt-static is a specially recognized cfg
640+
// directive that's printed out here as part of
641+
// rust-lang/rust#37406, but in general the
642+
// `target_feature` cfg is gated under
643+
// rust-lang/rust#29717. For now this is just
644+
// specifically allowing the crt-static cfg and that's
645+
// it, this is intended to get into Cargo and then go
646+
// through to build scripts.
647+
let value = value.as_ref().map(|s| s.as_str());
648+
let value = value.as_ref().map(|s| s.as_ref());
649+
if name != "target_feature" || value != Some("crt-static") {
650+
if !allow_unstable_cfg && gated_cfg.is_some() {
651+
continue;
652+
}
640653
}
641654

642-
cfgs.push(if let &Some(ref value) = value {
655+
cfgs.push(if let Some(value) = value {
643656
format!("{}=\"{}\"", name, value)
644657
} else {
645658
format!("{}", name)

src/librustc_driver/target_features.rs

-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use syntax::ast;
1212
use llvm::LLVMRustHasFeature;
1313
use rustc::session::Session;
1414
use rustc_trans::back::write::create_target_machine;
15-
use syntax::feature_gate::UnstableFeatures;
1615
use syntax::symbol::Symbol;
1716
use libc::c_char;
1817

@@ -50,8 +49,6 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
5049
}
5150

5251
let requested_features = sess.opts.cg.target_feature.split(',');
53-
let unstable_options = sess.opts.debugging_opts.unstable_options;
54-
let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
5552
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
5653
let found_positive = requested_features.clone().any(|r| r == "+crt-static");
5754

@@ -65,14 +62,6 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
6562
found_positive
6663
};
6764

68-
// If we switched from the default then that's only allowed on nightly, so
69-
// gate that here.
70-
if (found_positive || found_negative) && (!is_nightly || !unstable_options) {
71-
sess.fatal("specifying the `crt-static` target feature is only allowed \
72-
on the nightly channel with `-Z unstable-options` passed \
73-
as well");
74-
}
75-
7665
if crt_static {
7766
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
7867
}

src/test/compile-fail/crt-static-gated.rs

-14
This file was deleted.

0 commit comments

Comments
 (0)