Collapse all uses of target.options.foo
into target.foo
with an eye on merging `TargetOptions` into `Target`. `TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
This commit is contained in:
parent
87a0997ef9
commit
bf66988aa1
48 changed files with 235 additions and 260 deletions
|
@ -151,9 +151,7 @@ fn get_linker(
|
|||
Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker),
|
||||
_ => match flavor {
|
||||
LinkerFlavor::Lld(f) => Command::lld(linker, f),
|
||||
LinkerFlavor::Msvc
|
||||
if sess.opts.cg.linker.is_none() && sess.target.options.linker.is_none() =>
|
||||
{
|
||||
LinkerFlavor::Msvc if sess.opts.cg.linker.is_none() && sess.target.linker.is_none() => {
|
||||
Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker))
|
||||
}
|
||||
_ => Command::new(linker),
|
||||
|
@ -197,7 +195,7 @@ fn get_linker(
|
|||
// PATH for the child.
|
||||
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained);
|
||||
let mut msvc_changed_path = false;
|
||||
if sess.target.options.is_like_msvc {
|
||||
if sess.target.is_like_msvc {
|
||||
if let Some(ref tool) = msvc_tool {
|
||||
cmd.args(tool.args());
|
||||
for &(ref k, ref v) in tool.env() {
|
||||
|
@ -365,7 +363,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
|||
// After adding all files to the archive, we need to update the
|
||||
// symbol table of the archive. This currently dies on macOS (see
|
||||
// #11162), and isn't necessary there anyway
|
||||
if !sess.target.options.is_like_osx {
|
||||
if !sess.target.is_like_osx {
|
||||
ab.update_symbols();
|
||||
}
|
||||
}
|
||||
|
@ -476,10 +474,10 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
linker::disable_localization(&mut cmd);
|
||||
|
||||
for &(ref k, ref v) in &sess.target.options.link_env {
|
||||
for &(ref k, ref v) in &sess.target.link_env {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
for k in &sess.target.options.link_env_remove {
|
||||
for k in &sess.target.link_env_remove {
|
||||
cmd.env_remove(k);
|
||||
}
|
||||
|
||||
|
@ -515,7 +513,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// if the linker doesn't support -no-pie then it should not default to
|
||||
// linking executables as pie. Different versions of gcc seem to use
|
||||
// different quotes in the error message so don't check for them.
|
||||
if sess.target.options.linker_is_gnu
|
||||
if sess.target.linker_is_gnu
|
||||
&& flavor != LinkerFlavor::Ld
|
||||
&& (out.contains("unrecognized command line option")
|
||||
|| out.contains("unknown argument"))
|
||||
|
@ -535,7 +533,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
// Detect '-static-pie' used with an older version of gcc or clang not supporting it.
|
||||
// Fallback from '-static-pie' to '-static' in that case.
|
||||
if sess.target.options.linker_is_gnu
|
||||
if sess.target.linker_is_gnu
|
||||
&& flavor != LinkerFlavor::Ld
|
||||
&& (out.contains("unrecognized command line option")
|
||||
|| out.contains("unknown argument"))
|
||||
|
@ -548,7 +546,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
);
|
||||
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
|
||||
let self_contained = crt_objects_fallback(sess, crate_type);
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let pre_objects = if self_contained {
|
||||
&opts.pre_link_objects_fallback
|
||||
} else {
|
||||
|
@ -670,7 +668,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// is not a Microsoft LNK error then suggest a way to fix or
|
||||
// install the Visual Studio build tools.
|
||||
if let Some(code) = prog.status.code() {
|
||||
if sess.target.options.is_like_msvc
|
||||
if sess.target.is_like_msvc
|
||||
&& flavor == LinkerFlavor::Msvc
|
||||
// Respect the command line override
|
||||
&& sess.opts.cg.linker.is_none()
|
||||
|
@ -741,7 +739,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
linker_error.emit();
|
||||
|
||||
if sess.target.options.is_like_msvc && linker_not_found {
|
||||
if sess.target.is_like_msvc && linker_not_found {
|
||||
sess.note_without_error(
|
||||
"the msvc targets depend on the msvc linker \
|
||||
but `link.exe` was not found",
|
||||
|
@ -758,7 +756,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// On macOS, debuggers need this utility to get run to do some munging of
|
||||
// the symbols. Note, though, that if the object files are being preserved
|
||||
// for their debug information there's no need for us to run dsymutil.
|
||||
if sess.target.options.is_like_osx
|
||||
if sess.target.is_like_osx
|
||||
&& sess.opts.debuginfo != DebugInfo::None
|
||||
&& !preserve_objects_for_their_debuginfo(sess)
|
||||
{
|
||||
|
@ -775,9 +773,7 @@ fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linke
|
|||
// executables only.
|
||||
let needs_runtime = match crate_type {
|
||||
CrateType::Executable => true,
|
||||
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
|
||||
sess.target.options.is_like_osx
|
||||
}
|
||||
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
|
||||
CrateType::Rlib | CrateType::Staticlib => false,
|
||||
};
|
||||
|
||||
|
@ -846,7 +842,7 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
|
|||
// If our target enables builtin function lowering in LLVM then the
|
||||
// crates providing these functions don't participate in LTO (e.g.
|
||||
// no_builtins or compiler builtins crates).
|
||||
!sess.target.options.no_builtins
|
||||
!sess.target.no_builtins
|
||||
&& (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
|
||||
}
|
||||
|
||||
|
@ -906,7 +902,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
|||
} else if stem == "link" || stem == "lld-link" {
|
||||
LinkerFlavor::Msvc
|
||||
} else if stem == "lld" || stem == "rust-lld" {
|
||||
LinkerFlavor::Lld(sess.target.options.lld_flavor)
|
||||
LinkerFlavor::Lld(sess.target.lld_flavor)
|
||||
} else {
|
||||
// fall back to the value in the target spec
|
||||
sess.target.linker_flavor
|
||||
|
@ -926,7 +922,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
|||
|
||||
if let Some(ret) = infer_from(
|
||||
sess,
|
||||
sess.target.options.linker.clone().map(PathBuf::from),
|
||||
sess.target.linker.clone().map(PathBuf::from),
|
||||
Some(sess.target.linker_flavor),
|
||||
) {
|
||||
return ret;
|
||||
|
@ -962,7 +958,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
|
|||
// Basically as a result this just means that if we're on OSX and we're
|
||||
// *not* running dsymutil then the object files are the only source of truth
|
||||
// for debug information, so we must preserve them.
|
||||
if sess.target.options.is_like_osx {
|
||||
if sess.target.is_like_osx {
|
||||
return !sess.opts.debugging_opts.run_dsymutil;
|
||||
}
|
||||
|
||||
|
@ -988,7 +984,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
|
|||
NativeLibKind::StaticNoBundle
|
||||
| NativeLibKind::Dylib
|
||||
| NativeLibKind::Unspecified => {
|
||||
if sess.target.options.is_like_msvc {
|
||||
if sess.target.is_like_msvc {
|
||||
Some(format!("{}.lib", name))
|
||||
} else {
|
||||
Some(format!("-l{}", name))
|
||||
|
@ -1070,13 +1066,13 @@ fn exec_linker(
|
|||
let mut args = String::new();
|
||||
for arg in cmd2.take_args() {
|
||||
args.push_str(
|
||||
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.options.is_like_msvc }
|
||||
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.is_like_msvc }
|
||||
.to_string(),
|
||||
);
|
||||
args.push('\n');
|
||||
}
|
||||
let file = tmpdir.join("linker-arguments");
|
||||
let bytes = if sess.target.options.is_like_msvc {
|
||||
let bytes = if sess.target.is_like_msvc {
|
||||
let mut out = Vec::with_capacity((1 + args.len()) * 2);
|
||||
// start the stream with a UTF-16 BOM
|
||||
for c in std::iter::once(0xFEFF).chain(args.encode_utf16()) {
|
||||
|
@ -1192,7 +1188,7 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
|
|||
};
|
||||
|
||||
// Adjust the output kind to target capabilities.
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let pic_exe_supported = opts.position_independent_executables;
|
||||
let static_pic_exe_supported = opts.static_position_independent_executables;
|
||||
let static_dylib_supported = opts.crt_static_allows_dylibs;
|
||||
|
@ -1233,7 +1229,7 @@ fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
|
|||
return self_contained;
|
||||
}
|
||||
|
||||
match sess.target.options.crt_objects_fallback {
|
||||
match sess.target.crt_objects_fallback {
|
||||
// FIXME: Find a better heuristic for "native musl toolchain is available",
|
||||
// based on host and linker path, for example.
|
||||
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
|
||||
|
@ -1256,7 +1252,7 @@ fn add_pre_link_objects(
|
|||
link_output_kind: LinkOutputKind,
|
||||
self_contained: bool,
|
||||
) {
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let objects =
|
||||
if self_contained { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
|
||||
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
|
||||
|
@ -1271,7 +1267,7 @@ fn add_post_link_objects(
|
|||
link_output_kind: LinkOutputKind,
|
||||
self_contained: bool,
|
||||
) {
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let objects =
|
||||
if self_contained { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
|
||||
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
|
||||
|
@ -1282,7 +1278,7 @@ fn add_post_link_objects(
|
|||
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
|
||||
/// FIXME: Determine where exactly these args need to be inserted.
|
||||
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||
if let Some(args) = sess.target.options.pre_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.pre_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
cmd.args(&sess.opts.debugging_opts.pre_link_args);
|
||||
|
@ -1290,9 +1286,9 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor)
|
|||
|
||||
/// Add a link script embedded in the target, if applicable.
|
||||
fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_type: CrateType) {
|
||||
match (crate_type, &sess.target.options.link_script) {
|
||||
match (crate_type, &sess.target.link_script) {
|
||||
(CrateType::Cdylib | CrateType::Executable, Some(script)) => {
|
||||
if !sess.target.options.linker_is_gnu {
|
||||
if !sess.target.linker_is_gnu {
|
||||
sess.fatal("can only use link script when linking with GNU-like linker");
|
||||
}
|
||||
|
||||
|
@ -1335,15 +1331,15 @@ fn add_late_link_args(
|
|||
*ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic)
|
||||
});
|
||||
if any_dynamic_crate {
|
||||
if let Some(args) = sess.target.options.late_link_args_dynamic.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
} else {
|
||||
if let Some(args) = sess.target.options.late_link_args_static.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
if let Some(args) = sess.target.options.late_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
|
@ -1351,7 +1347,7 @@ fn add_late_link_args(
|
|||
/// Add arbitrary "post-link" args defined by the target spec.
|
||||
/// FIXME: Determine where exactly these args need to be inserted.
|
||||
fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||
if let Some(args) = sess.target.options.post_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.post_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
|
@ -1453,7 +1449,7 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained:
|
|||
/// Add options making relocation sections in the produced ELF files read-only
|
||||
/// and suppressing lazy binding.
|
||||
fn add_relro_args(cmd: &mut dyn Linker, sess: &Session) {
|
||||
match sess.opts.debugging_opts.relro_level.unwrap_or(sess.target.options.relro_level) {
|
||||
match sess.opts.debugging_opts.relro_level.unwrap_or(sess.target.relro_level) {
|
||||
RelroLevel::Full => cmd.full_relro(),
|
||||
RelroLevel::Partial => cmd.partial_relro(),
|
||||
RelroLevel::Off => cmd.no_relro(),
|
||||
|
@ -1484,9 +1480,9 @@ fn add_rpath_args(
|
|||
let mut rpath_config = RPathConfig {
|
||||
used_crates: &codegen_results.crate_info.used_crates_dynamic,
|
||||
out_filename: out_filename.to_path_buf(),
|
||||
has_rpath: sess.target.options.has_rpath,
|
||||
is_like_osx: sess.target.options.is_like_osx,
|
||||
linker_is_gnu: sess.target.options.linker_is_gnu,
|
||||
has_rpath: sess.target.has_rpath,
|
||||
is_like_osx: sess.target.is_like_osx,
|
||||
linker_is_gnu: sess.target.linker_is_gnu,
|
||||
get_install_prefix_lib_path: &mut get_install_prefix_lib_path,
|
||||
};
|
||||
cmd.args(&rpath::get_rpath_flags(&mut rpath_config));
|
||||
|
@ -1528,7 +1524,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
add_link_script(cmd, sess, tmpdir, crate_type);
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.is_like_fuchsia && crate_type == CrateType::Executable {
|
||||
if sess.target.is_like_fuchsia && crate_type == CrateType::Executable {
|
||||
let prefix = if sess.opts.debugging_opts.sanitizer.contains(SanitizerSet::ADDRESS) {
|
||||
"asan/"
|
||||
} else {
|
||||
|
@ -1538,7 +1534,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
}
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.eh_frame_header {
|
||||
if sess.target.eh_frame_header {
|
||||
cmd.add_eh_frame_header();
|
||||
}
|
||||
|
||||
|
@ -1551,7 +1547,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
add_pre_link_objects(cmd, sess, link_output_kind, crt_objects_fallback);
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.is_like_emscripten {
|
||||
if sess.target.is_like_emscripten {
|
||||
cmd.arg("-s");
|
||||
cmd.arg(if sess.panic_strategy() == PanicStrategy::Abort {
|
||||
"DISABLE_EXCEPTION_CATCHING=1"
|
||||
|
@ -1579,7 +1575,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
cmd.output_filename(out_filename);
|
||||
|
||||
// OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if crate_type == CrateType::Executable && sess.target.options.is_like_windows {
|
||||
if crate_type == CrateType::Executable && sess.target.is_like_windows {
|
||||
if let Some(ref s) = codegen_results.windows_subsystem {
|
||||
cmd.subsystem(s);
|
||||
}
|
||||
|
@ -1623,7 +1619,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
// OBJECT-FILES-NO, AUDIT-ORDER
|
||||
// We want to prevent the compiler from accidentally leaking in any system libraries,
|
||||
// so by default we tell linkers not to link to any default libraries.
|
||||
if !sess.opts.cg.default_linker_libraries && sess.target.options.no_default_libraries {
|
||||
if !sess.opts.cg.default_linker_libraries && sess.target.no_default_libraries {
|
||||
cmd.no_default_libraries();
|
||||
}
|
||||
|
||||
|
@ -1843,7 +1839,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
// Converts a library file-stem into a cc -l argument
|
||||
fn unlib<'a>(target: &Target, stem: &'a str) -> &'a str {
|
||||
if stem.starts_with("lib") && !target.options.is_like_windows { &stem[3..] } else { stem }
|
||||
if stem.starts_with("lib") && !target.is_like_windows { &stem[3..] } else { stem }
|
||||
}
|
||||
|
||||
// Adds the static "rlib" versions of all crates to the command line.
|
||||
|
@ -1938,7 +1934,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
// though, so we let that object file slide.
|
||||
let skip_because_lto = are_upstream_rust_objects_already_included(sess)
|
||||
&& is_rust_object
|
||||
&& (sess.target.options.no_builtins
|
||||
&& (sess.target.no_builtins
|
||||
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum));
|
||||
|
||||
if skip_because_cfg_say_so || skip_because_lto {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue