|
1 | 1 | use std::{borrow::Cow, env};
|
2 | 2 |
|
3 |
| -use crate::spec::{cvs, DebuginfoKind, FramePointer, SplitDebuginfo, TargetOptions}; |
| 3 | +use crate::spec::{cvs, DebuginfoKind, FramePointer, SplitDebuginfo, StaticCow, TargetOptions}; |
4 | 4 | use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor};
|
5 | 5 |
|
6 | 6 | fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
|
7 |
| - let mut args = LinkArgs::new(); |
8 |
| - |
9 |
| - let platform_name = match abi { |
10 |
| - "sim" => format!("{}-simulator", os), |
11 |
| - "macabi" => "mac-catalyst".to_string(), |
12 |
| - _ => os.to_string(), |
| 7 | + let platform_name: StaticCow<str> = match abi { |
| 8 | + "sim" => format!("{}-simulator", os).into(), |
| 9 | + "macabi" => "mac-catalyst".into(), |
| 10 | + _ => os.into(), |
13 | 11 | };
|
14 | 12 |
|
15 |
| - let platform_version = match os.as_ref() { |
| 13 | + let platform_version: StaticCow<str> = match os.as_ref() { |
16 | 14 | "ios" => ios_lld_platform_version(),
|
17 | 15 | "tvos" => tvos_lld_platform_version(),
|
18 | 16 | "watchos" => watchos_lld_platform_version(),
|
19 | 17 | "macos" => macos_lld_platform_version(arch),
|
20 | 18 | _ => unreachable!(),
|
21 |
| - }; |
22 |
| - |
23 |
| - if abi != "macabi" { |
24 |
| - args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch.into()]); |
25 | 19 | }
|
| 20 | + .into(); |
26 | 21 |
|
27 |
| - args.insert( |
| 22 | + let mut args = TargetOptions::link_args( |
28 | 23 | LinkerFlavor::Lld(LldFlavor::Ld64),
|
29 |
| - vec![ |
30 |
| - "-arch".into(), |
31 |
| - arch.into(), |
32 |
| - "-platform_version".into(), |
33 |
| - platform_name.into(), |
34 |
| - platform_version.clone().into(), |
35 |
| - platform_version.into(), |
36 |
| - ], |
| 24 | + &["-arch", arch, "-platform_version"], |
37 | 25 | );
|
| 26 | + // Manually add owned args unsupported by link arg building helpers. |
| 27 | + args.entry(LinkerFlavor::Lld(LldFlavor::Ld64)).or_default().extend([ |
| 28 | + platform_name, |
| 29 | + platform_version.clone(), |
| 30 | + platform_version, |
| 31 | + ]); |
| 32 | + if abi != "macabi" { |
| 33 | + super::add_link_args(&mut args, LinkerFlavor::Gcc, &["-arch", arch]); |
| 34 | + } |
38 | 35 |
|
39 | 36 | args
|
40 | 37 | }
|
@@ -127,7 +124,7 @@ pub fn macos_llvm_target(arch: &str) -> String {
|
127 | 124 | format!("{}-apple-macosx{}.{}.0", arch, major, minor)
|
128 | 125 | }
|
129 | 126 |
|
130 |
| -pub fn macos_link_env_remove() -> Vec<Cow<'static, str>> { |
| 127 | +pub fn macos_link_env_remove() -> Vec<StaticCow<str>> { |
131 | 128 | let mut env_remove = Vec::with_capacity(2);
|
132 | 129 | // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
133 | 130 | // may occur when we're linking a custom build script while targeting iOS for example.
|
|
0 commit comments