Skip to content

Commit 9782770

Browse files
committed
Auto merge of rust-lang#121430 - madsmtm:mac-catalyst-iOSSupport, r=wesleywiser
Add `/System/iOSSupport` to the library search path on Mac Catalyst On macOS, `/System/iOSSupport` contains iOS frameworks like UIKit, which is the whole idea of Mac Catalyst. To link to these, we need to explicitly tell the linker about the support library stubs provided in the macOS SDK under the same path. Concretely, when building a binary for Mac Catalyst, Xcode passes the following flags to the linker: ``` -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/System/iOSSupport/System/Library/Frameworks -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/System/iOSSupport/usr/lib ``` This is not something that can be disabled (it's enabled as soon as you enable `SUPPORTS_MACCATALYST`), so I think it's pretty safe to say that we don't need an option to turn these off. I've chosen to slightly deviate from what Xcode does and use `-F` instead of `-iframework`, since we don't need to change the header search path, and this way the flags nicely match on all the linkers. From what I could tell by reading Clang sources, there shouldn't be a difference when just running the linker. CC `@BlackHoleFox,` `@shepmaster` (I accidentally let rustbot choose the reviewer).
2 parents 7942405 + ff3f0a3 commit 9782770

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
30003000
}
30013001
_ => unreachable!(),
30023002
}
3003+
3004+
if llvm_target.contains("macabi") {
3005+
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific
3006+
// frameworks, we must have the support library stubs in the library
3007+
// search path.
3008+
3009+
// The flags are called `-L` and `-F` both in Clang, ld64 and ldd.
3010+
cmd.arg(format!("-L{sdk_root}/System/iOSSupport/usr/lib"));
3011+
cmd.arg(format!("-F{sdk_root}/System/iOSSupport/System/Library/Frameworks"));
3012+
}
30033013
}
30043014

30053015
fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootError<'_>> {

Diff for: src/tools/compiletest/src/header.rs

+7
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,18 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
790790
"ignore-thumb",
791791
"ignore-thumbv8m.base-none-eabi",
792792
"ignore-thumbv8m.main-none-eabi",
793+
"ignore-tvos",
793794
"ignore-unix",
794795
"ignore-unknown",
795796
"ignore-uwp",
797+
"ignore-visionos",
796798
"ignore-vxworks",
797799
"ignore-wasi",
798800
"ignore-wasm",
799801
"ignore-wasm32",
800802
"ignore-wasm32-bare",
801803
"ignore-wasm64",
804+
"ignore-watchos",
802805
"ignore-windows",
803806
"ignore-windows-gnu",
804807
"ignore-x32",
@@ -856,6 +859,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
856859
"only-cdb",
857860
"only-gnu",
858861
"only-i686-pc-windows-msvc",
862+
"only-ios",
859863
"only-linux",
860864
"only-loongarch64",
861865
"only-loongarch64-unknown-linux-gnu",
@@ -871,10 +875,13 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
871875
"only-sparc64",
872876
"only-stable",
873877
"only-thumb",
878+
"only-tvos",
874879
"only-unix",
880+
"only-visionos",
875881
"only-wasm32",
876882
"only-wasm32-bare",
877883
"only-wasm32-wasip1",
884+
"only-watchos",
878885
"only-windows",
879886
"only-x86",
880887
"only-x86_64",

Diff for: tests/ui/linkage-attr/uikit-framework.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Check that linking to UIKit on platforms where that is available works.
2+
//@ revisions: ios tvos watchos visionos
3+
//@ [ios]only-ios
4+
//@ [tvos]only-tvos
5+
//@ [watchos]only-watchos
6+
//@ [visionos]only-visionos
7+
//@ build-pass
8+
9+
use std::ffi::{c_char, c_int, c_void};
10+
11+
#[link(name = "UIKit", kind = "framework")]
12+
extern "C" {
13+
pub fn UIApplicationMain(
14+
argc: c_int,
15+
argv: *const c_char,
16+
principalClassName: *const c_void,
17+
delegateClassName: *const c_void,
18+
) -> c_int;
19+
}
20+
21+
pub fn main() {
22+
unsafe {
23+
UIApplicationMain(0, core::ptr::null(), core::ptr::null(), core::ptr::null());
24+
}
25+
}

0 commit comments

Comments
 (0)