]> git.lizzy.rs Git - rust.git/blob - src/librustc_driver/target_features.rs
Auto merge of #43651 - petrochenkov:foreign-life, r=eddyb
[rust.git] / src / librustc_driver / target_features.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use syntax::ast;
12 use rustc::session::Session;
13 use syntax::symbol::Symbol;
14 use rustc_trans;
15
16 /// Add `target_feature = "..."` cfgs for a variety of platform
17 /// specific features (SSE, NEON etc.).
18 ///
19 /// This is performed by checking whether a whitelisted set of
20 /// features is available on the target machine, by querying LLVM.
21 pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
22     let tf = Symbol::intern("target_feature");
23
24     for feat in rustc_trans::target_features(sess) {
25         cfg.insert((tf, Some(feat)));
26     }
27
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 {
43         cfg.insert((tf, Some(Symbol::intern("crt-static"))));
44     }
45 }