Auto merge of #118644 - madsmtm:macos-weak-linking-test, r=compiler-errors
Add test for Apple's `-weak_framework` linker argument The [`-weak_framework`](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html) linker argument can sometimes be useful to reduce startup times, and to link newer frameworks while still having older deployment targets. So I made a test to ensure that it continues to work. Discussed in https://github.com/rust-lang/rust/issues/99427.
This commit is contained in:
commit
47ecded352
@ -708,6 +708,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",
|
||||
|
23
tests/run-make/link-framework/Makefile
Normal file
23
tests/run-make/link-framework/Makefile
Normal file
@ -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
|
4
tests/run-make/link-framework/dep-link-framework.rs
Normal file
4
tests/run-make/link-framework/dep-link-framework.rs
Normal file
@ -0,0 +1,4 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "CoreFoundation", kind = "framework")]
|
||||
extern "C" {}
|
6
tests/run-make/link-framework/dep-link-weak-framework.rs
Normal file
6
tests/run-make/link-framework/dep-link-weak-framework.rs
Normal file
@ -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
tests/run-make/link-framework/empty.rs
Normal file
1
tests/run-make/link-framework/empty.rs
Normal file
@ -0,0 +1 @@
|
||||
fn main() {}
|
4
tests/run-make/link-framework/link-both.rs
Normal file
4
tests/run-make/link-framework/link-both.rs
Normal file
@ -0,0 +1,4 @@
|
||||
extern crate dep_link_framework;
|
||||
extern crate dep_link_weak_framework;
|
||||
|
||||
fn main() {}
|
3
tests/run-make/link-framework/link-framework.rs
Normal file
3
tests/run-make/link-framework/link-framework.rs
Normal file
@ -0,0 +1,3 @@
|
||||
extern crate dep_link_framework;
|
||||
|
||||
fn main() {}
|
3
tests/run-make/link-framework/link-weak-framework.rs
Normal file
3
tests/run-make/link-framework/link-weak-framework.rs
Normal file
@ -0,0 +1,3 @@
|
||||
extern crate dep_link_weak_framework;
|
||||
|
||||
fn main() {}
|
@ -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() {}
|
8
tests/ui/linkage-attr/framework.omit.stderr
Normal file
8
tests/ui/linkage-attr/framework.omit.stderr
Normal file
@ -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
tests/ui/linkage-attr/framework.rs
Normal file
30
tests/ui/linkage-attr/framework.rs
Normal file
@ -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…
x
Reference in New Issue
Block a user