|
45 | 45 | //! settings, though `target-feature` and `link-args` will *add* to the list
|
46 | 46 | //! specified by the target, rather than replace.
|
47 | 47 |
|
48 |
| -use serialize::json::Json; |
| 48 | +use serialize::json::{Json, ToJson}; |
| 49 | +use std::collections::BTreeMap; |
49 | 50 | use std::default::Default;
|
50 | 51 | use std::io::prelude::*;
|
51 | 52 | use syntax::abi::Abi;
|
@@ -504,6 +505,80 @@ impl Target {
|
504 | 505 | }
|
505 | 506 | }
|
506 | 507 |
|
| 508 | +impl ToJson for Target { |
| 509 | + fn to_json(&self) -> Json { |
| 510 | + let mut d = BTreeMap::new(); |
| 511 | + let default: TargetOptions = Default::default(); |
| 512 | + |
| 513 | + macro_rules! target_val { |
| 514 | + ($attr:ident) => ( { |
| 515 | + let name = (stringify!($attr)).replace("_", "-"); |
| 516 | + d.insert(name.to_string(), self.$attr.to_json()); |
| 517 | + } ); |
| 518 | + ($attr:ident, $key_name:expr) => ( { |
| 519 | + let name = $key_name; |
| 520 | + d.insert(name.to_string(), self.$attr.to_json()); |
| 521 | + } ); |
| 522 | + } |
| 523 | + |
| 524 | + macro_rules! target_option_val { |
| 525 | + ($attr:ident) => ( { |
| 526 | + let name = (stringify!($attr)).replace("_", "-"); |
| 527 | + if default.$attr != self.options.$attr { |
| 528 | + d.insert(name.to_string(), self.options.$attr.to_json()); |
| 529 | + } |
| 530 | + } ); |
| 531 | + ($attr:ident, $key_name:expr) => ( { |
| 532 | + let name = $key_name; |
| 533 | + if default.$attr != self.options.$attr { |
| 534 | + d.insert(name.to_string(), self.options.$attr.to_json()); |
| 535 | + } |
| 536 | + } ); |
| 537 | + } |
| 538 | + |
| 539 | + target_val!(llvm_target); |
| 540 | + target_val!(target_endian); |
| 541 | + target_val!(target_pointer_width); |
| 542 | + target_val!(arch); |
| 543 | + target_val!(target_os, "os"); |
| 544 | + target_val!(target_env, "env"); |
| 545 | + target_val!(target_vendor, "vendor"); |
| 546 | + |
| 547 | + target_option_val!(cpu); |
| 548 | + target_option_val!(ar); |
| 549 | + target_option_val!(linker); |
| 550 | + target_option_val!(relocation_model); |
| 551 | + target_option_val!(code_model); |
| 552 | + target_option_val!(dll_prefix); |
| 553 | + target_option_val!(dll_suffix); |
| 554 | + target_option_val!(exe_suffix); |
| 555 | + target_option_val!(staticlib_prefix); |
| 556 | + target_option_val!(staticlib_suffix); |
| 557 | + target_option_val!(features); |
| 558 | + target_option_val!(data_layout); |
| 559 | + target_option_val!(dynamic_linking); |
| 560 | + target_option_val!(executables); |
| 561 | + target_option_val!(disable_redzone); |
| 562 | + target_option_val!(eliminate_frame_pointer); |
| 563 | + target_option_val!(function_sections); |
| 564 | + target_option_val!(target_family); |
| 565 | + target_option_val!(is_like_osx); |
| 566 | + target_option_val!(is_like_windows); |
| 567 | + target_option_val!(is_like_msvc); |
| 568 | + target_option_val!(linker_is_gnu); |
| 569 | + target_option_val!(has_rpath); |
| 570 | + target_option_val!(no_compiler_rt); |
| 571 | + target_option_val!(no_default_libraries); |
| 572 | + target_option_val!(pre_link_args); |
| 573 | + target_option_val!(post_link_args); |
| 574 | + target_option_val!(archive_format); |
| 575 | + target_option_val!(allow_asm); |
| 576 | + target_option_val!(custom_unwind_resume); |
| 577 | + |
| 578 | + Json::Object(d) |
| 579 | + } |
| 580 | +} |
| 581 | + |
507 | 582 | fn maybe_jemalloc() -> String {
|
508 | 583 | if cfg!(feature = "jemalloc") {
|
509 | 584 | "alloc_jemalloc".to_string()
|
|
0 commit comments