1 // Copyright 2014-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.
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.
11 //! [Flexible target specification.](https://github.com/rust-lang/rfcs/pull/131)
13 //! Rust targets a wide variety of usecases, and in the interest of flexibility,
14 //! allows new target triples to be defined in configuration files. Most users
15 //! will not need to care about these, but this is invaluable when porting Rust
16 //! to a new platform, and allows for an unprecedented level of control over how
17 //! the compiler works.
19 //! # Using custom targets
21 //! A target triple, as passed via `rustc --target=TRIPLE`, will first be
22 //! compared against the list of built-in targets. This is to ease distributing
23 //! rustc (no need for configuration files) and also to hold these built-in
24 //! targets as immutable and sacred. If `TRIPLE` is not one of the built-in
25 //! targets, rustc will check if a file named `TRIPLE` exists. If it does, it
26 //! will be loaded as the target configuration. If the file does not exist,
27 //! rustc will search each directory in the environment variable
28 //! `RUST_TARGET_PATH` for a file named `TRIPLE.json`. The first one found will
29 //! be loaded. If no file is found in any of those directories, a fatal error
32 //! Projects defining their own targets should use
33 //! `--target=path/to/my-awesome-platform.json` instead of adding to
34 //! `RUST_TARGET_PATH`.
36 //! # Defining a new target
38 //! Targets are defined using [JSON](http://json.org/). The `Target` struct in
39 //! this module defines the format the JSON file should take, though each
40 //! underscore in the field names should be replaced with a hyphen (`-`) in the
41 //! JSON file. Some fields are required in every target specification, such as
42 //! `llvm-target`, `target-endian`, `target-pointer-width`, `data-layout`,
43 //! `arch`, and `os`. In general, options passed to rustc with `-C` override
44 //! the target's settings, though `target-feature` and `link-args` will *add*
45 //! to the list specified by the target, rather than replace.
47 use serialize::json::{Json, ToJson};
48 use std::collections::BTreeMap;
49 use std::default::Default;
51 use std::path::{Path, PathBuf};
52 use std::str::FromStr;
53 use spec::abi::{Abi, lookup as lookup_abi};
72 mod windows_msvc_base;
79 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
80 RustcEncodable, RustcDecodable)]
81 pub enum LinkerFlavor {
89 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
90 RustcEncodable, RustcDecodable)]
99 fn from_str(s: &str) -> Option<Self> {
101 "darwin" => LldFlavor::Ld64,
102 "gnu" => LldFlavor::Ld,
103 "link" => LldFlavor::Link,
104 "wasm" => LldFlavor::Wasm,
110 impl ToJson for LldFlavor {
111 fn to_json(&self) -> Json {
113 LldFlavor::Ld64 => "darwin",
114 LldFlavor::Ld => "gnu",
115 LldFlavor::Link => "link",
116 LldFlavor::Wasm => "wasm",
121 impl ToJson for LinkerFlavor {
122 fn to_json(&self) -> Json {
123 self.desc().to_json()
126 macro_rules! flavor_mappings {
127 ($((($($flavor:tt)*), $string:expr),)*) => (
129 pub const fn one_of() -> &'static str {
130 concat!("one of: ", $($string, " ",)+)
133 pub fn from_str(s: &str) -> Option<Self> {
135 $($string => $($flavor)*,)+
140 pub fn desc(&self) -> &str {
142 $($($flavor)* => $string,)+
151 ((LinkerFlavor::Em), "em"),
152 ((LinkerFlavor::Gcc), "gcc"),
153 ((LinkerFlavor::Ld), "ld"),
154 ((LinkerFlavor::Msvc), "msvc"),
155 ((LinkerFlavor::Lld(LldFlavor::Wasm)), "wasm-ld"),
156 ((LinkerFlavor::Lld(LldFlavor::Ld64)), "ld64.lld"),
157 ((LinkerFlavor::Lld(LldFlavor::Ld)), "ld.lld"),
158 ((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"),
161 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
162 pub enum PanicStrategy {
168 pub fn desc(&self) -> &str {
170 PanicStrategy::Unwind => "unwind",
171 PanicStrategy::Abort => "abort",
176 impl ToJson for PanicStrategy {
177 fn to_json(&self) -> Json {
179 PanicStrategy::Abort => "abort".to_json(),
180 PanicStrategy::Unwind => "unwind".to_json(),
185 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
186 pub enum RelroLevel {
194 pub fn desc(&self) -> &str {
196 RelroLevel::Full => "full",
197 RelroLevel::Partial => "partial",
198 RelroLevel::Off => "off",
199 RelroLevel::None => "none",
204 impl FromStr for RelroLevel {
207 fn from_str(s: &str) -> Result<RelroLevel, ()> {
209 "full" => Ok(RelroLevel::Full),
210 "partial" => Ok(RelroLevel::Partial),
211 "off" => Ok(RelroLevel::Off),
212 "none" => Ok(RelroLevel::None),
218 impl ToJson for RelroLevel {
219 fn to_json(&self) -> Json {
221 RelroLevel::Full => "full".to_json(),
222 RelroLevel::Partial => "partial".to_json(),
223 RelroLevel::Off => "off".to_json(),
224 RelroLevel::None => "None".to_json(),
229 pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>;
230 pub type TargetResult = Result<Target, String>;
232 macro_rules! supported_targets {
233 ( $(($triple:expr, $module:ident),)+ ) => (
236 /// List of supported targets
237 const TARGETS: &'static [&'static str] = &[$($triple),*];
239 fn load_specific(target: &str) -> TargetResult {
243 let mut t = $module::target()?;
244 t.options.is_builtin = true;
246 // round-trip through the JSON parser to ensure at
247 // run-time that the parser works correctly
248 t = Target::from_json(t.to_json())?;
249 debug!("Got builtin target: {:?}", t);
253 _ => Err(format!("Unable to find target: {}", target))
257 pub fn get_targets() -> Box<dyn Iterator<Item=String>> {
258 Box::new(TARGETS.iter().filter_map(|t| -> Option<String> {
260 .and(Ok(t.to_string()))
266 mod test_json_encode_decode {
267 use serialize::json::ToJson;
269 $(use super::$module;)*
274 // Grab the TargetResult struct. If we successfully retrieved
275 // a Target, then the test JSON encoding/decoding can run for this
276 // Target on this testing platform (i.e., checking the iOS targets
277 // only on a Mac test platform).
278 let _ = $module::target().map(|original| {
279 let as_json = original.to_json();
280 let parsed = Target::from_json(as_json).unwrap();
281 assert_eq!(original, parsed);
290 ("x86_64-unknown-linux-gnu", x86_64_unknown_linux_gnu),
291 ("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
292 ("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
293 ("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
294 ("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
295 ("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),
296 ("mips64el-unknown-linux-gnuabi64", mips64el_unknown_linux_gnuabi64),
297 ("mipsel-unknown-linux-gnu", mipsel_unknown_linux_gnu),
298 ("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
299 ("powerpc-unknown-linux-gnuspe", powerpc_unknown_linux_gnuspe),
300 ("powerpc-unknown-linux-musl", powerpc_unknown_linux_musl),
301 ("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
302 ("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
303 ("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
304 ("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
305 ("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
306 ("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
307 ("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
308 ("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),
309 ("arm-unknown-linux-gnueabihf", arm_unknown_linux_gnueabihf),
310 ("arm-unknown-linux-musleabi", arm_unknown_linux_musleabi),
311 ("arm-unknown-linux-musleabihf", arm_unknown_linux_musleabihf),
312 ("armv4t-unknown-linux-gnueabi", armv4t_unknown_linux_gnueabi),
313 ("armv5te-unknown-linux-gnueabi", armv5te_unknown_linux_gnueabi),
314 ("armv5te-unknown-linux-musleabi", armv5te_unknown_linux_musleabi),
315 ("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf),
316 ("armv7-unknown-linux-musleabihf", armv7_unknown_linux_musleabihf),
317 ("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu),
319 ("aarch64-unknown-linux-musl", aarch64_unknown_linux_musl),
320 ("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl),
321 ("i686-unknown-linux-musl", i686_unknown_linux_musl),
322 ("i586-unknown-linux-musl", i586_unknown_linux_musl),
323 ("mips-unknown-linux-musl", mips_unknown_linux_musl),
324 ("mipsel-unknown-linux-musl", mipsel_unknown_linux_musl),
326 ("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
327 ("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),
329 ("i686-linux-android", i686_linux_android),
330 ("x86_64-linux-android", x86_64_linux_android),
331 ("arm-linux-androideabi", arm_linux_androideabi),
332 ("armv7-linux-androideabi", armv7_linux_androideabi),
333 ("aarch64-linux-android", aarch64_linux_android),
335 ("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
336 ("i686-unknown-freebsd", i686_unknown_freebsd),
337 ("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
339 ("i686-unknown-dragonfly", i686_unknown_dragonfly),
340 ("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly),
342 ("x86_64-unknown-bitrig", x86_64_unknown_bitrig),
344 ("aarch64-unknown-openbsd", aarch64_unknown_openbsd),
345 ("i686-unknown-openbsd", i686_unknown_openbsd),
346 ("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
348 ("aarch64-unknown-netbsd", aarch64_unknown_netbsd),
349 ("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf),
350 ("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf),
351 ("i686-unknown-netbsd", i686_unknown_netbsd),
352 ("powerpc-unknown-netbsd", powerpc_unknown_netbsd),
353 ("sparc64-unknown-netbsd", sparc64_unknown_netbsd),
354 ("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
355 ("x86_64-rumprun-netbsd", x86_64_rumprun_netbsd),
357 ("i686-unknown-haiku", i686_unknown_haiku),
358 ("x86_64-unknown-haiku", x86_64_unknown_haiku),
360 ("x86_64-apple-darwin", x86_64_apple_darwin),
361 ("i686-apple-darwin", i686_apple_darwin),
363 ("aarch64-fuchsia", aarch64_fuchsia),
364 ("x86_64-fuchsia", x86_64_fuchsia),
366 ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
368 ("x86_64-unknown-redox", x86_64_unknown_redox),
370 ("i386-apple-ios", i386_apple_ios),
371 ("x86_64-apple-ios", x86_64_apple_ios),
372 ("aarch64-apple-ios", aarch64_apple_ios),
373 ("armv7-apple-ios", armv7_apple_ios),
374 ("armv7s-apple-ios", armv7s_apple_ios),
376 ("armebv7r-none-eabi", armebv7r_none_eabi),
377 ("armebv7r-none-eabihf", armebv7r_none_eabihf),
378 ("armv7r-none-eabi", armv7r_none_eabi),
379 ("armv7r-none-eabihf", armv7r_none_eabihf),
381 ("x86_64-sun-solaris", x86_64_sun_solaris),
382 ("sparcv9-sun-solaris", sparcv9_sun_solaris),
384 ("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
385 ("i686-pc-windows-gnu", i686_pc_windows_gnu),
387 ("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
388 ("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
389 ("i686-pc-windows-msvc", i686_pc_windows_msvc),
390 ("i586-pc-windows-msvc", i586_pc_windows_msvc),
391 ("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
393 ("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
394 ("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
395 ("wasm32-unknown-unknown", wasm32_unknown_unknown),
396 ("wasm32-experimental-emscripten", wasm32_experimental_emscripten),
398 ("thumbv6m-none-eabi", thumbv6m_none_eabi),
399 ("thumbv7m-none-eabi", thumbv7m_none_eabi),
400 ("thumbv7em-none-eabi", thumbv7em_none_eabi),
401 ("thumbv7em-none-eabihf", thumbv7em_none_eabihf),
402 ("thumbv8m.base-none-eabi", thumbv8m_base_none_eabi),
404 ("msp430-none-elf", msp430_none_elf),
406 ("aarch64-unknown-cloudabi", aarch64_unknown_cloudabi),
407 ("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf),
408 ("i686-unknown-cloudabi", i686_unknown_cloudabi),
409 ("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi),
411 ("aarch64-unknown-hermit", aarch64_unknown_hermit),
412 ("x86_64-unknown-hermit", x86_64_unknown_hermit),
414 ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
415 ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
417 ("aarch64-unknown-none", aarch64_unknown_none),
419 ("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx),
422 /// Everything `rustc` knows about how to compile for a specific target.
424 /// Every field here must be specified, and has no default value.
425 #[derive(PartialEq, Clone, Debug)]
427 /// Target triple to pass to LLVM.
428 pub llvm_target: String,
429 /// String to use as the `target_endian` `cfg` variable.
430 pub target_endian: String,
431 /// String to use as the `target_pointer_width` `cfg` variable.
432 pub target_pointer_width: String,
433 /// Width of c_int type
434 pub target_c_int_width: String,
435 /// OS name to use for conditional compilation.
436 pub target_os: String,
437 /// Environment name to use for conditional compilation.
438 pub target_env: String,
439 /// Vendor name to use for conditional compilation.
440 pub target_vendor: String,
441 /// Architecture to use for ABI considerations. Valid options: "x86",
442 /// "x86_64", "arm", "aarch64", "mips", "powerpc", and "powerpc64".
444 /// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
445 pub data_layout: String,
447 pub linker_flavor: LinkerFlavor,
448 /// Optional settings with defaults.
449 pub options: TargetOptions,
452 pub trait HasTargetSpec {
453 fn target_spec(&self) -> &Target;
456 impl HasTargetSpec for Target {
457 fn target_spec(&self) -> &Target {
462 /// Optional aspects of a target specification.
464 /// This has an implementation of `Default`, see each field for what the default is. In general,
465 /// these try to take "minimal defaults" that don't assume anything about the runtime they run in.
466 #[derive(PartialEq, Clone, Debug)]
467 pub struct TargetOptions {
468 /// Whether the target is built-in or loaded from a custom target specification.
469 pub is_builtin: bool,
472 pub linker: Option<String>,
475 pub lld_flavor: LldFlavor,
477 /// Linker arguments that are passed *before* any user-defined libraries.
478 pub pre_link_args: LinkArgs, // ... unconditionally
479 pub pre_link_args_crt: LinkArgs, // ... when linking with a bundled crt
480 /// Objects to link before all others, always found within the
482 pub pre_link_objects_exe: Vec<String>, // ... when linking an executable, unconditionally
483 pub pre_link_objects_exe_crt: Vec<String>, // ... when linking an executable with a bundled crt
484 pub pre_link_objects_dll: Vec<String>, // ... when linking a dylib
485 /// Linker arguments that are unconditionally passed after any
486 /// user-defined but before post_link_objects. Standard platform
487 /// libraries that should be always be linked to, usually go here.
488 pub late_link_args: LinkArgs,
489 /// Objects to link after all others, always found within the
491 pub post_link_objects: Vec<String>, // ... unconditionally
492 pub post_link_objects_crt: Vec<String>, // ... when linking with a bundled crt
493 /// Linker arguments that are unconditionally passed *after* any
494 /// user-defined libraries.
495 pub post_link_args: LinkArgs,
497 /// Environment variables to be set before invoking the linker.
498 pub link_env: Vec<(String, String)>,
500 /// Extra arguments to pass to the external assembler (when used)
501 pub asm_args: Vec<String>,
503 /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
506 /// Default target features to pass to LLVM. These features will *always* be
507 /// passed, and cannot be disabled even via `-C`. Corresponds to `llc
508 /// -mattr=$features`.
509 pub features: String,
510 /// Whether dynamic linking is available on this target. Defaults to false.
511 pub dynamic_linking: bool,
512 /// If dynamic linking is available, whether only cdylibs are supported.
513 pub only_cdylib: bool,
514 /// Whether executables are available on this target. iOS, for example, only allows static
515 /// libraries. Defaults to false.
516 pub executables: bool,
517 /// Relocation model to use in object file. Corresponds to `llc
518 /// -relocation-model=$relocation_model`. Defaults to "pic".
519 pub relocation_model: String,
520 /// Code model to use. Corresponds to `llc -code-model=$code_model`.
521 pub code_model: Option<String>,
522 /// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec"
523 /// and "local-exec". This is similar to the -ftls-model option in GCC/Clang.
524 pub tls_model: String,
525 /// Do not emit code that uses the "red zone", if the ABI has one. Defaults to false.
526 pub disable_redzone: bool,
527 /// Eliminate frame pointers from stack frames if possible. Defaults to true.
528 pub eliminate_frame_pointer: bool,
529 /// Emit each function in its own section. Defaults to true.
530 pub function_sections: bool,
531 /// String to prepend to the name of every dynamic library. Defaults to "lib".
532 pub dll_prefix: String,
533 /// String to append to the name of every dynamic library. Defaults to ".so".
534 pub dll_suffix: String,
535 /// String to append to the name of every executable.
536 pub exe_suffix: String,
537 /// String to prepend to the name of every static library. Defaults to "lib".
538 pub staticlib_prefix: String,
539 /// String to append to the name of every static library. Defaults to ".a".
540 pub staticlib_suffix: String,
541 /// OS family to use for conditional compilation. Valid options: "unix", "windows".
542 pub target_family: Option<String>,
543 /// Whether the target toolchain's ABI supports returning small structs as an integer.
544 pub abi_return_struct_as_int: bool,
545 /// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
546 /// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
547 pub is_like_osx: bool,
548 /// Whether the target toolchain is like Solaris's.
549 /// Only useful for compiling against Illumos/Solaris,
550 /// as they have a different set of linker flags. Defaults to false.
551 pub is_like_solaris: bool,
552 /// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
553 /// only really used for figuring out how to find libraries, since Windows uses its own
554 /// library naming convention. Defaults to false.
555 pub is_like_windows: bool,
556 pub is_like_msvc: bool,
557 /// Whether the target toolchain is like Android's. Only useful for compiling against Android.
558 /// Defaults to false.
559 pub is_like_android: bool,
560 /// Whether the target toolchain is like Emscripten's. Only useful for compiling with
561 /// Emscripten toolchain.
562 /// Defaults to false.
563 pub is_like_emscripten: bool,
564 /// Whether the target toolchain is like Fuchsia's.
565 pub is_like_fuchsia: bool,
566 /// Whether the linker support GNU-like arguments such as -O. Defaults to false.
567 pub linker_is_gnu: bool,
568 /// The MinGW toolchain has a known issue that prevents it from correctly
569 /// handling COFF object files with more than 2<sup>15</sup> sections. Since each weak
570 /// symbol needs its own COMDAT section, weak linkage implies a large
571 /// number sections that easily exceeds the given limit for larger
572 /// codebases. Consequently we want a way to disallow weak linkage on some
574 pub allows_weak_linkage: bool,
575 /// Whether the linker support rpaths or not. Defaults to false.
577 /// Whether to disable linking to the default libraries, typically corresponds
578 /// to `-nodefaultlibs`. Defaults to true.
579 pub no_default_libraries: bool,
580 /// Dynamically linked executables can be compiled as position independent
581 /// if the default relocation model of position independent code is not
582 /// changed. This is a requirement to take advantage of ASLR, as otherwise
583 /// the functions in the executable are not randomized and can be used
584 /// during an exploit of a vulnerability in any code.
585 pub position_independent_executables: bool,
586 /// Determines if the target always requires using the PLT for indirect
587 /// library calls or not. This controls the default value of the `-Z plt` flag.
589 /// Either partial, full, or off. Full RELRO makes the dynamic linker
590 /// resolve all symbols at startup and marks the GOT read-only before
591 /// starting the program, preventing overwriting the GOT.
592 pub relro_level: RelroLevel,
593 /// Format that archives should be emitted in. This affects whether we use
594 /// LLVM to assemble an archive or fall back to the system linker, and
595 /// currently only "gnu" is used to fall into LLVM. Unknown strings cause
596 /// the system linker to be used.
597 pub archive_format: String,
598 /// Is asm!() allowed? Defaults to true.
600 /// Whether the target uses a custom unwind resumption routine.
601 /// By default LLVM lowers `resume` instructions into calls to `_Unwind_Resume`
602 /// defined in libgcc. If this option is enabled, the target must provide
603 /// `eh_unwind_resume` lang item.
604 pub custom_unwind_resume: bool,
606 /// Flag indicating whether ELF TLS (e.g. #[thread_local]) is available for
608 pub has_elf_tls: bool,
609 // This is mainly for easy compatibility with emscripten.
610 // If we give emcc .o files that are actually .bc files it
612 pub obj_is_bitcode: bool,
614 // LLVM can't produce object files for this target. Instead, we'll make LLVM
615 // emit assembly and then use `gcc` to turn that assembly into an object
617 pub no_integrated_as: bool,
619 /// Don't use this field; instead use the `.min_atomic_width()` method.
620 pub min_atomic_width: Option<u64>,
622 /// Don't use this field; instead use the `.max_atomic_width()` method.
623 pub max_atomic_width: Option<u64>,
625 /// Whether the target supports atomic CAS operations natively
626 pub atomic_cas: bool,
628 /// Panic strategy: "unwind" or "abort"
629 pub panic_strategy: PanicStrategy,
631 /// A blacklist of ABIs unsupported by the current target. Note that generic
632 /// ABIs are considered to be supported on all platforms and cannot be blacklisted.
633 pub abi_blacklist: Vec<Abi>,
635 /// Whether or not linking dylibs to a static CRT is allowed.
636 pub crt_static_allows_dylibs: bool,
637 /// Whether or not the CRT is statically linked by default.
638 pub crt_static_default: bool,
639 /// Whether or not crt-static is respected by the compiler (or is a no-op).
640 pub crt_static_respected: bool,
642 /// Whether or not stack probes (__rust_probestack) are enabled
643 pub stack_probes: bool,
645 /// The minimum alignment for global symbols.
646 pub min_global_align: Option<u64>,
648 /// Default number of codegen units to use in debug mode
649 pub default_codegen_units: Option<u64>,
651 /// Whether to generate trap instructions in places where optimization would
652 /// otherwise produce control flow that falls through into unrelated memory.
653 pub trap_unreachable: bool,
655 /// This target requires everything to be compiled with LTO to emit a final
656 /// executable, aka there is no native linker for this target.
657 pub requires_lto: bool,
659 /// This target has no support for threads.
660 pub singlethread: bool,
662 /// Whether library functions call lowering/optimization is disabled in LLVM
663 /// for this target unconditionally.
664 pub no_builtins: bool,
666 /// Whether to lower 128-bit operations to compiler_builtins calls. Use if
667 /// your backend only supports 64-bit and smaller math.
668 pub i128_lowering: bool,
670 /// The codegen backend to use for this target, typically "llvm"
671 pub codegen_backend: String,
673 /// The default visibility for symbols in this target should be "hidden"
674 /// rather than "default"
675 pub default_hidden_visibility: bool,
677 /// Whether or not bitcode is embedded in object files
678 pub embed_bitcode: bool,
680 /// Whether a .debug_gdb_scripts section will be added to the output object file
681 pub emit_debug_gdb_scripts: bool,
683 /// Whether or not to unconditionally `uwtable` attributes on functions,
684 /// typically because the platform needs to unwind for things like stack
686 pub requires_uwtable: bool,
688 /// Whether or not SIMD types are passed by reference in the Rust ABI,
689 /// typically required if a target can be compiled with a mixed set of
690 /// target features. This is `true` by default, and `false` for targets like
691 /// wasm32 where the whole program either has simd or not.
692 pub simd_types_indirect: bool,
694 /// If set, have the linker export exactly these symbols, instead of using
695 /// the usual logic to figure this out from the crate itself.
696 pub override_export_symbols: Option<Vec<String>>
699 impl Default for TargetOptions {
700 /// Create a set of "sane defaults" for any target. This is still
701 /// incomplete, and if used for compilation, will certainly not work.
702 fn default() -> TargetOptions {
705 linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()),
706 lld_flavor: LldFlavor::Ld,
707 pre_link_args: LinkArgs::new(),
708 pre_link_args_crt: LinkArgs::new(),
709 post_link_args: LinkArgs::new(),
710 asm_args: Vec::new(),
711 cpu: "generic".to_string(),
712 features: String::new(),
713 dynamic_linking: false,
716 relocation_model: "pic".to_string(),
718 tls_model: "global-dynamic".to_string(),
719 disable_redzone: false,
720 eliminate_frame_pointer: true,
721 function_sections: true,
722 dll_prefix: "lib".to_string(),
723 dll_suffix: ".so".to_string(),
724 exe_suffix: String::new(),
725 staticlib_prefix: "lib".to_string(),
726 staticlib_suffix: ".a".to_string(),
728 abi_return_struct_as_int: false,
730 is_like_solaris: false,
731 is_like_windows: false,
732 is_like_android: false,
733 is_like_emscripten: false,
735 is_like_fuchsia: false,
736 linker_is_gnu: false,
737 allows_weak_linkage: true,
739 no_default_libraries: true,
740 position_independent_executables: false,
742 relro_level: RelroLevel::None,
743 pre_link_objects_exe: Vec::new(),
744 pre_link_objects_exe_crt: Vec::new(),
745 pre_link_objects_dll: Vec::new(),
746 post_link_objects: Vec::new(),
747 post_link_objects_crt: Vec::new(),
748 late_link_args: LinkArgs::new(),
749 link_env: Vec::new(),
750 archive_format: "gnu".to_string(),
751 custom_unwind_resume: false,
754 obj_is_bitcode: false,
755 no_integrated_as: false,
756 min_atomic_width: None,
757 max_atomic_width: None,
759 panic_strategy: PanicStrategy::Unwind,
760 abi_blacklist: vec![],
761 crt_static_allows_dylibs: false,
762 crt_static_default: false,
763 crt_static_respected: false,
765 min_global_align: None,
766 default_codegen_units: None,
767 trap_unreachable: true,
771 i128_lowering: false,
772 codegen_backend: "llvm".to_string(),
773 default_hidden_visibility: false,
774 embed_bitcode: false,
775 emit_debug_gdb_scripts: true,
776 requires_uwtable: false,
777 simd_types_indirect: true,
778 override_export_symbols: None,
784 /// Given a function ABI, turn it into the correct ABI for this target.
785 pub fn adjust_abi(&self, abi: Abi) -> Abi {
788 if self.options.is_like_windows && self.arch == "x86" {
794 // These ABI kinds are ignored on non-x86 Windows targets.
795 // See https://docs.microsoft.com/en-us/cpp/cpp/argument-passing-and-naming-conventions
796 // and the individual pages for __stdcall et al.
797 Abi::Stdcall | Abi::Fastcall | Abi::Vectorcall | Abi::Thiscall => {
798 if self.options.is_like_windows && self.arch != "x86" {
808 /// Minimum integer size in bits that this target can perform atomic
810 pub fn min_atomic_width(&self) -> u64 {
811 self.options.min_atomic_width.unwrap_or(8)
814 /// Maximum integer size in bits that this target can perform atomic
816 pub fn max_atomic_width(&self) -> u64 {
817 self.options.max_atomic_width.unwrap_or_else(|| self.target_pointer_width.parse().unwrap())
820 pub fn is_abi_supported(&self, abi: Abi) -> bool {
821 abi.generic() || !self.options.abi_blacklist.contains(&abi)
824 /// Load a target descriptor from a JSON object.
825 pub fn from_json(obj: Json) -> TargetResult {
826 // While ugly, this code must remain this way to retain
827 // compatibility with existing JSON fields and the internal
828 // expected naming of the Target and TargetOptions structs.
829 // To ensure compatibility is retained, the built-in targets
830 // are round-tripped through this code to catch cases where
831 // the JSON parser is not updated to match the structs.
833 let get_req_field = |name: &str| {
835 .map(|s| s.as_string())
836 .and_then(|os| os.map(|s| s.to_string()))
837 .ok_or_else(|| format!("Field {} in target specification is required", name))
840 let get_opt_field = |name: &str, default: &str| {
841 obj.find(name).and_then(|s| s.as_string())
842 .map(|s| s.to_string())
843 .unwrap_or_else(|| default.to_string())
846 let mut base = Target {
847 llvm_target: get_req_field("llvm-target")?,
848 target_endian: get_req_field("target-endian")?,
849 target_pointer_width: get_req_field("target-pointer-width")?,
850 target_c_int_width: get_req_field("target-c-int-width")?,
851 data_layout: get_req_field("data-layout")?,
852 arch: get_req_field("arch")?,
853 target_os: get_req_field("os")?,
854 target_env: get_opt_field("env", ""),
855 target_vendor: get_opt_field("vendor", "unknown"),
856 linker_flavor: LinkerFlavor::from_str(&*get_req_field("linker-flavor")?)
858 format!("linker flavor must be {}", LinkerFlavor::one_of())
860 options: Default::default(),
864 ($key_name:ident) => ( {
865 let name = (stringify!($key_name)).replace("_", "-");
866 obj.find(&name[..]).map(|o| o.as_string()
867 .map(|s| base.options.$key_name = s.to_string()));
869 ($key_name:ident, bool) => ( {
870 let name = (stringify!($key_name)).replace("_", "-");
872 .map(|o| o.as_boolean()
873 .map(|s| base.options.$key_name = s));
875 ($key_name:ident, Option<u64>) => ( {
876 let name = (stringify!($key_name)).replace("_", "-");
879 .map(|s| base.options.$key_name = Some(s)));
881 ($key_name:ident, PanicStrategy) => ( {
882 let name = (stringify!($key_name)).replace("_", "-");
883 obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
885 "unwind" => base.options.$key_name = PanicStrategy::Unwind,
886 "abort" => base.options.$key_name = PanicStrategy::Abort,
887 _ => return Some(Err(format!("'{}' is not a valid value for \
888 panic-strategy. Use 'unwind' or 'abort'.",
892 })).unwrap_or(Ok(()))
894 ($key_name:ident, RelroLevel) => ( {
895 let name = (stringify!($key_name)).replace("_", "-");
896 obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
897 match s.parse::<RelroLevel>() {
898 Ok(level) => base.options.$key_name = level,
899 _ => return Some(Err(format!("'{}' is not a valid value for \
900 relro-level. Use 'full', 'partial, or 'off'.",
904 })).unwrap_or(Ok(()))
906 ($key_name:ident, list) => ( {
907 let name = (stringify!($key_name)).replace("_", "-");
908 obj.find(&name[..]).map(|o| o.as_array()
909 .map(|v| base.options.$key_name = v.iter()
910 .map(|a| a.as_string().unwrap().to_string()).collect()
914 ($key_name:ident, opt_list) => ( {
915 let name = (stringify!($key_name)).replace("_", "-");
916 obj.find(&name[..]).map(|o| o.as_array()
917 .map(|v| base.options.$key_name = Some(v.iter()
918 .map(|a| a.as_string().unwrap().to_string()).collect())
922 ($key_name:ident, optional) => ( {
923 let name = (stringify!($key_name)).replace("_", "-");
924 if let Some(o) = obj.find(&name[..]) {
925 base.options.$key_name = o
927 .map(|s| s.to_string() );
930 ($key_name:ident, LldFlavor) => ( {
931 let name = (stringify!($key_name)).replace("_", "-");
932 obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
933 if let Some(flavor) = LldFlavor::from_str(&s) {
934 base.options.$key_name = flavor;
936 return Some(Err(format!(
937 "'{}' is not a valid value for lld-flavor. \
938 Use 'darwin', 'gnu', 'link' or 'wasm.",
942 })).unwrap_or(Ok(()))
944 ($key_name:ident, LinkerFlavor) => ( {
945 let name = (stringify!($key_name)).replace("_", "-");
946 obj.find(&name[..]).and_then(|o| o.as_string().map(|s| {
947 LinkerFlavor::from_str(&s).ok_or_else(|| {
948 Err(format!("'{}' is not a valid value for linker-flavor. \
949 Use 'em', 'gcc', 'ld' or 'msvc.", s))
951 })).unwrap_or(Ok(()))
953 ($key_name:ident, link_args) => ( {
954 let name = (stringify!($key_name)).replace("_", "-");
955 if let Some(val) = obj.find(&name[..]) {
956 let obj = val.as_object().ok_or_else(|| format!("{}: expected a \
957 JSON object with fields per linker-flavor.", name))?;
958 let mut args = LinkArgs::new();
960 let flavor = LinkerFlavor::from_str(&k).ok_or_else(|| {
961 format!("{}: '{}' is not a valid value for linker-flavor. \
962 Use 'em', 'gcc', 'ld' or 'msvc'", name, k)
965 let v = v.as_array().ok_or_else(||
966 format!("{}.{}: expected a JSON array", name, k)
967 )?.iter().enumerate()
969 let s = s.as_string().ok_or_else(||
970 format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
973 .collect::<Result<Vec<_>, String>>()?;
975 args.insert(flavor, v);
977 base.options.$key_name = args;
980 ($key_name:ident, env) => ( {
981 let name = (stringify!($key_name)).replace("_", "-");
982 if let Some(a) = obj.find(&name[..]).and_then(|o| o.as_array()) {
984 if let Some(s) = o.as_string() {
985 let p = s.split('=').collect::<Vec<_>>();
987 let k = p[0].to_string();
988 let v = p[1].to_string();
989 base.options.$key_name.push((k, v));
997 key!(is_builtin, bool);
998 key!(linker, optional);
999 key!(lld_flavor, LldFlavor)?;
1000 key!(pre_link_args, link_args);
1001 key!(pre_link_args_crt, link_args);
1002 key!(pre_link_objects_exe, list);
1003 key!(pre_link_objects_exe_crt, list);
1004 key!(pre_link_objects_dll, list);
1005 key!(late_link_args, link_args);
1006 key!(post_link_objects, list);
1007 key!(post_link_objects_crt, list);
1008 key!(post_link_args, link_args);
1009 key!(link_env, env);
1010 key!(asm_args, list);
1013 key!(dynamic_linking, bool);
1014 key!(only_cdylib, bool);
1015 key!(executables, bool);
1016 key!(relocation_model);
1017 key!(code_model, optional);
1019 key!(disable_redzone, bool);
1020 key!(eliminate_frame_pointer, bool);
1021 key!(function_sections, bool);
1025 key!(staticlib_prefix);
1026 key!(staticlib_suffix);
1027 key!(target_family, optional);
1028 key!(abi_return_struct_as_int, bool);
1029 key!(is_like_osx, bool);
1030 key!(is_like_solaris, bool);
1031 key!(is_like_windows, bool);
1032 key!(is_like_msvc, bool);
1033 key!(is_like_emscripten, bool);
1034 key!(is_like_android, bool);
1035 key!(is_like_fuchsia, bool);
1036 key!(linker_is_gnu, bool);
1037 key!(allows_weak_linkage, bool);
1038 key!(has_rpath, bool);
1039 key!(no_default_libraries, bool);
1040 key!(position_independent_executables, bool);
1041 key!(needs_plt, bool);
1042 key!(relro_level, RelroLevel)?;
1043 key!(archive_format);
1044 key!(allow_asm, bool);
1045 key!(custom_unwind_resume, bool);
1046 key!(has_elf_tls, bool);
1047 key!(obj_is_bitcode, bool);
1048 key!(no_integrated_as, bool);
1049 key!(max_atomic_width, Option<u64>);
1050 key!(min_atomic_width, Option<u64>);
1051 key!(atomic_cas, bool);
1052 key!(panic_strategy, PanicStrategy)?;
1053 key!(crt_static_allows_dylibs, bool);
1054 key!(crt_static_default, bool);
1055 key!(crt_static_respected, bool);
1056 key!(stack_probes, bool);
1057 key!(min_global_align, Option<u64>);
1058 key!(default_codegen_units, Option<u64>);
1059 key!(trap_unreachable, bool);
1060 key!(requires_lto, bool);
1061 key!(singlethread, bool);
1062 key!(no_builtins, bool);
1063 key!(codegen_backend);
1064 key!(default_hidden_visibility, bool);
1065 key!(embed_bitcode, bool);
1066 key!(emit_debug_gdb_scripts, bool);
1067 key!(requires_uwtable, bool);
1068 key!(simd_types_indirect, bool);
1069 key!(override_export_symbols, opt_list);
1071 if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
1072 for name in array.iter().filter_map(|abi| abi.as_string()) {
1073 match lookup_abi(name) {
1076 return Err(format!("The ABI \"{}\" is considered to be supported on \
1077 all targets and cannot be blacklisted", abi))
1080 base.options.abi_blacklist.push(abi)
1082 None => return Err(format!("Unknown ABI \"{}\" in target specification", name))
1090 /// Search RUST_TARGET_PATH for a JSON file specifying the given target
1091 /// triple. Note that it could also just be a bare filename already, so also
1092 /// check for that. If one of the hardcoded targets we know about, just
1093 /// return it directly.
1095 /// The error string could come from any of the APIs called, including
1096 /// filesystem access and JSON decoding.
1097 pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
1100 use serialize::json;
1102 fn load_file(path: &Path) -> Result<Target, String> {
1103 let contents = fs::read(path).map_err(|e| e.to_string())?;
1104 let obj = json::from_reader(&mut &contents[..])
1105 .map_err(|e| e.to_string())?;
1106 Target::from_json(obj)
1109 match *target_triple {
1110 TargetTriple::TargetTriple(ref target_triple) => {
1111 // check if triple is in list of supported targets
1112 if let Ok(t) = load_specific(target_triple) {
1116 // search for a file named `target_triple`.json in RUST_TARGET_PATH
1118 let mut target = target_triple.to_string();
1119 target.push_str(".json");
1120 PathBuf::from(target)
1123 let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();
1125 // FIXME 16351: add a sane default search path?
1127 for dir in env::split_paths(&target_path) {
1128 let p = dir.join(&path);
1130 return load_file(&p);
1133 Err(format!("Could not find specification for target {:?}", target_triple))
1135 TargetTriple::TargetPath(ref target_path) => {
1136 if target_path.is_file() {
1137 return load_file(&target_path);
1139 Err(format!("Target path {:?} is not a valid file", target_path))
1145 impl ToJson for Target {
1146 fn to_json(&self) -> Json {
1147 let mut d = BTreeMap::new();
1148 let default: TargetOptions = Default::default();
1150 macro_rules! target_val {
1151 ($attr:ident) => ( {
1152 let name = (stringify!($attr)).replace("_", "-");
1153 d.insert(name, self.$attr.to_json());
1155 ($attr:ident, $key_name:expr) => ( {
1156 let name = $key_name;
1157 d.insert(name.to_string(), self.$attr.to_json());
1161 macro_rules! target_option_val {
1162 ($attr:ident) => ( {
1163 let name = (stringify!($attr)).replace("_", "-");
1164 if default.$attr != self.options.$attr {
1165 d.insert(name, self.options.$attr.to_json());
1168 ($attr:ident, $key_name:expr) => ( {
1169 let name = $key_name;
1170 if default.$attr != self.options.$attr {
1171 d.insert(name.to_string(), self.options.$attr.to_json());
1174 (link_args - $attr:ident) => ( {
1175 let name = (stringify!($attr)).replace("_", "-");
1176 if default.$attr != self.options.$attr {
1177 let obj = self.options.$attr
1179 .map(|(k, v)| (k.desc().to_owned(), v.clone()))
1180 .collect::<BTreeMap<_, _>>();
1181 d.insert(name, obj.to_json());
1184 (env - $attr:ident) => ( {
1185 let name = (stringify!($attr)).replace("_", "-");
1186 if default.$attr != self.options.$attr {
1187 let obj = self.options.$attr
1189 .map(|&(ref k, ref v)| k.clone() + "=" + &v)
1190 .collect::<Vec<_>>();
1191 d.insert(name, obj.to_json());
1197 target_val!(llvm_target);
1198 target_val!(target_endian);
1199 target_val!(target_pointer_width);
1200 target_val!(target_c_int_width);
1202 target_val!(target_os, "os");
1203 target_val!(target_env, "env");
1204 target_val!(target_vendor, "vendor");
1205 target_val!(data_layout);
1206 target_val!(linker_flavor);
1208 target_option_val!(is_builtin);
1209 target_option_val!(linker);
1210 target_option_val!(lld_flavor);
1211 target_option_val!(link_args - pre_link_args);
1212 target_option_val!(link_args - pre_link_args_crt);
1213 target_option_val!(pre_link_objects_exe);
1214 target_option_val!(pre_link_objects_exe_crt);
1215 target_option_val!(pre_link_objects_dll);
1216 target_option_val!(link_args - late_link_args);
1217 target_option_val!(post_link_objects);
1218 target_option_val!(post_link_objects_crt);
1219 target_option_val!(link_args - post_link_args);
1220 target_option_val!(env - link_env);
1221 target_option_val!(asm_args);
1222 target_option_val!(cpu);
1223 target_option_val!(features);
1224 target_option_val!(dynamic_linking);
1225 target_option_val!(only_cdylib);
1226 target_option_val!(executables);
1227 target_option_val!(relocation_model);
1228 target_option_val!(code_model);
1229 target_option_val!(tls_model);
1230 target_option_val!(disable_redzone);
1231 target_option_val!(eliminate_frame_pointer);
1232 target_option_val!(function_sections);
1233 target_option_val!(dll_prefix);
1234 target_option_val!(dll_suffix);
1235 target_option_val!(exe_suffix);
1236 target_option_val!(staticlib_prefix);
1237 target_option_val!(staticlib_suffix);
1238 target_option_val!(target_family);
1239 target_option_val!(abi_return_struct_as_int);
1240 target_option_val!(is_like_osx);
1241 target_option_val!(is_like_solaris);
1242 target_option_val!(is_like_windows);
1243 target_option_val!(is_like_msvc);
1244 target_option_val!(is_like_emscripten);
1245 target_option_val!(is_like_android);
1246 target_option_val!(is_like_fuchsia);
1247 target_option_val!(linker_is_gnu);
1248 target_option_val!(allows_weak_linkage);
1249 target_option_val!(has_rpath);
1250 target_option_val!(no_default_libraries);
1251 target_option_val!(position_independent_executables);
1252 target_option_val!(needs_plt);
1253 target_option_val!(relro_level);
1254 target_option_val!(archive_format);
1255 target_option_val!(allow_asm);
1256 target_option_val!(custom_unwind_resume);
1257 target_option_val!(has_elf_tls);
1258 target_option_val!(obj_is_bitcode);
1259 target_option_val!(no_integrated_as);
1260 target_option_val!(min_atomic_width);
1261 target_option_val!(max_atomic_width);
1262 target_option_val!(atomic_cas);
1263 target_option_val!(panic_strategy);
1264 target_option_val!(crt_static_allows_dylibs);
1265 target_option_val!(crt_static_default);
1266 target_option_val!(crt_static_respected);
1267 target_option_val!(stack_probes);
1268 target_option_val!(min_global_align);
1269 target_option_val!(default_codegen_units);
1270 target_option_val!(trap_unreachable);
1271 target_option_val!(requires_lto);
1272 target_option_val!(singlethread);
1273 target_option_val!(no_builtins);
1274 target_option_val!(codegen_backend);
1275 target_option_val!(default_hidden_visibility);
1276 target_option_val!(embed_bitcode);
1277 target_option_val!(emit_debug_gdb_scripts);
1278 target_option_val!(requires_uwtable);
1279 target_option_val!(simd_types_indirect);
1280 target_option_val!(override_export_symbols);
1282 if default.abi_blacklist != self.options.abi_blacklist {
1283 d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
1284 .map(|&name| Abi::name(name).to_json())
1285 .collect::<Vec<_>>().to_json());
1292 /// Either a target triple string or a path to a JSON file.
1293 #[derive(PartialEq, Clone, Debug, Hash, RustcEncodable, RustcDecodable)]
1294 pub enum TargetTriple {
1295 TargetTriple(String),
1296 TargetPath(PathBuf),
1300 /// Creates a target triple from the passed target triple string.
1301 pub fn from_triple(triple: &str) -> Self {
1302 TargetTriple::TargetTriple(triple.to_string())
1305 /// Creates a target triple from the passed target path.
1306 pub fn from_path(path: &Path) -> Result<Self, io::Error> {
1307 let canonicalized_path = path.canonicalize()?;
1308 Ok(TargetTriple::TargetPath(canonicalized_path))
1311 /// Returns a string triple for this target.
1313 /// If this target is a path, the file name (without extension) is returned.
1314 pub fn triple(&self) -> &str {
1316 TargetTriple::TargetTriple(ref triple) => triple,
1317 TargetTriple::TargetPath(ref path) => {
1318 path.file_stem().expect("target path must not be empty").to_str()
1319 .expect("target path must be valid unicode")
1324 /// Returns an extended string triple for this target.
1326 /// If this target is a path, a hash of the path is appended to the triple returned
1328 pub fn debug_triple(&self) -> String {
1329 use std::hash::{Hash, Hasher};
1330 use std::collections::hash_map::DefaultHasher;
1332 let triple = self.triple();
1333 if let TargetTriple::TargetPath(ref path) = *self {
1334 let mut hasher = DefaultHasher::new();
1335 path.hash(&mut hasher);
1336 let hash = hasher.finish();
1337 format!("{}-{}", triple, hash)
1344 impl fmt::Display for TargetTriple {
1345 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1346 write!(f, "{}", self.debug_triple())