Auto merge of #28282 - DiamondLovesYou:optional-data-layout, r=alexcrichton
NFC.
This commit is contained in:
commit
de63207d18
@ -91,7 +91,7 @@ pub struct Target {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TargetOptions {
|
||||
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
||||
pub data_layout: String,
|
||||
pub data_layout: Option<String>,
|
||||
/// Linker to invoke. Defaults to "cc".
|
||||
pub linker: String,
|
||||
/// Archive utility to use when managing archives. Defaults to "ar".
|
||||
@ -186,7 +186,7 @@ impl Default for TargetOptions {
|
||||
/// incomplete, and if used for compilation, will certainly not work.
|
||||
fn default() -> TargetOptions {
|
||||
TargetOptions {
|
||||
data_layout: String::new(),
|
||||
data_layout: None,
|
||||
linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(),
|
||||
ar: option_env!("CFG_DEFAULT_AR").unwrap_or("ar").to_string(),
|
||||
pre_link_args: Vec::new(),
|
||||
@ -287,6 +287,14 @@ impl Target {
|
||||
)
|
||||
);
|
||||
} );
|
||||
($key_name:ident, optional) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
if let Some(o) = obj.find(&name[..]) {
|
||||
base.options.$key_name = o
|
||||
.as_string()
|
||||
.map(|s| s.to_string() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
key!(cpu);
|
||||
@ -300,7 +308,7 @@ impl Target {
|
||||
key!(staticlib_prefix);
|
||||
key!(staticlib_suffix);
|
||||
key!(features);
|
||||
key!(data_layout);
|
||||
key!(data_layout, optional);
|
||||
key!(dynamic_linking, bool);
|
||||
key!(executables, bool);
|
||||
key!(disable_redzone, bool);
|
||||
|
@ -229,9 +229,8 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
|
||||
let mod_name = CString::new(mod_name).unwrap();
|
||||
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
|
||||
|
||||
let custom_data_layout = &sess.target.target.options.data_layout[..];
|
||||
if custom_data_layout.len() > 0 {
|
||||
let data_layout = CString::new(custom_data_layout).unwrap();
|
||||
if let Some(ref custom_data_layout) = sess.target.target.options.data_layout {
|
||||
let data_layout = CString::new(&custom_data_layout[..]).unwrap();
|
||||
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
|
||||
} else {
|
||||
let tm = ::back::write::create_target_machine(sess);
|
||||
|
Loading…
Reference in New Issue
Block a user