From 402100f03b98a265ca42a0706d0d2fdfcfcc6804 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Mon, 29 Sep 2025 19:48:21 +0200 Subject: [PATCH 01/19] add "Android" to PlatformKinds --- include/swift/AST/PlatformKinds.def | 1 + lib/AST/PlatformKindUtils.cpp | 6 ++ lib/Basic/Platform.cpp | 2 + lib/ClangImporter/ClangImporter.cpp | 11 ++++ lib/IRGen/TBDGen.cpp | 2 + lib/PrintAsClang/DeclAndTypePrinter.cpp | 3 + lib/SymbolGraphGen/AvailabilityMixin.cpp | 2 + stdlib/public/core/Availability.swift | 2 +- test/attr/attr_availability_android.swift | 59 +++++++++++++++++++ .../lib/SwiftLang/SwiftDocSupport.cpp | 4 ++ 10 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/attr/attr_availability_android.swift diff --git a/include/swift/AST/PlatformKinds.def b/include/swift/AST/PlatformKinds.def index 9b2fcdadd554a..885bd81c16850 100644 --- a/include/swift/AST/PlatformKinds.def +++ b/include/swift/AST/PlatformKinds.def @@ -37,5 +37,6 @@ AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions f AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD") AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") AVAILABILITY_PLATFORM(Windows, "Windows") +AVAILABILITY_PLATFORM(Android, "Android") #undef AVAILABILITY_PLATFORM diff --git a/lib/AST/PlatformKindUtils.cpp b/lib/AST/PlatformKindUtils.cpp index e54e6be019bee..af8345c1ee4b8 100644 --- a/lib/AST/PlatformKindUtils.cpp +++ b/lib/AST/PlatformKindUtils.cpp @@ -118,6 +118,7 @@ swift::basePlatformForExtensionPlatform(PlatformKind Platform) { case PlatformKind::FreeBSD: case PlatformKind::OpenBSD: case PlatformKind::Windows: + case PlatformKind::Android: case PlatformKind::none: return std::nullopt; } @@ -164,6 +165,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform, return Target.isOSFreeBSD(); case PlatformKind::Windows: return Target.isOSWindows(); + case PlatformKind::Android: + return Target.isAndroid(); case PlatformKind::none: llvm_unreachable("handled above"); } @@ -291,6 +294,8 @@ swift::tripleOSTypeForPlatform(PlatformKind platform) { return llvm::Triple::OpenBSD; case PlatformKind::Windows: return llvm::Triple::Win32; + case PlatformKind::Android: + return llvm::Triple::Linux; case PlatformKind::none: return std::nullopt; } @@ -326,6 +331,7 @@ bool swift::isPlatformSPI(PlatformKind Platform) { case PlatformKind::OpenBSD: case PlatformKind::FreeBSD: case PlatformKind::Windows: + case PlatformKind::Android: case PlatformKind::none: return false; } diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 8906bce54be32..8c6f1200c0a39 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -301,6 +301,8 @@ llvm::VersionTuple swift::getVersionForTriple(const llvm::Triple &triple) { return triple.getOSVersion(); } else if (triple.isOSWindows()) { return triple.getOSVersion(); + } else if (triple.isAndroid()) { + return triple.getEnvironmentVersion(); } return llvm::VersionTuple(/*Major=*/0, /*Minor=*/0, /*Subminor=*/0); } diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 9d0bed0087c8d..57f127efa7e0c 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -2568,6 +2568,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts) deprecatedAsUnavailableMessage = ""; break; + case PlatformKind::Android: + deprecatedAsUnavailableMessage = ""; + break; + case PlatformKind::none: break; } @@ -2616,6 +2620,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const { case PlatformKind::Windows: return name == "windows"; + case PlatformKind::Android: + return name == "android"; + case PlatformKind::none: return false; } @@ -2692,6 +2699,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable( case PlatformKind::Windows: // No deprecation filter on Windows return false; + + case PlatformKind::Android: + // The minimum Android API level supported by Swift is 21 + return major <= 20; } llvm_unreachable("Unexpected platform"); diff --git a/lib/IRGen/TBDGen.cpp b/lib/IRGen/TBDGen.cpp index 5512e5062e0a9..5fcb78af93c44 100644 --- a/lib/IRGen/TBDGen.cpp +++ b/lib/IRGen/TBDGen.cpp @@ -251,6 +251,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver, llvm_unreachable("not used for this platform"); case swift::PlatformKind::Windows: llvm_unreachable("not used for this platform"); + case swift::PlatformKind::Android: + llvm_unreachable("not used for this platform"); case swift::PlatformKind::iOS: case swift::PlatformKind::iOSApplicationExtension: if (target && target->isMacCatalystEnvironment()) diff --git a/lib/PrintAsClang/DeclAndTypePrinter.cpp b/lib/PrintAsClang/DeclAndTypePrinter.cpp index ea84364f60407..868238a4e8d32 100644 --- a/lib/PrintAsClang/DeclAndTypePrinter.cpp +++ b/lib/PrintAsClang/DeclAndTypePrinter.cpp @@ -1830,6 +1830,9 @@ class DeclAndTypePrinter::Implementation case PlatformKind::Windows: plat = "windows"; break; + case PlatformKind::Android: + plat = "android"; + break; case PlatformKind::none: llvm_unreachable("handled above"); } diff --git a/lib/SymbolGraphGen/AvailabilityMixin.cpp b/lib/SymbolGraphGen/AvailabilityMixin.cpp index 4678641bf1598..6da42c72e55dc 100644 --- a/lib/SymbolGraphGen/AvailabilityMixin.cpp +++ b/lib/SymbolGraphGen/AvailabilityMixin.cpp @@ -60,6 +60,8 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) { return { "OpenBSD" }; case swift::PlatformKind::Windows: return { "Windows" }; + case swift::PlatformKind::Android: + return { "Android" }; case swift::PlatformKind::none: return { "*" }; } diff --git a/stdlib/public/core/Availability.swift b/stdlib/public/core/Availability.swift index 08880a2ee57d5..0fd92086e961d 100644 --- a/stdlib/public/core/Availability.swift +++ b/stdlib/public/core/Availability.swift @@ -75,7 +75,7 @@ public func _stdlib_isOSVersionAtLeast_AEIC( _ minor: Builtin.Word, _ patch: Builtin.Word ) -> Builtin.Int1 { -#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)) && SWIFT_RUNTIME_OS_VERSIONING +#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(Android)) && SWIFT_RUNTIME_OS_VERSIONING if Int(major) == 9999 { return true._value } diff --git a/test/attr/attr_availability_android.swift b/test/attr/attr_availability_android.swift new file mode 100644 index 0000000000000..af7ac294d1dc1 --- /dev/null +++ b/test/attr/attr_availability_android.swift @@ -0,0 +1,59 @@ +// RUN: %swift -typecheck -verify -parse-stdlib -target aarch64-unknown-linux-android28 %s + +@available(Android, introduced: 1.0, deprecated: 2.0, obsoleted: 28.0, + message: "you don't want to do that anyway") +func doSomething() { } +// expected-note @-1{{'doSomething()' was obsoleted in Android 28.0}} + +doSomething() // expected-error{{'doSomething()' is unavailable in Android: you don't want to do that anyway}} + +// Preservation of major.minor.micro +@available(Android, introduced: 1.0, deprecated: 2.0, obsoleted: 27.0) +func doSomethingElse() { } +// expected-note @-1{{'doSomethingElse()' was obsoleted in Android 27.0}} + +doSomethingElse() // expected-error{{'doSomethingElse()' is unavailable in Android}} + +// Test deprecations in 28.0 and later + +@available(Android, introduced: 1.1, deprecated: 28.0, + message: "Use another function") +func deprecatedFunctionWithMessage() { } + +deprecatedFunctionWithMessage() // expected-warning{{'deprecatedFunctionWithMessage()' was deprecated in Android 28.0: Use another function}} + + +@available(Android, introduced: 1.0, deprecated: 28.0) +func deprecatedFunctionWithoutMessage() { } + +deprecatedFunctionWithoutMessage() // expected-warning{{'deprecatedFunctionWithoutMessage()' was deprecated in Android 28.0}} + +@available(Android, introduced: 1.0, deprecated: 28.0, + message: "Use BetterClass instead") +class DeprecatedClass { } + +func functionWithDeprecatedParameter(p: DeprecatedClass) { } // expected-warning{{'DeprecatedClass' was deprecated in Android 28.0: Use BetterClass instead}} + +@available(tvOS, introduced: 7.0, deprecated: 29, + message: "Use BetterClass instead") +class DeprecatedClassIn29_0 { } + +// Elements deprecated later than the minimum deployment target (which is 28.0, in this case) should not generate warnings +func functionWithDeprecatedLaterParameter(p: DeprecatedClassIn29_0) { } + +@available(Android, introduced: 30) +func functionIntroducedOnAndroid30() { } + +if #available(iOS 17.3, *) { + functionIntroducedOnAndroid30() // expected-error{{'functionIntroducedOnAndroid30()' is only available in Android 30 or newer}} + // expected-note @-1{{add 'if #available' version check}} +} + +if #available(Android 28, *) { + functionIntroducedOnAndroid30() // expected-error{{'functionIntroducedOnAndroid30()' is only available in Android 30 or newer}} + // expected-note @-1{{add 'if #available' version check}} +} + +if #available(Android 30, *) { + functionIntroducedOnAndroid30() +} diff --git a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp index c5d2c5f3b2612..211f88ff38bf1 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp @@ -688,6 +688,7 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D, static UIdent PlatformFreeBSD("source.availability.platform.freebsd"); static UIdent PlatformOpenBSD("source.availability.platform.openbsd"); static UIdent PlatformWindows("source.availability.platform.windows"); + static UIdent PlatformAndroid("source.availability.platform.android"); std::vector Scratch; for (auto Attr : getAvailableAttrs(D, Scratch)) { @@ -743,6 +744,9 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D, case PlatformKind::Windows: PlatformUID = PlatformWindows; break; + case PlatformKind::Android: + PlatformUID = PlatformAndroid; + break; } // FIXME: [availability] Handle other availability domains? From e00462e2112b70d043c480611957827996cf2eae Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Mon, 29 Sep 2025 21:43:04 +0200 Subject: [PATCH 02/19] add flag to weakly link Android symbols --- lib/ClangImporter/ClangImporter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 57f127efa7e0c..4301af40d09f4 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -665,6 +665,12 @@ void importer::getNormalInvocationArguments( }); } + if (triple.isAndroid()) { + invocationArgStrs.insert(invocationArgStrs.end(), { + "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", + }); + } + if (triple.isOSWindows()) { switch (triple.getArch()) { default: llvm_unreachable("unsupported Windows architecture"); From d955d3ecdc27cfcec59732bfa551404f164fa45e Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Tue, 30 Sep 2025 17:25:25 +0200 Subject: [PATCH 03/19] import Android availability C attribute --- lib/ClangImporter/ImportDecl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 13750fee1c517..4ea5a89aaf4bc 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -9855,6 +9855,7 @@ void ClangImporter::Implementation::importAttributes( PlatformKind::watchOSApplicationExtension) .Case("xros_app_extension", PlatformKind::visionOSApplicationExtension) + .Case("android", PlatformKind::Android) .Default(std::nullopt); if (!platformK) continue; From ea73ef5ab0fe17d94dae3fd6ff21e94e6aab7bb5 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Thu, 2 Oct 2025 06:47:14 +0100 Subject: [PATCH 04/19] add macro test --- test/ClangImporter/android-sdk-macros.swift | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/ClangImporter/android-sdk-macros.swift diff --git a/test/ClangImporter/android-sdk-macros.swift b/test/ClangImporter/android-sdk-macros.swift new file mode 100644 index 0000000000000..3eee516879a2a --- /dev/null +++ b/test/ClangImporter/android-sdk-macros.swift @@ -0,0 +1,4 @@ +// RUN: %swift -target aarch64-unknown-linux-android28 -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-WEAK-SYMBOLS + +// CHECK-WEAK-SYMBOLS: -D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__ + From 73bda81bf10c503d8ef1afcdc8a392af673ba611 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Thu, 2 Oct 2025 06:50:48 +0100 Subject: [PATCH 05/19] include fix-its in tests --- test/attr/attr_availability_android.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/attr/attr_availability_android.swift b/test/attr/attr_availability_android.swift index af7ac294d1dc1..560c361a1cb9e 100644 --- a/test/attr/attr_availability_android.swift +++ b/test/attr/attr_availability_android.swift @@ -46,12 +46,12 @@ func functionIntroducedOnAndroid30() { } if #available(iOS 17.3, *) { functionIntroducedOnAndroid30() // expected-error{{'functionIntroducedOnAndroid30()' is only available in Android 30 or newer}} - // expected-note @-1{{add 'if #available' version check}} + // expected-note @-1{{add 'if #available' version check}}{{3-34=if #available(Android 30, *) {\n functionIntroducedOnAndroid30()\n \} else {\n // Fallback on earlier versions\n \}}} } if #available(Android 28, *) { functionIntroducedOnAndroid30() // expected-error{{'functionIntroducedOnAndroid30()' is only available in Android 30 or newer}} - // expected-note @-1{{add 'if #available' version check}} + // expected-note @-1{{add 'if #available' version check}}{{3-34=if #available(Android 30, *) {\n functionIntroducedOnAndroid30()\n \} else {\n // Fallback on earlier versions\n \}}} } if #available(Android 30, *) { From 94b5e4a47820c0d7689f784069853b20da25c820 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 3 Oct 2025 23:28:38 +0100 Subject: [PATCH 06/19] add ClangImporter tests --- .../Inputs/custom-modules/AndroidVersioning.h | 5 +++++ test/ClangImporter/availability_android.swift | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h create mode 100644 test/ClangImporter/availability_android.swift diff --git a/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h b/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h new file mode 100644 index 0000000000000..70956605a9bb7 --- /dev/null +++ b/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h @@ -0,0 +1,5 @@ +import + +void FunctionIntroducedIn24() __INTRODUCED_IN(24); +void FunctionIntroducedIn28() __INTRODUCED_IN(28); + diff --git a/test/ClangImporter/availability_android.swift b/test/ClangImporter/availability_android.swift new file mode 100644 index 0000000000000..986bf8eb4f4cc --- /dev/null +++ b/test/ClangImporter/availability_android.swift @@ -0,0 +1,11 @@ +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -verify-ignore-unknown -target aarch64-unknown-linux-android24 %s + +// REQUIRES: OS=linux-android || OS=linux-androideabi + +import AndroidVersioning + +FunctionIntroducedIn24() + +FunctionIntroducedIn28() +// expected-error@-1 {{'FunctionIntroducedIn28()' is only available in Android 28 or newer}} +// expected-note@-2 {{add 'if #available' version check}} From 24710b57dcd22b1ca9b0b705436096e0c49673b2 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sun, 5 Oct 2025 22:25:30 +0200 Subject: [PATCH 07/19] emit `__isOSVersionAtLeast` for Android --- include/swift/Runtime/RuntimeFunctions.def | 10 ++++++++++ lib/IRGen/IRGenFunction.cpp | 15 +++++++++++---- test/ClangImporter/availability_android.swift | 2 +- test/IRGen/availability_android.swift | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 test/IRGen/availability_android.swift diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index 7709fc11dac54..ffe1c72ed3ec2 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -2133,6 +2133,16 @@ FUNCTION(TSanInoutAccess, tsan, __tsan_external_write, C_CC, AlwaysAvailable, EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) +// int32 __isOSVersionAtLeast(uint32_t major, uint32_t minor, uint32_t patch); +// This a C builtin provided by compiler-rt. +FUNCTION(OSVersionAtLeast, libgcc, __isOSVersionAtLeast, + C_CC, AlwaysAvailable, + RETURNS(Int32Ty), + ARGS(Int32Ty, Int32Ty, Int32Ty), + ATTRS(NoUnwind), + EFFECT(RuntimeEffect::NoEffect), + UNKNOWN_MEMEFFECTS) + // int32 __isPlatformVersionAtLeast(uint32_t platform, uint32_t major, // uint32_t minor, uint32_t patch); // This a C builtin provided by compiler-rt. diff --git a/lib/IRGen/IRGenFunction.cpp b/lib/IRGen/IRGenFunction.cpp index 34606f3353a9a..ffc4cd94919cd 100644 --- a/lib/IRGen/IRGenFunction.cpp +++ b/lib/IRGen/IRGenFunction.cpp @@ -307,11 +307,18 @@ llvm::Value * IRGenFunction::emitTargetOSVersionAtLeastCall(llvm::Value *major, llvm::Value *minor, llvm::Value *patch) { - auto fn = IGM.getPlatformVersionAtLeastFunctionPointer(); + // compiler-rt in the NDK does not include __isPlatformVersionAtLeast + // but only __isOSVersionAtLeast + if (IGM.Triple.isAndroid()) { + auto fn = IGM.getOSVersionAtLeastFunctionPointer(); + return Builder.CreateCall(fn, {major, minor, patch}); + } else { + auto fn = IGM.getPlatformVersionAtLeastFunctionPointer(); - llvm::Value *platformID = - llvm::ConstantInt::get(IGM.Int32Ty, getBaseMachOPlatformID(IGM.Triple)); - return Builder.CreateCall(fn, {platformID, major, minor, patch}); + llvm::Value *platformID = + llvm::ConstantInt::get(IGM.Int32Ty, getBaseMachOPlatformID(IGM.Triple)); + return Builder.CreateCall(fn, {platformID, major, minor, patch}); + } } llvm::Value * diff --git a/test/ClangImporter/availability_android.swift b/test/ClangImporter/availability_android.swift index 986bf8eb4f4cc..ad891bccb0be0 100644 --- a/test/ClangImporter/availability_android.swift +++ b/test/ClangImporter/availability_android.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -verify-ignore-unknown -target aarch64-unknown-linux-android24 %s -// REQUIRES: OS=linux-android || OS=linux-androideabi +// REQUIRES: OS=linux-android || OS=linux-androideabi import AndroidVersioning diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift new file mode 100644 index 0000000000000..56f701c07ac80 --- /dev/null +++ b/test/IRGen/availability_android.swift @@ -0,0 +1,16 @@ +// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir | %FileCheck %s +// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT + +// REQUIRES: OS=linux-android || OS=linux-androideabi + +// CHECK-LABEL: define{{.*}} @{{.*}}availabilityCheck +// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( + +// OPT-LABEL: define{{.*}} @{{.*}}availabilityCheck +// OPT: call {{.*}} @__isOSVersionAtLeast( + +public func availabilityCheck() { + if #available(Android 28, *) { + print("test") + } +} From 5e878855bca337aa65a48d0a086d94393f6a3532 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Mon, 6 Oct 2025 18:35:28 +0200 Subject: [PATCH 08/19] fix tests --- .../Inputs/custom-modules/AndroidVersioning.h | 2 +- test/ClangImporter/Inputs/custom-modules/module.modulemap | 5 +++++ test/ClangImporter/availability_android.swift | 2 +- test/IRGen/availability_android.swift | 8 ++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h b/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h index 70956605a9bb7..813d9b9fa7137 100644 --- a/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h +++ b/test/ClangImporter/Inputs/custom-modules/AndroidVersioning.h @@ -1,4 +1,4 @@ -import +#include void FunctionIntroducedIn24() __INTRODUCED_IN(24); void FunctionIntroducedIn28() __INTRODUCED_IN(28); diff --git a/test/ClangImporter/Inputs/custom-modules/module.modulemap b/test/ClangImporter/Inputs/custom-modules/module.modulemap index b37985ec675e0..7332d7d643539 100644 --- a/test/ClangImporter/Inputs/custom-modules/module.modulemap +++ b/test/ClangImporter/Inputs/custom-modules/module.modulemap @@ -2,6 +2,11 @@ module script { header "script.h" } +module AndroidVersioning { + header "AndroidVersioning.h" + export * +} + module AvailabilityExtras { header "AvailabilityExtras.h" export * diff --git a/test/ClangImporter/availability_android.swift b/test/ClangImporter/availability_android.swift index ad891bccb0be0..96e73248b21cb 100644 --- a/test/ClangImporter/availability_android.swift +++ b/test/ClangImporter/availability_android.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -verify-ignore-unknown -target aarch64-unknown-linux-android24 %s +// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs/custom-modules -verify-ignore-unknown -target aarch64-unknown-linux-android24 %s // REQUIRES: OS=linux-android || OS=linux-androideabi diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index 56f701c07ac80..b9c771c888b34 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -3,11 +3,11 @@ // REQUIRES: OS=linux-android || OS=linux-androideabi -// CHECK-LABEL: define{{.*}} @{{.*}}availabilityCheck -// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( +// CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF +// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1#include_Bw_BwBwtF"( -// OPT-LABEL: define{{.*}} @{{.*}}availabilityCheck -// OPT: call {{.*}} @__isOSVersionAtLeast( +// OPT-LABEL: define{{.*}}$s20availability_android0A5CheckyyF +// OPT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( public func availabilityCheck() { if #available(Android 28, *) { From 71a6851ade661307766d70e1422e860a67077fe5 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Wed, 8 Oct 2025 11:36:24 +0200 Subject: [PATCH 09/19] update naming --- include/swift/AST/PlatformKinds.def | 2 +- lib/SymbolGraphGen/AvailabilityMixin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/swift/AST/PlatformKinds.def b/include/swift/AST/PlatformKinds.def index 885bd81c16850..9d095f405b75b 100644 --- a/include/swift/AST/PlatformKinds.def +++ b/include/swift/AST/PlatformKinds.def @@ -37,6 +37,6 @@ AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions f AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD") AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") AVAILABILITY_PLATFORM(Windows, "Windows") -AVAILABILITY_PLATFORM(Android, "Android") +AVAILABILITY_PLATFORM(Android, "android") #undef AVAILABILITY_PLATFORM diff --git a/lib/SymbolGraphGen/AvailabilityMixin.cpp b/lib/SymbolGraphGen/AvailabilityMixin.cpp index 6da42c72e55dc..c832c8bc8d17a 100644 --- a/lib/SymbolGraphGen/AvailabilityMixin.cpp +++ b/lib/SymbolGraphGen/AvailabilityMixin.cpp @@ -61,7 +61,7 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) { case swift::PlatformKind::Windows: return { "Windows" }; case swift::PlatformKind::Android: - return { "Android" }; + return { "android" }; case swift::PlatformKind::none: return { "*" }; } From 91601fd315fa73757e649d9dc8dcfa7c3ad09833 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Wed, 8 Oct 2025 12:51:00 +0200 Subject: [PATCH 10/19] detect android from triple --- include/swift/AST/PlatformKinds.def | 2 +- lib/AST/PlatformKindUtils.cpp | 4 ++++ lib/SymbolGraphGen/AvailabilityMixin.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/swift/AST/PlatformKinds.def b/include/swift/AST/PlatformKinds.def index 9d095f405b75b..885bd81c16850 100644 --- a/include/swift/AST/PlatformKinds.def +++ b/include/swift/AST/PlatformKinds.def @@ -37,6 +37,6 @@ AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions f AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD") AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") AVAILABILITY_PLATFORM(Windows, "Windows") -AVAILABILITY_PLATFORM(Android, "android") +AVAILABILITY_PLATFORM(Android, "Android") #undef AVAILABILITY_PLATFORM diff --git a/lib/AST/PlatformKindUtils.cpp b/lib/AST/PlatformKindUtils.cpp index af8345c1ee4b8..bf8fca3bad5d1 100644 --- a/lib/AST/PlatformKindUtils.cpp +++ b/lib/AST/PlatformKindUtils.cpp @@ -222,6 +222,10 @@ static PlatformKind platformForTriple(const llvm::Triple &triple, : PlatformKind::visionOS); } + if (triple.isAndroid()) { + return PlatformKind::Android; + } + return PlatformKind::none; } diff --git a/lib/SymbolGraphGen/AvailabilityMixin.cpp b/lib/SymbolGraphGen/AvailabilityMixin.cpp index c832c8bc8d17a..6da42c72e55dc 100644 --- a/lib/SymbolGraphGen/AvailabilityMixin.cpp +++ b/lib/SymbolGraphGen/AvailabilityMixin.cpp @@ -61,7 +61,7 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) { case swift::PlatformKind::Windows: return { "Windows" }; case swift::PlatformKind::Android: - return { "android" }; + return { "Android" }; case swift::PlatformKind::none: return { "*" }; } From 1297b467b01bd42e5b324255e1188667dc8c4f79 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Wed, 8 Oct 2025 13:21:21 +0200 Subject: [PATCH 11/19] fix irgen test --- test/IRGen/availability_android.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index b9c771c888b34..9fac1b89076d1 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -4,7 +4,7 @@ // REQUIRES: OS=linux-android || OS=linux-androideabi // CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF -// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1#include_Bw_BwBwtF"( +// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( // OPT-LABEL: define{{.*}}$s20availability_android0A5CheckyyF // OPT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( From 973913f8221391bfa7ff985519d7a2916a91234e Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Thu, 9 Oct 2025 17:19:57 +0200 Subject: [PATCH 12/19] use parse-stdlib for test and disable unversioned reflection test --- stdlib/private/CMakeLists.txt | 5 ++++- test/IRGen/availability_android.swift | 8 ++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/stdlib/private/CMakeLists.txt b/stdlib/private/CMakeLists.txt index f6a78bef273eb..142f4cb51fa72 100644 --- a/stdlib/private/CMakeLists.txt +++ b/stdlib/private/CMakeLists.txt @@ -30,10 +30,13 @@ if(SWIFT_BUILD_SDK_OVERLAY endif() # Currently SwiftReflectionTest cannot be built on Windows, due to # dependencies on POSIX symbols + # Android does not have stdout on API 22 and below, so we also disable it there if (SWIFT_INCLUDE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" - AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.8")) + AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.8") + AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" + AND CMAKE_SYSTEM_VERSION VERSION_LESS "23")) add_subdirectory(SwiftReflectionTest) endif() endif() diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index 9fac1b89076d1..959d2fea258af 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -1,13 +1,9 @@ -// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir | %FileCheck %s -// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT - -// REQUIRES: OS=linux-android || OS=linux-androideabi +// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir -parse-stdlib | %FileCheck %s // CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF // CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( -// OPT-LABEL: define{{.*}}$s20availability_android0A5CheckyyF -// OPT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( +import Swift public func availabilityCheck() { if #available(Android 28, *) { From 12d269675dedf4689c6ed36eff037406831d3028 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 10 Oct 2025 13:23:03 +0200 Subject: [PATCH 13/19] add android target version to reflection test --- stdlib/cmake/modules/AddSwiftStdlib.cmake | 4 ++++ stdlib/private/CMakeLists.txt | 5 +---- stdlib/private/SwiftReflectionTest/CMakeLists.txt | 11 +++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index e47c9db33ab65..3e83bda5752c6 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -2022,6 +2022,7 @@ function(add_swift_target_library name) SWIFT_COMPILE_FLAGS_WATCHOS SWIFT_COMPILE_FLAGS_XROS SWIFT_COMPILE_FLAGS_LINUX + SWIFT_COMPILE_FLAGS_ANDROID SWIFT_COMPILE_FLAGS_LINUX_STATIC SWIFT_MODULE_DEPENDS SWIFT_MODULE_DEPENDS_ANDROID @@ -2250,6 +2251,9 @@ function(add_swift_target_library name) elseif(sdk STREQUAL "LINUX") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_LINUX}) + elseif(sdk STREQUAL "ANDROID") + list(APPEND swiftlib_module_depends_flattened + ${SWIFTLIB_SWIFT_MODULE_DEPENDS_ANDROID}) elseif(sdk STREQUAL "LINUX_STATIC") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_LINUX_STATIC}) diff --git a/stdlib/private/CMakeLists.txt b/stdlib/private/CMakeLists.txt index 142f4cb51fa72..f6a78bef273eb 100644 --- a/stdlib/private/CMakeLists.txt +++ b/stdlib/private/CMakeLists.txt @@ -30,13 +30,10 @@ if(SWIFT_BUILD_SDK_OVERLAY endif() # Currently SwiftReflectionTest cannot be built on Windows, due to # dependencies on POSIX symbols - # Android does not have stdout on API 22 and below, so we also disable it there if (SWIFT_INCLUDE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" - AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.8") - AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" - AND CMAKE_SYSTEM_VERSION VERSION_LESS "23")) + AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.8")) add_subdirectory(SwiftReflectionTest) endif() endif() diff --git a/stdlib/private/SwiftReflectionTest/CMakeLists.txt b/stdlib/private/SwiftReflectionTest/CMakeLists.txt index 8cbe7c8a6ee6d..743be6f5679f0 100644 --- a/stdlib/private/SwiftReflectionTest/CMakeLists.txt +++ b/stdlib/private/SwiftReflectionTest/CMakeLists.txt @@ -10,10 +10,21 @@ if((SWIFT_BUILD_CLANG_OVERLAYS endif() if (SWIFT_INCLUDE_TESTS AND SWIFT_BUILD_DYNAMIC_STDLIB) + if(SWIFT_ANDROID_API_LEVEL) + # SWIFT_SDK_ANDROID_ARCHITECTURES can be a list (e.g., "armv7;aarch64"). + # We only need one architecture to construct a representative target triple + # for the Swift availability checker. We'll pick the first one. + list(GET SWIFT_SDK_ANDROID_ARCHITECTURES 0 arch) + + # Construct the full, versioned target triple. + set(ANDROID_VERSIONED_TARGET "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}") + endif() + add_swift_target_library(swiftSwiftReflectionTest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB SwiftReflectionTest.swift SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} SWIFT_COMPILE_FLAGS_LINUX -Xcc -D_GNU_SOURCE + SWIFT_COMPILE_FLAGS_ANDROID -target ${ANDROID_VERSIONED_TARGET} SWIFT_MODULE_DEPENDS_OSX ${swift_reflection_test_darwin_dependencies} SWIFT_MODULE_DEPENDS_IOS ${swift_reflection_test_darwin_dependencies} SWIFT_MODULE_DEPENDS_TVOS ${swift_reflection_test_darwin_dependencies} From cf03af940ea3dd08b0b781566cf52b14404c611e Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 10 Oct 2025 13:55:21 +0200 Subject: [PATCH 14/19] add bionic clang importer test --- test/ClangImporter/availability_android.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ClangImporter/availability_android.swift b/test/ClangImporter/availability_android.swift index 96e73248b21cb..bab53776770b2 100644 --- a/test/ClangImporter/availability_android.swift +++ b/test/ClangImporter/availability_android.swift @@ -3,9 +3,24 @@ // REQUIRES: OS=linux-android || OS=linux-androideabi import AndroidVersioning +import Android FunctionIntroducedIn24() FunctionIntroducedIn28() // expected-error@-1 {{'FunctionIntroducedIn28()' is only available in Android 28 or newer}} // expected-note@-2 {{add 'if #available' version check}} + +func test_ifaddrs_introduced_in_24() { + var ifaddr_ptr: UnsafeMutablePointer? = nil + if getifaddrs(&ifaddr_ptr) == 0 { + freeifaddrs(ifaddr_ptr) + } +} + +func test_getentropy_introduced_in_28() { + var buffer: [UInt8] = .init(repeating: 0, count: 16) + getentropy(&buffer, buffer.count) + // expected-error@-1 {{'getentropy' is only available in Android 28 or newer}} + // expected-note@-2 {{add 'if #available' version check}} +} \ No newline at end of file From 0516c319a10603a75eaaa8a7fe7d548a125a910c Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 10 Oct 2025 18:09:38 +0200 Subject: [PATCH 15/19] fix IRGen test --- test/IRGen/availability_android.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index 959d2fea258af..fb6093735e2bd 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -3,10 +3,7 @@ // CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF // CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( -import Swift - +@inlinable public func availabilityCheck() { - if #available(Android 28, *) { - print("test") - } + if #available(Android 28, *) {} } From 1917895869b86f1ffe84bc3aac0a7943e14e16e3 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 10 Oct 2025 20:02:54 +0200 Subject: [PATCH 16/19] change the "hack" to version build the reflection test --- stdlib/cmake/modules/AddSwiftStdlib.cmake | 6 +++++- stdlib/private/SwiftReflectionTest/CMakeLists.txt | 11 ----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 3e83bda5752c6..4af8f5702a90b 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -2022,7 +2022,6 @@ function(add_swift_target_library name) SWIFT_COMPILE_FLAGS_WATCHOS SWIFT_COMPILE_FLAGS_XROS SWIFT_COMPILE_FLAGS_LINUX - SWIFT_COMPILE_FLAGS_ANDROID SWIFT_COMPILE_FLAGS_LINUX_STATIC SWIFT_MODULE_DEPENDS SWIFT_MODULE_DEPENDS_ANDROID @@ -2545,6 +2544,11 @@ function(add_swift_target_library name) list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384") endif() + # This is a Android-specific hack till we transition the stdlib fully to versioned triples. + if(sdk STREQUAL "ANDROID" AND name STREQUAL "swiftSwiftReflectionTest") + list(APPEND swiftlib_swift_compile_flags_arch "-target" "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}") + endif() + if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY) set(back_deployment_library_option BACK_DEPLOYMENT_LIBRARY ${SWIFTLIB_BACK_DEPLOYMENT_LIBRARY}) else() diff --git a/stdlib/private/SwiftReflectionTest/CMakeLists.txt b/stdlib/private/SwiftReflectionTest/CMakeLists.txt index 743be6f5679f0..8cbe7c8a6ee6d 100644 --- a/stdlib/private/SwiftReflectionTest/CMakeLists.txt +++ b/stdlib/private/SwiftReflectionTest/CMakeLists.txt @@ -10,21 +10,10 @@ if((SWIFT_BUILD_CLANG_OVERLAYS endif() if (SWIFT_INCLUDE_TESTS AND SWIFT_BUILD_DYNAMIC_STDLIB) - if(SWIFT_ANDROID_API_LEVEL) - # SWIFT_SDK_ANDROID_ARCHITECTURES can be a list (e.g., "armv7;aarch64"). - # We only need one architecture to construct a representative target triple - # for the Swift availability checker. We'll pick the first one. - list(GET SWIFT_SDK_ANDROID_ARCHITECTURES 0 arch) - - # Construct the full, versioned target triple. - set(ANDROID_VERSIONED_TARGET "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}") - endif() - add_swift_target_library(swiftSwiftReflectionTest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB SwiftReflectionTest.swift SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} SWIFT_COMPILE_FLAGS_LINUX -Xcc -D_GNU_SOURCE - SWIFT_COMPILE_FLAGS_ANDROID -target ${ANDROID_VERSIONED_TARGET} SWIFT_MODULE_DEPENDS_OSX ${swift_reflection_test_darwin_dependencies} SWIFT_MODULE_DEPENDS_IOS ${swift_reflection_test_darwin_dependencies} SWIFT_MODULE_DEPENDS_TVOS ${swift_reflection_test_darwin_dependencies} From ae7ef63e273be5e14f7b039bf1ce91642f2eab91 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 11 Oct 2025 10:26:35 +0200 Subject: [PATCH 17/19] use `all` instead of `arch` --- stdlib/cmake/modules/AddSwiftStdlib.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 4af8f5702a90b..b2d4e34bc98a3 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -2546,7 +2546,7 @@ function(add_swift_target_library name) # This is a Android-specific hack till we transition the stdlib fully to versioned triples. if(sdk STREQUAL "ANDROID" AND name STREQUAL "swiftSwiftReflectionTest") - list(APPEND swiftlib_swift_compile_flags_arch "-target" "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}") + list(APPEND swiftlib_swift_compile_flags_all "-target" "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}") endif() if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY) From 7d8314211dcb0c96b8c5ff540b340ba7bcf5a3b4 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 11 Oct 2025 15:31:17 +0200 Subject: [PATCH 18/19] fix IRGen test --- test/IRGen/availability_android.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index fb6093735e2bd..f184ef9426a8e 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -1,9 +1,14 @@ // RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir -parse-stdlib | %FileCheck %s -// CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF +// CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckSSyF // CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( -@inlinable -public func availabilityCheck() { - if #available(Android 28, *) {} +import Swift + +public func availabilityCheck() -> String { + if #available(Android 28, *) { + return "28" + } else { + return "not 28" + } } From b4e2b9705bb59afdf05dcbb19a13a761e5478be7 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sun, 12 Oct 2025 09:02:54 +0200 Subject: [PATCH 19/19] revert to only running IRGen for android --- test/IRGen/availability_android.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/IRGen/availability_android.swift b/test/IRGen/availability_android.swift index f184ef9426a8e..470eaa8a9462f 100644 --- a/test/IRGen/availability_android.swift +++ b/test/IRGen/availability_android.swift @@ -1,14 +1,12 @@ -// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir -parse-stdlib | %FileCheck %s +// RUN: %target-swift-frontend -target aarch64-unknown-linux-android24 -primary-file %s -emit-ir | %FileCheck %s -// CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckSSyF +// CHECK-LABEL: define{{.*}}$s20availability_android0A5CheckyyF // CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"( -import Swift +// REQUIRES: OS=linux-android || OS=linux-androideabi -public func availabilityCheck() -> String { +public func availabilityCheck() { if #available(Android 28, *) { - return "28" - } else { - return "not 28" + print("test") } }