diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 894afc25ef2..813d4014f88 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3000,6 +3000,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { } _ => unreachable!(), } + + if llvm_target.contains("macabi") { + // Mac Catalyst uses the macOS SDK, but to link to iOS-specific + // frameworks, we must have the support library stubs in the library + // search path. + + // The flags are called `-L` and `-F` both in Clang, ld64 and ldd. + cmd.arg(format!("-L{sdk_root}/System/iOSSupport/usr/lib")); + cmd.arg(format!("-F{sdk_root}/System/iOSSupport/System/Library/Frameworks")); + } } fn get_apple_sdk_root(sdk_name: &str) -> Result> { diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 80dd06dc7ad..e6f4accfd7b 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -790,15 +790,18 @@ pub fn line_directive<'line>( "ignore-thumb", "ignore-thumbv8m.base-none-eabi", "ignore-thumbv8m.main-none-eabi", + "ignore-tvos", "ignore-unix", "ignore-unknown", "ignore-uwp", + "ignore-visionos", "ignore-vxworks", "ignore-wasi", "ignore-wasm", "ignore-wasm32", "ignore-wasm32-bare", "ignore-wasm64", + "ignore-watchos", "ignore-windows", "ignore-windows-gnu", "ignore-x32", @@ -856,6 +859,7 @@ pub fn line_directive<'line>( "only-cdb", "only-gnu", "only-i686-pc-windows-msvc", + "only-ios", "only-linux", "only-loongarch64", "only-loongarch64-unknown-linux-gnu", @@ -871,10 +875,13 @@ pub fn line_directive<'line>( "only-sparc64", "only-stable", "only-thumb", + "only-tvos", "only-unix", + "only-visionos", "only-wasm32", "only-wasm32-bare", "only-wasm32-wasip1", + "only-watchos", "only-windows", "only-x86", "only-x86_64", diff --git a/tests/ui/linkage-attr/uikit-framework.rs b/tests/ui/linkage-attr/uikit-framework.rs new file mode 100644 index 00000000000..fca0332384a --- /dev/null +++ b/tests/ui/linkage-attr/uikit-framework.rs @@ -0,0 +1,25 @@ +//! Check that linking to UIKit on platforms where that is available works. +//@ revisions: ios tvos watchos visionos +//@ [ios]only-ios +//@ [tvos]only-tvos +//@ [watchos]only-watchos +//@ [visionos]only-visionos +//@ build-pass + +use std::ffi::{c_char, c_int, c_void}; + +#[link(name = "UIKit", kind = "framework")] +extern "C" { + pub fn UIApplicationMain( + argc: c_int, + argv: *const c_char, + principalClassName: *const c_void, + delegateClassName: *const c_void, + ) -> c_int; +} + +pub fn main() { + unsafe { + UIApplicationMain(0, core::ptr::null(), core::ptr::null(), core::ptr::null()); + } +}