Skip to content

Commit 4afea69

Browse files
committed
Allow setting target_family to multiple values
This enables us to set more generic labels shared between targets. For example `target_family="wasm"` across all targets that are conceptually "wasm". See rust-lang/reference#1006
1 parent 72c63de commit 4afea69

18 files changed

+36
-30
lines changed

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
813813
ret.reserve(6); // the minimum number of insertions
814814
// Target bindings.
815815
ret.insert((sym::target_os, Some(Symbol::intern(os))));
816-
if let Some(ref fam) = sess.target.os_family {
816+
for fam in &sess.target.families {
817817
ret.insert((sym::target_family, Some(Symbol::intern(fam))));
818818
if fam == "windows" {
819819
ret.insert((sym::windows, None));

compiler/rustc_target/src/spec/apple_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn opts(os: &str) -> TargetOptions {
2323
function_sections: false,
2424
dynamic_linking: true,
2525
executables: true,
26-
os_family: Some("unix".to_string()),
26+
families: vec!["unix".to_string()],
2727
is_like_osx: true,
2828
dwarf_version: Some(2),
2929
has_rpath: true,

compiler/rustc_target/src/spec/dragonfly_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "dragonfly".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/freebsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "freebsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/fuchsia_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn opts() -> TargetOptions {
2525
linker: Some("rust-lld".to_owned()),
2626
dynamic_linking: true,
2727
executables: true,
28-
os_family: Some("unix".to_string()),
28+
families: vec!["unix".to_string()],
2929
is_like_fuchsia: true,
3030
linker_is_gnu: true,
3131
pre_link_args,

compiler/rustc_target/src/spec/haiku_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "haiku".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
relro_level: RelroLevel::Full,
1010
linker_is_gnu: true,
1111
..Default::default()

compiler/rustc_target/src/spec/illumos_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions {
2020
dynamic_linking: true,
2121
executables: true,
2222
has_rpath: true,
23-
os_family: Some("unix".to_string()),
23+
families: vec!["unix".to_string()],
2424
is_like_solaris: true,
2525
limit_rdylib_exports: false, // Linker doesn't support this
2626
eliminate_frame_pointer: false,

compiler/rustc_target/src/spec/l4re_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions {
2020
executables: true,
2121
panic_strategy: PanicStrategy::Abort,
2222
linker: Some("ld".to_string()),
23-
os_family: Some("unix".to_string()),
23+
families: vec!["unix".to_string()],
2424
..Default::default()
2525
}
2626
}

compiler/rustc_target/src/spec/linux_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "linux".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,12 @@ pub struct TargetOptions {
10421042
pub staticlib_prefix: String,
10431043
/// String to append to the name of every static library. Defaults to ".a".
10441044
pub staticlib_suffix: String,
1045-
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
1046-
pub os_family: Option<String>,
1045+
/// Values of the `target_family` cfg set for this target.
1046+
///
1047+
/// Common options are: "unix", "windows". Defaults to no families.
1048+
///
1049+
/// See https://doc.rust-lang.org/reference/conditional-compilation.html#target_family
1050+
pub families: Vec<String>,
10471051
/// Whether the target toolchain's ABI supports returning small structs as an integer.
10481052
pub abi_return_struct_as_int: bool,
10491053
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
@@ -1293,7 +1297,7 @@ impl Default for TargetOptions {
12931297
exe_suffix: String::new(),
12941298
staticlib_prefix: "lib".to_string(),
12951299
staticlib_suffix: ".a".to_string(),
1296-
os_family: None,
1300+
families: Vec::new(),
12971301
abi_return_struct_as_int: false,
12981302
is_like_osx: false,
12991303
is_like_solaris: false,
@@ -1605,14 +1609,6 @@ impl Target {
16051609
.map(|s| s.to_string() );
16061610
}
16071611
} );
1608-
($key_name:ident = $json_name:expr, optional) => ( {
1609-
let name = $json_name;
1610-
if let Some(o) = obj.find(name) {
1611-
base.$key_name = o
1612-
.as_string()
1613-
.map(|s| s.to_string() );
1614-
}
1615-
} );
16161612
($key_name:ident, LldFlavor) => ( {
16171613
let name = (stringify!($key_name)).replace("_", "-");
16181614
obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
@@ -1759,6 +1755,16 @@ impl Target {
17591755
Some(Ok(()))
17601756
})).unwrap_or(Ok(()))
17611757
} );
1758+
($key_name:ident, TargetFamilies) => ( {
1759+
let value = obj.find("target-family");
1760+
if let Some(v) = value.and_then(Json::as_array) {
1761+
base.$key_name = v.iter()
1762+
.map(|a| a.as_string().unwrap().to_string())
1763+
.collect();
1764+
} else if let Some(v) = value.and_then(Json::as_string) {
1765+
base.$key_name = vec![v.to_string()];
1766+
}
1767+
} );
17621768
}
17631769

17641770
if let Some(s) = obj.find("target-endian").and_then(Json::as_string) {
@@ -1802,7 +1808,7 @@ impl Target {
18021808
key!(exe_suffix);
18031809
key!(staticlib_prefix);
18041810
key!(staticlib_suffix);
1805-
key!(os_family = "target-family", optional);
1811+
key!(families, TargetFamilies);
18061812
key!(abi_return_struct_as_int, bool);
18071813
key!(is_like_osx, bool);
18081814
key!(is_like_solaris, bool);
@@ -2042,7 +2048,7 @@ impl ToJson for Target {
20422048
target_option_val!(exe_suffix);
20432049
target_option_val!(staticlib_prefix);
20442050
target_option_val!(staticlib_suffix);
2045-
target_option_val!(os_family, "target-family");
2051+
target_option_val!(families, "target-family");
20462052
target_option_val!(abi_return_struct_as_int);
20472053
target_option_val!(is_like_osx);
20482054
target_option_val!(is_like_solaris);

compiler/rustc_target/src/spec/netbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "netbsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
no_default_libraries: false,
1111
has_rpath: true,

compiler/rustc_target/src/spec/openbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "openbsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
abi_return_struct_as_int: true,

compiler/rustc_target/src/spec/redox_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions {
66
env: "relibc".to_string(),
77
dynamic_linking: true,
88
executables: true,
9-
os_family: Some("unix".to_string()),
9+
families: vec!["unix".to_string()],
1010
linker_is_gnu: true,
1111
has_rpath: true,
1212
position_independent_executables: true,

compiler/rustc_target/src/spec/solaris_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
has_rpath: true,
9-
os_family: Some("unix".to_string()),
9+
families: vec!["unix".to_string()],
1010
is_like_solaris: true,
1111
limit_rdylib_exports: false, // Linker doesn't support this
1212
eh_frame_header: false,

compiler/rustc_target/src/spec/vxworks_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions {
99
exe_suffix: ".vxe".to_string(),
1010
dynamic_linking: true,
1111
executables: true,
12-
os_family: Some("unix".to_string()),
12+
families: vec!["unix".to_string()],
1313
linker_is_gnu: true,
1414
has_rpath: true,
1515
has_elf_tls: true,

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn target() -> Target {
3838
is_like_emscripten: true,
3939
panic_strategy: PanicStrategy::Unwind,
4040
post_link_args,
41-
os_family: Some("unix".to_string()),
41+
families: vec!["unix".to_string()],
4242
..options
4343
};
4444
Target {

compiler/rustc_target/src/spec/windows_gnu_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn opts() -> TargetOptions {
7171
dll_prefix: String::new(),
7272
dll_suffix: ".dll".to_string(),
7373
exe_suffix: ".exe".to_string(),
74-
os_family: Some("windows".to_string()),
74+
families: vec!["windows".to_string()],
7575
is_like_windows: true,
7676
allows_weak_linkage: false,
7777
pre_link_args,

compiler/rustc_target/src/spec/windows_msvc_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn opts() -> TargetOptions {
1313
exe_suffix: ".exe".to_string(),
1414
staticlib_prefix: String::new(),
1515
staticlib_suffix: ".lib".to_string(),
16-
os_family: Some("windows".to_string()),
16+
families: vec!["windows".to_string()],
1717
crt_static_allows_dylibs: true,
1818
crt_static_respected: true,
1919
requires_uwtable: true,

0 commit comments

Comments
 (0)