Skip to content

Commit b48663d

Browse files
committed
[AVR][No Upstream] Expose the 'target_cpu' feature flag
1 parent 043550d commit b48663d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/librustc/session/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,7 @@ pub fn default_lib_output() -> CrateType {
14921492
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
14931493
let end = &sess.target.target.target_endian;
14941494
let arch = &sess.target.target.arch;
1495+
let cpu = &sess.target.target.options.cpu;
14951496
let wordsz = &sess.target.target.target_pointer_width;
14961497
let os = &sess.target.target.target_os;
14971498
let env = &sess.target.target.target_env;
@@ -1521,6 +1522,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
15211522
Symbol::intern("target_vendor"),
15221523
Some(Symbol::intern(vendor)),
15231524
));
1525+
if sess.target.target.options.is_specific_cpu() {
1526+
ret.insert((Symbol::intern("target_cpu"), Some(Symbol::intern(cpu))));
1527+
}
1528+
15241529
if sess.target.target.options.has_elf_tls {
15251530
ret.insert((sym::target_thread_local, None));
15261531
}

src/librustc_target/spec/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ impl Default for TargetOptions {
853853
}
854854
}
855855

856+
impl TargetOptions {
857+
pub fn is_specific_cpu(&self) -> bool {
858+
self.cpu != "generic"
859+
}
860+
}
861+
856862
impl Target {
857863
/// Given a function ABI, turn it into the correct ABI for this target.
858864
pub fn adjust_abi(&self, abi: Abi) -> Abi {

src/test/run-pass/cfg-target-cpu.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
pub fn main() {
12+
if cfg!(target_cpu = "cortex-a8") {
13+
println!("Running on Cortex A8!");
14+
} else {
15+
println!("Running on an arbitrary cpu");
16+
}
17+
}
18+

0 commit comments

Comments
 (0)