Skip to content

Commit

Permalink
port tests/ui/linkage-attr/framework to run-make
Browse files Browse the repository at this point in the history
this makes it much easier to understand test failures.

before:
```
diff of stderr:

1 error: linking with `LINKER` failed: exit status: 1
2    |
-            ld: Undefined symbols:
4              _CFRunLoopGetTypeID, referenced from:
5            clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

after:
```
=== HAYSTACK ===
error: linking with `cc` failed: exit status: 1
  |
  = note: use `--verbose` to show all linker arguments
  = note: Undefined symbols for architecture arm64:
            "_CFRunLoopGetTypeID", referenced from:
                main::main::hbb553f5dda62d3ea in main.main.d17f5fbe6225cf88-cgu.0.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to 1 previous error

=== NEEDLE ===
_CFRunLoopGetTypeID\.?, referenced from:
thread 'main' panicked at /Users/jyn/git/rust-lang/rust/tests/run-make/linkage-attr-framework/rmake.rs:22:10:
needle was not found in haystack
```

this also fixes a failure related to missing whitespace; we don't actually care about whitespace in this test.
  • Loading branch information
jyn514 committed Sep 24, 2024
1 parent cc941ad commit 8cdebfe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
17 changes: 17 additions & 0 deletions tests/run-make/linkage-attr-framework/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![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;
}

fn main() {
unsafe {
CFRunLoopGetTypeID();
}
}
27 changes: 27 additions & 0 deletions tests/run-make/linkage-attr-framework/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Check that linking frameworks on Apple platforms works.

//@ only-apple

use run_make_support::{rustc, run, Rustc};

fn compile(cfg: &str) -> Rustc {
let mut rustc = rustc();
rustc.cfg(cfg).input("main.rs");
rustc
}

fn main() {
for cfg in ["link", "weak", "both"] {
compile(cfg).run();
run("main");
}

let errs = compile("omit").run_fail();
// The linker's exact error output changes between Xcode versions, depends on
// linker invocation details, and the linker sometimes outputs more warnings.
errs.assert_stderr_contains_regex(r"error: linking with `.*` failed");
errs.assert_stderr_contains_regex(r"(Undefined symbols|ld: symbol[^\s]* not found)");
errs.assert_stderr_contains_regex(r".?_CFRunLoopGetTypeID.?, referenced from:");
errs.assert_stderr_contains("clang: error: linker command failed with exit code 1");
}

8 changes: 0 additions & 8 deletions tests/ui/linkage-attr/framework.omit.stderr

This file was deleted.

32 changes: 0 additions & 32 deletions tests/ui/linkage-attr/framework.rs

This file was deleted.

0 comments on commit 8cdebfe

Please sign in to comment.