Skip to content

Commit de63207

Browse files
committed
Auto merge of #28282 - DiamondLovesYou:optional-data-layout, r=alexcrichton
NFC.
2 parents e3fd444 + cdf6ceb commit de63207

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/librustc_back/target/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct Target {
9191
#[derive(Clone, Debug)]
9292
pub struct TargetOptions {
9393
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
94-
pub data_layout: String,
94+
pub data_layout: Option<String>,
9595
/// Linker to invoke. Defaults to "cc".
9696
pub linker: String,
9797
/// Archive utility to use when managing archives. Defaults to "ar".
@@ -186,7 +186,7 @@ impl Default for TargetOptions {
186186
/// incomplete, and if used for compilation, will certainly not work.
187187
fn default() -> TargetOptions {
188188
TargetOptions {
189-
data_layout: String::new(),
189+
data_layout: None,
190190
linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(),
191191
ar: option_env!("CFG_DEFAULT_AR").unwrap_or("ar").to_string(),
192192
pre_link_args: Vec::new(),
@@ -287,6 +287,14 @@ impl Target {
287287
)
288288
);
289289
} );
290+
($key_name:ident, optional) => ( {
291+
let name = (stringify!($key_name)).replace("_", "-");
292+
if let Some(o) = obj.find(&name[..]) {
293+
base.options.$key_name = o
294+
.as_string()
295+
.map(|s| s.to_string() );
296+
}
297+
} );
290298
}
291299

292300
key!(cpu);
@@ -300,7 +308,7 @@ impl Target {
300308
key!(staticlib_prefix);
301309
key!(staticlib_suffix);
302310
key!(features);
303-
key!(data_layout);
311+
key!(data_layout, optional);
304312
key!(dynamic_linking, bool);
305313
key!(executables, bool);
306314
key!(disable_redzone, bool);

src/librustc_trans/trans/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
229229
let mod_name = CString::new(mod_name).unwrap();
230230
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
231231

232-
let custom_data_layout = &sess.target.target.options.data_layout[..];
233-
if custom_data_layout.len() > 0 {
234-
let data_layout = CString::new(custom_data_layout).unwrap();
232+
if let Some(ref custom_data_layout) = sess.target.target.options.data_layout {
233+
let data_layout = CString::new(&custom_data_layout[..]).unwrap();
235234
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
236235
} else {
237236
let tm = ::back::write::create_target_machine(sess);

0 commit comments

Comments
 (0)