diff options
| author | Mads Marquart <mads@marquart.dk> | 2025-03-25 16:12:56 +0100 |
|---|---|---|
| committer | Mads Marquart <mads@marquart.dk> | 2025-09-05 16:18:49 +0200 |
| commit | 846d6a4466813f3ad12e2bf15db4071f22b8ae0b (patch) | |
| tree | f06e74b18ebd1d63a72f14b563c261189db97ac8 /tests | |
| parent | 523d3999dcd4bbd9a52661a29dbd7351a9c5fb03 (diff) | |
| download | rust-846d6a4466813f3ad12e2bf15db4071f22b8ae0b.tar.gz rust-846d6a4466813f3ad12e2bf15db4071f22b8ae0b.zip | |
Add __isOSVersionAtLeast and __isPlatformVersionAtLeast symbols
Allows users to link to Objective-C code using `@available(...)`.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/run-make/apple-c-available-links/foo.c | 22 | ||||
| -rw-r--r-- | tests/run-make/apple-c-available-links/main.rs | 7 | ||||
| -rw-r--r-- | tests/run-make/apple-c-available-links/rmake.rs | 14 |
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/run-make/apple-c-available-links/foo.c b/tests/run-make/apple-c-available-links/foo.c new file mode 100644 index 00000000000..eff99a8b12a --- /dev/null +++ b/tests/run-make/apple-c-available-links/foo.c @@ -0,0 +1,22 @@ +int foo(void) { + // Act as if using some API that's a lot newer than the deployment target. + // + // This forces Clang to insert a call to __isPlatformVersionAtLeast, + // and linking will fail if that is not present. + if (__builtin_available( + macos 1000.0, + ios 1000.0, + tvos 1000.0, + watchos 1000.0, + // CI runs below Xcode 15, where `visionos` wasn't a valid key in + // `__builtin_available`. +#ifdef TARGET_OS_VISION + visionos 1000.0, +#endif + * + )) { + return 1; + } else { + return 0; + } +} diff --git a/tests/run-make/apple-c-available-links/main.rs b/tests/run-make/apple-c-available-links/main.rs new file mode 100644 index 00000000000..4ffada43c1b --- /dev/null +++ b/tests/run-make/apple-c-available-links/main.rs @@ -0,0 +1,7 @@ +unsafe extern "C" { + safe fn foo() -> core::ffi::c_int; +} + +fn main() { + assert_eq!(foo(), 0); +} diff --git a/tests/run-make/apple-c-available-links/rmake.rs b/tests/run-make/apple-c-available-links/rmake.rs new file mode 100644 index 00000000000..44a5ee94d57 --- /dev/null +++ b/tests/run-make/apple-c-available-links/rmake.rs @@ -0,0 +1,14 @@ +//! Test that using `__builtin_available` in C (`@available` in Objective-C) +//! successfully links (because `std` provides the required symbols). + +//@ only-apple __builtin_available is (mostly) specific to Apple platforms. + +use run_make_support::{cc, rustc, target}; + +fn main() { + // Invoke the C compiler to generate an object file. + cc().arg("-c").input("foo.c").output("foo.o").run(); + + // Link the object file together with a Rust program. + rustc().target(target()).input("main.rs").link_arg("foo.o").run(); +} |
