Skip to content

Commit

Permalink
rustc: add a --print target-list command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Feb 12, 2016
1 parent 77f9231 commit 0bb4209
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 78 deletions.
4 changes: 3 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub enum PrintRequest {
Sysroot,
CrateName,
Cfg,
TargetList,
}

pub enum Input {
Expand Down Expand Up @@ -844,7 +845,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
opt::multi("", "print", "Comma separated list of compiler information to \
print on stdout",
"[crate-name|file-names|sysroot]"),
"[crate-name|file-names|sysroot|target-list]"),
opt::flagmulti("g", "", "Equivalent to -C debuginfo=2"),
opt::flagmulti("O", "", "Equivalent to -C opt-level=2"),
opt::opt("o", "", "Write output to <filename>", "FILENAME"),
Expand Down Expand Up @@ -1109,6 +1110,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
"file-names" => PrintRequest::FileNames,
"sysroot" => PrintRequest::Sysroot,
"cfg" => PrintRequest::Cfg,
"target-list" => PrintRequest::TargetList,
req => {
early_error(error_format, &format!("unknown print request `{}`", req))
}
Expand Down
155 changes: 78 additions & 77 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,82 @@ mod solaris_base;
mod windows_base;
mod windows_msvc_base;

macro_rules! supported_targets {
( $(($triple:expr, $module:ident)),+ ) => (
/// List of supported targets
pub const TARGETS: &'static [&'static str] = &[$($triple),*];

// this would use a match if stringify! were allowed in pattern position
fn load_specific(target: &str) -> Option<Target> {
$(mod $module;)*
let target = target.replace("-", "_");
if false { }
$(
else if target == stringify!($module) {
let t = $module::target();
debug!("Got builtin target: {:?}", t);
return Some(t);
}
)*

None
}
)
}

supported_targets! {
("x86_64-unknown-linux-gnu", x86_64_unknown_linux_gnu),
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
("mipsel-unknown-linux-gnu", mipsel_unknown_linux_gnu),
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),
("arm-unknown-linux-gnueabihf", arm_unknown_linux_gnueabihf),
("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf),
("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu),
("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl),
("i686-unknown-linux-musl", i686_unknown_linux_musl),
("mips-unknown-linux-musl", mips_unknown_linux_musl),
("mipsel-unknown-linux-musl", mipsel_unknown_linux_musl),

("i686-linux-android", i686_linux_android),
("arm-linux-androideabi", arm_linux_androideabi),
("aarch64-linux-android", aarch64_linux_android),

("i686-unknown-freebsd", i686_unknown_freebsd),
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),

("i686-unknown-dragonfly", i686_unknown_dragonfly),
("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly),

("x86_64-unknown-bitrig", x86_64_unknown_bitrig),
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
("x86_64-rumprun-netbsd", x86_64_rumprun_netbsd),

("x86_64-apple-darwin", x86_64_apple_darwin),
("i686-apple-darwin", i686_apple_darwin),

("i386-apple-ios", i386_apple_ios),
("x86_64-apple-ios", x86_64_apple_ios),
("aarch64-apple-ios", aarch64_apple_ios),
("armv7-apple-ios", armv7_apple_ios),
("armv7s-apple-ios", armv7s_apple_ios),

("x86_64-sun-solaris", x86_64_sun_solaris),

("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
("i686-pc-windows-gnu", i686_pc_windows_gnu),

("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
("i686-pc-windows-msvc", i686_pc_windows_msvc),

("le32-unknown-nacl", le32_unknown_nacl),
("asmjs-unknown-emscripten", asmjs_unknown_emscripten)
}

/// Everything `rustc` knows about how to compile for a specific target.
///
/// Every field here must be specified, and has no default value.
Expand Down Expand Up @@ -393,85 +469,10 @@ impl Target {
Ok(Target::from_json(obj))
}

// this would use a match if stringify! were allowed in pattern position
macro_rules! load_specific {
( $($name:ident),+ ) => (
{
$(mod $name;)*
let target = target.replace("-", "_");
if false { }
$(
else if target == stringify!($name) {
let t = $name::target();
debug!("Got builtin target: {:?}", t);
return Ok(t);
}
)*
else if target == "x86_64-w64-mingw32" {
let t = x86_64_pc_windows_gnu::target();
return Ok(t);
} else if target == "i686-w64-mingw32" {
let t = i686_pc_windows_gnu::target();
return Ok(t);
}
}
)
if let Some(t) = load_specific(target) {
return Ok(t)
}

load_specific!(
x86_64_unknown_linux_gnu,
i686_unknown_linux_gnu,
mips_unknown_linux_gnu,
mipsel_unknown_linux_gnu,
powerpc_unknown_linux_gnu,
powerpc64_unknown_linux_gnu,
powerpc64le_unknown_linux_gnu,
arm_unknown_linux_gnueabi,
arm_unknown_linux_gnueabihf,
armv7_unknown_linux_gnueabihf,
aarch64_unknown_linux_gnu,
x86_64_unknown_linux_musl,
i686_unknown_linux_musl,
mips_unknown_linux_musl,
mipsel_unknown_linux_musl,

i686_linux_android,
arm_linux_androideabi,
aarch64_linux_android,

i686_unknown_freebsd,
x86_64_unknown_freebsd,

i686_unknown_dragonfly,
x86_64_unknown_dragonfly,

x86_64_unknown_bitrig,
x86_64_unknown_openbsd,
x86_64_unknown_netbsd,
x86_64_rumprun_netbsd,

x86_64_apple_darwin,
i686_apple_darwin,

i386_apple_ios,
x86_64_apple_ios,
aarch64_apple_ios,
armv7_apple_ios,
armv7s_apple_ios,

x86_64_sun_solaris,

x86_64_pc_windows_gnu,
i686_pc_windows_gnu,

x86_64_pc_windows_msvc,
i686_pc_windows_msvc,

le32_unknown_nacl,
asmjs_unknown_emscripten
);


let path = Path::new(target);

if path.is_file() {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ impl RustcDefaultCalls {
let attrs = input.map(|input| parse_crate_attrs(sess, input));
for req in &sess.opts.prints {
match *req {
PrintRequest::TargetList => {
let mut targets = rustc_back::target::TARGETS.to_vec();
targets.sort();
println!("{}", targets.join("\n"));
},
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
PrintRequest::FileNames |
PrintRequest::CrateName => {
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-make/print-target-list/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-include ../tools.mk

# Checks that all the targets returned by `rustc --print target-list` are valid
# target specifications
# TODO remove the '*ios*' case when rust-lang/rust#29812 is fixed
all:
for target in $(shell $(BARE_RUSTC) --print target-list); do \
case $$target in \
*ios*) \
;; \
*) \
$(BARE_RUSTC) --target $$target --print sysroot \
;; \
esac \
done

0 comments on commit 0bb4209

Please sign in to comment.