Skip to content

Commit 4bbedd7

Browse files
committed
fully implement lld-flavor
1 parent cafeb6f commit 4bbedd7

File tree

1 file changed

+39
-0
lines changed
  • src/librustc_target/spec

1 file changed

+39
-0
lines changed

src/librustc_target/spec/mod.rs

+39
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ pub enum LldFlavor {
9494
Link,
9595
}
9696

97+
impl LldFlavor {
98+
fn from_str(s: &str) -> Option<Self> {
99+
Some(match s {
100+
"darwin" => LldFlavor::Ld64,
101+
"gnu" => LldFlavor::Ld,
102+
"link" => LldFlavor::Link,
103+
"wasm" => LldFlavor::Wasm,
104+
_ => return None,
105+
})
106+
}
107+
}
108+
109+
impl ToJson for LldFlavor {
110+
fn to_json(&self) -> Json {
111+
match *self {
112+
LldFlavor::Ld64 => "darwin",
113+
LldFlavor::Ld => "gnu",
114+
LldFlavor::Link => "link",
115+
LldFlavor::Wasm => "wasm",
116+
}.to_json()
117+
}
118+
}
119+
97120
impl ToJson for LinkerFlavor {
98121
fn to_json(&self) -> Json {
99122
self.desc().to_json()
@@ -860,6 +883,20 @@ impl Target {
860883
.map(|s| s.to_string() );
861884
}
862885
} );
886+
($key_name:ident, LldFlavor) => ( {
887+
let name = (stringify!($key_name)).replace("_", "-");
888+
obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
889+
if let Some(flavor) = LldFlavor::from_str(&s) {
890+
base.options.$key_name = flavor;
891+
} else {
892+
return Some(Err(format!(
893+
"'{}' is not a valid value for lld-flavor. \
894+
Use 'darwin', 'gnu', 'link' or 'wasm.",
895+
s)))
896+
}
897+
Some(Ok(()))
898+
})).unwrap_or(Ok(()))
899+
} );
863900
($key_name:ident, LinkerFlavor) => ( {
864901
let name = (stringify!($key_name)).replace("_", "-");
865902
obj.find(&name[..]).and_then(|o| o.as_string().map(|s| {
@@ -915,6 +952,7 @@ impl Target {
915952

916953
key!(is_builtin, bool);
917954
key!(linker, optional);
955+
try!(key!(lld_flavor, LldFlavor));
918956
key!(pre_link_args, link_args);
919957
key!(pre_link_args_crt, link_args);
920958
key!(pre_link_objects_exe, list);
@@ -1124,6 +1162,7 @@ impl ToJson for Target {
11241162

11251163
target_option_val!(is_builtin);
11261164
target_option_val!(linker);
1165+
target_option_val!(lld_flavor);
11271166
target_option_val!(link_args - pre_link_args);
11281167
target_option_val!(link_args - pre_link_args_crt);
11291168
target_option_val!(pre_link_objects_exe);

0 commit comments

Comments
 (0)