about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMads Marquart <mads@marquart.dk>2024-03-18 23:27:34 +0100
committerMads Marquart <mads@marquart.dk>2024-03-18 23:27:34 +0100
commitec5c8fec6c748b6eea3334637d4b6ce99e736e13 (patch)
tree55eca9edc97645807d1d57ec2a7fa79a8a83626c
parenta47d3909a7ae65ee398d4ce0822a92a59943caaf (diff)
downloadrust-ec5c8fec6c748b6eea3334637d4b6ce99e736e13.tar.gz
rust-ec5c8fec6c748b6eea3334637d4b6ce99e736e13.zip
Add test for Apple's -weak_framework linker argument
-rw-r--r--tests/run-pass-valgrind/osx-frameworks.rs21
-rw-r--r--tests/ui/linkage-attr/framework.omit.stderr8
-rw-r--r--tests/ui/linkage-attr/framework.rs30
3 files changed, 38 insertions, 21 deletions
diff --git a/tests/run-pass-valgrind/osx-frameworks.rs b/tests/run-pass-valgrind/osx-frameworks.rs
deleted file mode 100644
index 71465c0d199..00000000000
--- a/tests/run-pass-valgrind/osx-frameworks.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-//@ pretty-expanded FIXME #23616
-
-#![feature(rustc_private)]
-
-extern crate libc;
-
-#[cfg(target_os = "macos")]
-#[link(name = "CoreFoundation", kind = "framework")]
-extern "C" {
-    fn CFRunLoopGetTypeID() -> libc::c_ulong;
-}
-
-#[cfg(target_os = "macos")]
-pub fn main() {
-    unsafe {
-        CFRunLoopGetTypeID();
-    }
-}
-
-#[cfg(not(target_os = "macos"))]
-pub fn main() {}
diff --git a/tests/ui/linkage-attr/framework.omit.stderr b/tests/ui/linkage-attr/framework.omit.stderr
new file mode 100644
index 00000000000..5cb4d391437
--- /dev/null
+++ b/tests/ui/linkage-attr/framework.omit.stderr
@@ -0,0 +1,8 @@
+error: linking with `cc` failed: exit status: 1
+   |
+           ld: Undefined symbols:
+             _CFRunLoopGetTypeID, referenced from:
+           clang: error: linker command failed with exit code 1 (use -v to see invocation)
+
+
+error: aborting due to 1 previous error
diff --git a/tests/ui/linkage-attr/framework.rs b/tests/ui/linkage-attr/framework.rs
new file mode 100644
index 00000000000..662ef4c429d
--- /dev/null
+++ b/tests/ui/linkage-attr/framework.rs
@@ -0,0 +1,30 @@
+// Check that linking frameworks on Apple platforms works.
+//@ only-macos
+//@ revisions: omit link weak both
+//@ [omit]build-fail
+//@ [link]run-pass
+//@ [weak]run-pass
+//@ [both]run-pass
+
+// The linker's exact error output changes between Xcode versions.
+//@ compare-output-lines-by-subset
+//@ normalize-stderr-test: "Undefined symbols for architecture .*" -> "ld: Undefined symbols:"
+//@ normalize-stderr-test: "._CFRunLoopGetTypeID.," -> "_CFRunLoopGetTypeID,"
+
+#![cfg_attr(any(weak, both), feature(link_arg_attribute))]
+
+#[cfg_attr(any(link, both), link(name = "CoreFoundation", kind = "framework"))]
+#[cfg_attr(
+    any(weak, both),
+    link(name = "-weak_framework", kind = "link-arg", modifiers = "+verbatim"),
+    link(name = "CoreFoundation", kind = "link-arg", modifiers = "+verbatim")
+)]
+extern "C" {
+    fn CFRunLoopGetTypeID() -> core::ffi::c_ulong;
+}
+
+pub fn main() {
+    unsafe {
+        CFRunLoopGetTypeID();
+    }
+}