]>
Commit | Line | Data |
---|---|---|
e9174d1e SL |
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 | ||
476ff2be | 11 | use syntax::ast; |
e9174d1e | 12 | use rustc::session::Session; |
476ff2be | 13 | use syntax::symbol::Symbol; |
7cac9316 | 14 | use rustc_trans; |
e9174d1e SL |
15 | |
16 | /// Add `target_feature = "..."` cfgs for a variety of platform | |
17 | /// specific features (SSE, NEON etc.). | |
18 | /// | |
a7813a04 XL |
19 | /// This is performed by checking whether a whitelisted set of |
20 | /// features is available on the target machine, by querying LLVM. | |
e9174d1e | 21 | pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) { |
476ff2be | 22 | let tf = Symbol::intern("target_feature"); |
7cac9316 XL |
23 | |
24 | for feat in rustc_trans::target_features(sess) { | |
25 | cfg.insert((tf, Some(feat))); | |
a7813a04 | 26 | } |
476ff2be SL |
27 | |
28 | let requested_features = sess.opts.cg.target_feature.split(','); | |
476ff2be SL |
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 | ||
476ff2be SL |
42 | if crt_static { |
43 | cfg.insert((tf, Some(Symbol::intern("crt-static")))); | |
44 | } | |
e9174d1e | 45 | } |