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 test for Apple's -weak_framework linker argument #118644

Merged
merged 3 commits into from
Mar 26, 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
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions tests/run-make/link-framework/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# only-macos
Copy link
Member

@jieyouxu jieyouxu Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Since this seems like a new run-make test) Does this test need to be written in Makefile? Can it be written in rmake.rs?

Copy link
Contributor Author

@madsmtm madsmtm Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably could - didn't know about rmake.rs, I think I made this PR before that was available

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the timing was a bit unfortunate, but that's okay, we added a tidy check now

#
# 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
4 changes: 4 additions & 0 deletions tests/run-make/link-framework/dep-link-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_type = "rlib"]

#[link(name = "CoreFoundation", kind = "framework")]
extern "C" {}
6 changes: 6 additions & 0 deletions tests/run-make/link-framework/dep-link-weak-framework.rs
Original file line number Diff line number Diff line change
@@ -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" {}
1 change: 1 addition & 0 deletions tests/run-make/link-framework/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
4 changes: 4 additions & 0 deletions tests/run-make/link-framework/link-both.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extern crate dep_link_framework;
extern crate dep_link_weak_framework;

fn main() {}
3 changes: 3 additions & 0 deletions tests/run-make/link-framework/link-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate dep_link_framework;

fn main() {}
3 changes: 3 additions & 0 deletions tests/run-make/link-framework/link-weak-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate dep_link_weak_framework;

fn main() {}
21 changes: 0 additions & 21 deletions tests/run-pass-valgrind/osx-frameworks.rs

This file was deleted.

8 changes: 8 additions & 0 deletions tests/ui/linkage-attr/framework.omit.stderr
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions tests/ui/linkage-attr/framework.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading