rustc_target: Use Cow
and link args helpers in apple_base
This commit is contained in:
parent
f0d0573db1
commit
f4b5954764
2 changed files with 20 additions and 23 deletions
|
@ -1,40 +1,37 @@
|
||||||
use std::{borrow::Cow, env};
|
use std::{borrow::Cow, env};
|
||||||
|
|
||||||
use crate::spec::{cvs, DebuginfoKind, FramePointer, SplitDebuginfo, TargetOptions};
|
use crate::spec::{cvs, DebuginfoKind, FramePointer, SplitDebuginfo, StaticCow, TargetOptions};
|
||||||
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor};
|
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor};
|
||||||
|
|
||||||
fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
|
fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
|
||||||
let mut args = LinkArgs::new();
|
let platform_name: StaticCow<str> = match abi {
|
||||||
|
"sim" => format!("{}-simulator", os).into(),
|
||||||
let platform_name = match abi {
|
"macabi" => "mac-catalyst".into(),
|
||||||
"sim" => format!("{}-simulator", os),
|
_ => os.into(),
|
||||||
"macabi" => "mac-catalyst".to_string(),
|
|
||||||
_ => os.to_string(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let platform_version = match os.as_ref() {
|
let platform_version: StaticCow<str> = match os.as_ref() {
|
||||||
"ios" => ios_lld_platform_version(),
|
"ios" => ios_lld_platform_version(),
|
||||||
"tvos" => tvos_lld_platform_version(),
|
"tvos" => tvos_lld_platform_version(),
|
||||||
"watchos" => watchos_lld_platform_version(),
|
"watchos" => watchos_lld_platform_version(),
|
||||||
"macos" => macos_lld_platform_version(arch),
|
"macos" => macos_lld_platform_version(arch),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
|
||||||
|
|
||||||
if abi != "macabi" {
|
|
||||||
args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch.into()]);
|
|
||||||
}
|
}
|
||||||
|
.into();
|
||||||
|
|
||||||
args.insert(
|
let mut args = TargetOptions::link_args(
|
||||||
LinkerFlavor::Lld(LldFlavor::Ld64),
|
LinkerFlavor::Lld(LldFlavor::Ld64),
|
||||||
vec![
|
&["-arch", arch, "-platform_version"],
|
||||||
"-arch".into(),
|
|
||||||
arch.into(),
|
|
||||||
"-platform_version".into(),
|
|
||||||
platform_name.into(),
|
|
||||||
platform_version.clone().into(),
|
|
||||||
platform_version.into(),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
// Manually add owned args unsupported by link arg building helpers.
|
||||||
|
args.entry(LinkerFlavor::Lld(LldFlavor::Ld64)).or_default().extend([
|
||||||
|
platform_name,
|
||||||
|
platform_version.clone(),
|
||||||
|
platform_version,
|
||||||
|
]);
|
||||||
|
if abi != "macabi" {
|
||||||
|
super::add_link_args(&mut args, LinkerFlavor::Gcc, &["-arch", arch]);
|
||||||
|
}
|
||||||
|
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
|
@ -127,7 +124,7 @@ pub fn macos_llvm_target(arch: &str) -> String {
|
||||||
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
|
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macos_link_env_remove() -> Vec<Cow<'static, str>> {
|
pub fn macos_link_env_remove() -> Vec<StaticCow<str>> {
|
||||||
let mut env_remove = Vec::with_capacity(2);
|
let mut env_remove = Vec::with_capacity(2);
|
||||||
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
||||||
// may occur when we're linking a custom build script while targeting iOS for example.
|
// may occur when we're linking a custom build script while targeting iOS for example.
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ fn add_link_args(link_args: &mut LinkArgs, flavor: LinkerFlavor, args: &[&'stati
|
||||||
match flavor {
|
match flavor {
|
||||||
LinkerFlavor::Ld => insert(LinkerFlavor::Lld(LldFlavor::Ld)),
|
LinkerFlavor::Ld => insert(LinkerFlavor::Lld(LldFlavor::Ld)),
|
||||||
LinkerFlavor::Msvc => insert(LinkerFlavor::Lld(LldFlavor::Link)),
|
LinkerFlavor::Msvc => insert(LinkerFlavor::Lld(LldFlavor::Link)),
|
||||||
LinkerFlavor::Lld(LldFlavor::Wasm) => {}
|
LinkerFlavor::Lld(LldFlavor::Ld64) | LinkerFlavor::Lld(LldFlavor::Wasm) => {}
|
||||||
LinkerFlavor::Lld(lld_flavor) => {
|
LinkerFlavor::Lld(lld_flavor) => {
|
||||||
panic!("add_link_args: use non-LLD flavor for {:?}", lld_flavor)
|
panic!("add_link_args: use non-LLD flavor for {:?}", lld_flavor)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue