Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cfg predicate for target_feature = "crt-static" only if the target supports it #71775

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn add_configuration(

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

if sess.crt_static_feature(None) {
if sess.crt_static(None) {
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/librustc_session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,11 @@ impl Session {

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

/// Check whether this compile session and crate type use `crt-static` feature.
pub fn crt_static_feature(&self, crate_type: Option<CrateType>) -> bool {
let requested_features = self.opts.cg.target_feature.split(',');
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
let found_positive = requested_features.clone().any(|r| r == "+crt-static");
Expand Down
7 changes: 2 additions & 5 deletions src/test/ui/crt-static-on-works.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// run-pass

#![allow(stable_features)]
// compile-flags:-C target-feature=+crt-static -Z unstable-options

#![feature(cfg_target_feature)]
// compile-flags:-C target-feature=+crt-static
// only-msvc

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