Skip to content

Commit 0bb4209

Browse files
author
Jorge Aparicio
committed
rustc: add a --print target-list command
1 parent 77f9231 commit 0bb4209

File tree

4 files changed

+101
-78
lines changed

4 files changed

+101
-78
lines changed

Diff for: src/librustc/session/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ pub enum PrintRequest {
164164
Sysroot,
165165
CrateName,
166166
Cfg,
167+
TargetList,
167168
}
168169

169170
pub enum Input {
@@ -844,7 +845,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
844845
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
845846
opt::multi("", "print", "Comma separated list of compiler information to \
846847
print on stdout",
847-
"[crate-name|file-names|sysroot]"),
848+
"[crate-name|file-names|sysroot|target-list]"),
848849
opt::flagmulti("g", "", "Equivalent to -C debuginfo=2"),
849850
opt::flagmulti("O", "", "Equivalent to -C opt-level=2"),
850851
opt::opt("o", "", "Write output to <filename>", "FILENAME"),
@@ -1109,6 +1110,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11091110
"file-names" => PrintRequest::FileNames,
11101111
"sysroot" => PrintRequest::Sysroot,
11111112
"cfg" => PrintRequest::Cfg,
1113+
"target-list" => PrintRequest::TargetList,
11121114
req => {
11131115
early_error(error_format, &format!("unknown print request `{}`", req))
11141116
}

Diff for: src/librustc_back/target/mod.rs

+78-77
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,82 @@ mod solaris_base;
6363
mod windows_base;
6464
mod windows_msvc_base;
6565

66+
macro_rules! supported_targets {
67+
( $(($triple:expr, $module:ident)),+ ) => (
68+
/// List of supported targets
69+
pub const TARGETS: &'static [&'static str] = &[$($triple),*];
70+
71+
// this would use a match if stringify! were allowed in pattern position
72+
fn load_specific(target: &str) -> Option<Target> {
73+
$(mod $module;)*
74+
let target = target.replace("-", "_");
75+
if false { }
76+
$(
77+
else if target == stringify!($module) {
78+
let t = $module::target();
79+
debug!("Got builtin target: {:?}", t);
80+
return Some(t);
81+
}
82+
)*
83+
84+
None
85+
}
86+
)
87+
}
88+
89+
supported_targets! {
90+
("x86_64-unknown-linux-gnu", x86_64_unknown_linux_gnu),
91+
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
92+
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
93+
("mipsel-unknown-linux-gnu", mipsel_unknown_linux_gnu),
94+
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
95+
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
96+
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
97+
("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),
98+
("arm-unknown-linux-gnueabihf", arm_unknown_linux_gnueabihf),
99+
("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf),
100+
("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu),
101+
("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl),
102+
("i686-unknown-linux-musl", i686_unknown_linux_musl),
103+
("mips-unknown-linux-musl", mips_unknown_linux_musl),
104+
("mipsel-unknown-linux-musl", mipsel_unknown_linux_musl),
105+
106+
("i686-linux-android", i686_linux_android),
107+
("arm-linux-androideabi", arm_linux_androideabi),
108+
("aarch64-linux-android", aarch64_linux_android),
109+
110+
("i686-unknown-freebsd", i686_unknown_freebsd),
111+
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
112+
113+
("i686-unknown-dragonfly", i686_unknown_dragonfly),
114+
("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly),
115+
116+
("x86_64-unknown-bitrig", x86_64_unknown_bitrig),
117+
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
118+
("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
119+
("x86_64-rumprun-netbsd", x86_64_rumprun_netbsd),
120+
121+
("x86_64-apple-darwin", x86_64_apple_darwin),
122+
("i686-apple-darwin", i686_apple_darwin),
123+
124+
("i386-apple-ios", i386_apple_ios),
125+
("x86_64-apple-ios", x86_64_apple_ios),
126+
("aarch64-apple-ios", aarch64_apple_ios),
127+
("armv7-apple-ios", armv7_apple_ios),
128+
("armv7s-apple-ios", armv7s_apple_ios),
129+
130+
("x86_64-sun-solaris", x86_64_sun_solaris),
131+
132+
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
133+
("i686-pc-windows-gnu", i686_pc_windows_gnu),
134+
135+
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
136+
("i686-pc-windows-msvc", i686_pc_windows_msvc),
137+
138+
("le32-unknown-nacl", le32_unknown_nacl),
139+
("asmjs-unknown-emscripten", asmjs_unknown_emscripten)
140+
}
141+
66142
/// Everything `rustc` knows about how to compile for a specific target.
67143
///
68144
/// Every field here must be specified, and has no default value.
@@ -393,85 +469,10 @@ impl Target {
393469
Ok(Target::from_json(obj))
394470
}
395471

396-
// this would use a match if stringify! were allowed in pattern position
397-
macro_rules! load_specific {
398-
( $($name:ident),+ ) => (
399-
{
400-
$(mod $name;)*
401-
let target = target.replace("-", "_");
402-
if false { }
403-
$(
404-
else if target == stringify!($name) {
405-
let t = $name::target();
406-
debug!("Got builtin target: {:?}", t);
407-
return Ok(t);
408-
}
409-
)*
410-
else if target == "x86_64-w64-mingw32" {
411-
let t = x86_64_pc_windows_gnu::target();
412-
return Ok(t);
413-
} else if target == "i686-w64-mingw32" {
414-
let t = i686_pc_windows_gnu::target();
415-
return Ok(t);
416-
}
417-
}
418-
)
472+
if let Some(t) = load_specific(target) {
473+
return Ok(t)
419474
}
420475

421-
load_specific!(
422-
x86_64_unknown_linux_gnu,
423-
i686_unknown_linux_gnu,
424-
mips_unknown_linux_gnu,
425-
mipsel_unknown_linux_gnu,
426-
powerpc_unknown_linux_gnu,
427-
powerpc64_unknown_linux_gnu,
428-
powerpc64le_unknown_linux_gnu,
429-
arm_unknown_linux_gnueabi,
430-
arm_unknown_linux_gnueabihf,
431-
armv7_unknown_linux_gnueabihf,
432-
aarch64_unknown_linux_gnu,
433-
x86_64_unknown_linux_musl,
434-
i686_unknown_linux_musl,
435-
mips_unknown_linux_musl,
436-
mipsel_unknown_linux_musl,
437-
438-
i686_linux_android,
439-
arm_linux_androideabi,
440-
aarch64_linux_android,
441-
442-
i686_unknown_freebsd,
443-
x86_64_unknown_freebsd,
444-
445-
i686_unknown_dragonfly,
446-
x86_64_unknown_dragonfly,
447-
448-
x86_64_unknown_bitrig,
449-
x86_64_unknown_openbsd,
450-
x86_64_unknown_netbsd,
451-
x86_64_rumprun_netbsd,
452-
453-
x86_64_apple_darwin,
454-
i686_apple_darwin,
455-
456-
i386_apple_ios,
457-
x86_64_apple_ios,
458-
aarch64_apple_ios,
459-
armv7_apple_ios,
460-
armv7s_apple_ios,
461-
462-
x86_64_sun_solaris,
463-
464-
x86_64_pc_windows_gnu,
465-
i686_pc_windows_gnu,
466-
467-
x86_64_pc_windows_msvc,
468-
i686_pc_windows_msvc,
469-
470-
le32_unknown_nacl,
471-
asmjs_unknown_emscripten
472-
);
473-
474-
475476
let path = Path::new(target);
476477

477478
if path.is_file() {

Diff for: src/librustc_driver/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@ impl RustcDefaultCalls {
532532
let attrs = input.map(|input| parse_crate_attrs(sess, input));
533533
for req in &sess.opts.prints {
534534
match *req {
535+
PrintRequest::TargetList => {
536+
let mut targets = rustc_back::target::TARGETS.to_vec();
537+
targets.sort();
538+
println!("{}", targets.join("\n"));
539+
},
535540
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
536541
PrintRequest::FileNames |
537542
PrintRequest::CrateName => {

Diff for: src/test/run-make/print-target-list/Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-include ../tools.mk
2+
3+
# Checks that all the targets returned by `rustc --print target-list` are valid
4+
# target specifications
5+
# TODO remove the '*ios*' case when rust-lang/rust#29812 is fixed
6+
all:
7+
for target in $(shell $(BARE_RUSTC) --print target-list); do \
8+
case $$target in \
9+
*ios*) \
10+
;; \
11+
*) \
12+
$(BARE_RUSTC) --target $$target --print sysroot \
13+
;; \
14+
esac \
15+
done

0 commit comments

Comments
 (0)