Skip to content

Commit 1e3e7e7

Browse files
committed
Auto merge of #29551 - arcnmx:target-family, r=alexcrichton
Allow the changing of `target_family` through flexible configuration. The whole computing world isn't just a binary of *nix and Windows! Makes porting `libstd` and co to new platforms a lot less painful.
2 parents 6dbd250 + efdf9aa commit 1e3e7e7

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/librustc/session/config.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -610,22 +610,28 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
610610
let env = &sess.target.target.target_env;
611611
let vendor = &sess.target.target.target_vendor;
612612

613-
let fam = match sess.target.target.options.is_like_windows {
614-
true => InternedString::new("windows"),
615-
false => InternedString::new("unix")
613+
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
614+
intern(fam)
615+
} else if sess.target.target.options.is_like_windows {
616+
InternedString::new("windows")
617+
} else {
618+
InternedString::new("unix")
616619
};
617620

618621
let mk = attr::mk_name_value_item_str;
619622
let mut ret = vec![ // Target bindings.
620-
attr::mk_word_item(fam.clone()),
621-
mk(InternedString::new("target_os"), intern(os)),
622-
mk(InternedString::new("target_family"), fam),
623-
mk(InternedString::new("target_arch"), intern(arch)),
624-
mk(InternedString::new("target_endian"), intern(end)),
625-
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
626-
mk(InternedString::new("target_env"), intern(env)),
627-
mk(InternedString::new("target_vendor"), intern(vendor)),
623+
mk(InternedString::new("target_os"), intern(os)),
624+
mk(InternedString::new("target_family"), fam.clone()),
625+
mk(InternedString::new("target_arch"), intern(arch)),
626+
mk(InternedString::new("target_endian"), intern(end)),
627+
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
628+
mk(InternedString::new("target_env"), intern(env)),
629+
mk(InternedString::new("target_vendor"), intern(vendor)),
628630
];
631+
match &fam[..] {
632+
"windows" | "unix" => ret.push(attr::mk_word_item(fam)),
633+
_ => (),
634+
}
629635
if sess.opts.debug_assertions {
630636
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
631637
}

src/librustc_back/target/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pub struct TargetOptions {
150150
pub staticlib_prefix: String,
151151
/// String to append to the name of every static library. Defaults to ".a".
152152
pub staticlib_suffix: String,
153+
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
154+
pub target_family: Option<String>,
153155
/// Whether the target toolchain is like OSX's. Only useful for compiling against iOS/OS X, in
154156
/// particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
155157
pub is_like_osx: bool,
@@ -219,6 +221,7 @@ impl Default for TargetOptions {
219221
exe_suffix: "".to_string(),
220222
staticlib_prefix: "lib".to_string(),
221223
staticlib_suffix: ".a".to_string(),
224+
target_family: None,
222225
is_like_osx: false,
223226
is_like_windows: false,
224227
is_like_android: false,
@@ -339,6 +342,7 @@ impl Target {
339342
key!(disable_redzone, bool);
340343
key!(eliminate_frame_pointer, bool);
341344
key!(function_sections, bool);
345+
key!(target_family, optional);
342346
key!(is_like_osx, bool);
343347
key!(is_like_windows, bool);
344348
key!(linker_is_gnu, bool);

0 commit comments

Comments
 (0)