From a47d3909a7ae65ee398d4ce0822a92a59943caaf Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 13 Mar 2024 10:59:07 +0100 Subject: [PATCH 1/3] Add compare-output-lines-by-subset to compiletest KNOWN_DIRECTIVE_NAMES --- src/tools/compiletest/src/header.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 69658222ff3eb..3ee315edc51b5 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -693,6 +693,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "check-run-results", "check-stdout", "check-test-line-numbers-match", + "compare-output-lines-by-subset", "compile-flags", "dont-check-compiler-stderr", "dont-check-compiler-stdout", From ec5c8fec6c748b6eea3334637d4b6ce99e736e13 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 18 Mar 2024 23:27:34 +0100 Subject: [PATCH 2/3] Add test for Apple's -weak_framework linker argument --- tests/run-pass-valgrind/osx-frameworks.rs | 21 --------------- tests/ui/linkage-attr/framework.omit.stderr | 8 ++++++ tests/ui/linkage-attr/framework.rs | 30 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 21 deletions(-) delete mode 100644 tests/run-pass-valgrind/osx-frameworks.rs create mode 100644 tests/ui/linkage-attr/framework.omit.stderr create mode 100644 tests/ui/linkage-attr/framework.rs diff --git a/tests/run-pass-valgrind/osx-frameworks.rs b/tests/run-pass-valgrind/osx-frameworks.rs deleted file mode 100644 index 71465c0d1997d..0000000000000 --- 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 0000000000000..5cb4d3914371c --- /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 0000000000000..662ef4c429ddd --- /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(); + } +} From 440fce19a1d412d560a13cfe1d98351e16703468 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 12 Dec 2023 05:56:07 +0100 Subject: [PATCH 3/3] Ensure using `otool` that framework linking actually happened --- tests/run-make/link-framework/Makefile | 23 +++++++++++++++++++ .../link-framework/dep-link-framework.rs | 4 ++++ .../link-framework/dep-link-weak-framework.rs | 6 +++++ tests/run-make/link-framework/empty.rs | 1 + tests/run-make/link-framework/link-both.rs | 4 ++++ .../run-make/link-framework/link-framework.rs | 3 +++ .../link-framework/link-weak-framework.rs | 3 +++ 7 files changed, 44 insertions(+) create mode 100644 tests/run-make/link-framework/Makefile create mode 100644 tests/run-make/link-framework/dep-link-framework.rs create mode 100644 tests/run-make/link-framework/dep-link-weak-framework.rs create mode 100644 tests/run-make/link-framework/empty.rs create mode 100644 tests/run-make/link-framework/link-both.rs create mode 100644 tests/run-make/link-framework/link-framework.rs create mode 100644 tests/run-make/link-framework/link-weak-framework.rs diff --git a/tests/run-make/link-framework/Makefile b/tests/run-make/link-framework/Makefile new file mode 100644 index 0000000000000..f33347ac7f8f5 --- /dev/null +++ b/tests/run-make/link-framework/Makefile @@ -0,0 +1,23 @@ +# only-macos +# +# Check that linking to a framework actually makes it to the linker. + +include ../tools.mk + +all: + $(RUSTC) dep-link-framework.rs + $(RUSTC) dep-link-weak-framework.rs + + $(RUSTC) empty.rs + otool -L $(TMPDIR)/no-link | $(CGREP) -v CoreFoundation + + $(RUSTC) link-framework.rs + otool -L $(TMPDIR)/link-framework | $(CGREP) CoreFoundation | $(CGREP) -v weak + + $(RUSTC) link-weak-framework.rs + otool -L $(TMPDIR)/link-weak-framework | $(CGREP) CoreFoundation | $(CGREP) weak + +# When linking the framework both normally, and weakly, the weak linking takes preference + + $(RUSTC) link-both.rs + otool -L $(TMPDIR)/link-both | $(CGREP) CoreFoundation | $(CGREP) weak diff --git a/tests/run-make/link-framework/dep-link-framework.rs b/tests/run-make/link-framework/dep-link-framework.rs new file mode 100644 index 0000000000000..9bdeb2052d255 --- /dev/null +++ b/tests/run-make/link-framework/dep-link-framework.rs @@ -0,0 +1,4 @@ +#![crate_type = "rlib"] + +#[link(name = "CoreFoundation", kind = "framework")] +extern "C" {} diff --git a/tests/run-make/link-framework/dep-link-weak-framework.rs b/tests/run-make/link-framework/dep-link-weak-framework.rs new file mode 100644 index 0000000000000..d3e1cf9c98f5f --- /dev/null +++ b/tests/run-make/link-framework/dep-link-weak-framework.rs @@ -0,0 +1,6 @@ +#![crate_type = "rlib"] +#![feature(link_arg_attribute)] + +#[link(name = "-weak_framework", kind = "link-arg", modifiers = "+verbatim")] +#[link(name = "CoreFoundation", kind = "link-arg", modifiers = "+verbatim")] +extern "C" {} diff --git a/tests/run-make/link-framework/empty.rs b/tests/run-make/link-framework/empty.rs new file mode 100644 index 0000000000000..f328e4d9d04c3 --- /dev/null +++ b/tests/run-make/link-framework/empty.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/link-framework/link-both.rs b/tests/run-make/link-framework/link-both.rs new file mode 100644 index 0000000000000..31fc79e1929ac --- /dev/null +++ b/tests/run-make/link-framework/link-both.rs @@ -0,0 +1,4 @@ +extern crate dep_link_framework; +extern crate dep_link_weak_framework; + +fn main() {} diff --git a/tests/run-make/link-framework/link-framework.rs b/tests/run-make/link-framework/link-framework.rs new file mode 100644 index 0000000000000..e33e830248ebe --- /dev/null +++ b/tests/run-make/link-framework/link-framework.rs @@ -0,0 +1,3 @@ +extern crate dep_link_framework; + +fn main() {} diff --git a/tests/run-make/link-framework/link-weak-framework.rs b/tests/run-make/link-framework/link-weak-framework.rs new file mode 100644 index 0000000000000..f0557f8013a43 --- /dev/null +++ b/tests/run-make/link-framework/link-weak-framework.rs @@ -0,0 +1,3 @@ +extern crate dep_link_weak_framework; + +fn main() {}