Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /System/iOSSupport to the library search path on Mac Catalyst #121430

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,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<String, errors::AppleSdkRootError<'_>> {
Expand Down
7 changes: 7 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,18 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"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",
Expand Down Expand Up @@ -856,6 +859,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"only-cdb",
"only-gnu",
"only-i686-pc-windows-msvc",
"only-ios",
"only-linux",
"only-loongarch64",
"only-loongarch64-unknown-linux-gnu",
Expand All @@ -871,10 +875,13 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"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",
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/linkage-attr/uikit-framework.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading