Skip to content

Commit 35f52ab

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 38dbbf0 + 1dbdf0c commit 35f52ab

14 files changed

+136
-157
lines changed

docs/Android.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ on an Android device, it takes a lot more than just the Swift stdlib to write
2222
an app. You'd need some sort of framework to build a user interface for your
2323
application, which the Swift stdlib does not provide.
2424

25-
Alternatively, one could theoretically call into Java interfaces from Swift,
26-
but unlike as with Objective-C, the Swift compiler does nothing to facilitate
27-
Swift-to-Java bridging.
28-
2925
## Prerequisites
3026

3127
To follow along with this guide, you'll need:
3228

3329
1. A Linux environment capable of building Swift from source, preferably
34-
Ubuntu 22.04 or Ubuntu 20.04. Before attempting to build for Android,
30+
Ubuntu 24.04 or Ubuntu 22.04. Before attempting to build for Android,
3531
please make sure you are able to build for Linux by following the
3632
instructions in the Swift project README.
3733
2. The latest build of the Swift compiler for your Linux distro, available at
38-
https://www.swift.org/download/ or sometimes your distro package manager.
39-
3. The latest version of the Android LTS NDK (r27c at the time of this writing),
34+
https://www.swift.org/install/linux/ or sometimes your distro package manager.
35+
3. The latest version of the Android LTS NDK (r27d at the time of this writing),
4036
available to download here:
4137
https://developer.android.com/ndk/downloads
4238
4. An Android device with remote debugging enabled or the emulator. We require
@@ -54,9 +50,9 @@ and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
5450
have a Swift toolchain in your path):
5551

5652
```
57-
$ NDK_PATH=path/to/android-ndk-r27c
58-
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a-ubuntu22.04/usr/bin
59-
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a
53+
$ NDK_PATH=path/to/android-ndk-r27d
54+
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a-ubuntu24.04/usr/bin
55+
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a
6056
$ utils/build-script \
6157
-R \ # Build in ReleaseAssert mode.
6258
--android \ # Build for Android.
@@ -83,11 +79,12 @@ Then use the standalone Swift stdlib from the previous step to compile a Swift
8379
source file, targeting Android:
8480

8581
```
86-
$ NDK_PATH="path/to/android-ndk-r27c"
87-
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a-ubuntu22.04/usr/bin
82+
$ NDK_PATH="path/to/android-ndk-r27d"
83+
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a-ubuntu24.04/usr/bin
8884
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
8985
# The location of the tools used to build Android binaries
9086
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
87+
-disallow-use-new-driver \ # Work around a bug in the driver, a fix is in the works
9188
-target aarch64-unknown-linux-android21 \ # Targeting Android aarch64 at API 21
9289
-sdk ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ # The SDK is the Android unified sysroot and the resource-dir is where you just built the Swift stdlib.
9390
-resource-dir build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift
@@ -135,7 +132,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
135132
In addition, you'll also need to copy the Android NDK's libc++:
136133

137134
```
138-
$ adb push /path/to/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
135+
$ adb push /path/to/android-ndk-r27d/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
139136
```
140137

141138
Finally, you'll need to copy the `hello` executable you built in the
@@ -178,7 +175,7 @@ $ utils/build-script \
178175
-R \ # Build in ReleaseAssert mode.
179176
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
180177
--android \ # Build for Android.
181-
--android-ndk ~/android-ndk-r27c \ # Path to an Android NDK.
178+
--android-ndk ~/android-ndk-r27d \ # Path to an Android NDK.
182179
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7 or x86_64
183180
--android-api-level 21
184181
```

lib/AST/AvailabilityConstraint.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,9 @@ static bool canIgnoreConstraintInUnavailableContexts(
172172
return true;
173173

174174
case AvailabilityConstraint::Reason::Unintroduced:
175-
switch (domain.getKind()) {
176-
case AvailabilityDomain::Kind::Universal:
177-
case AvailabilityDomain::Kind::SwiftLanguage:
178-
case AvailabilityDomain::Kind::PackageDescription:
179-
case AvailabilityDomain::Kind::Embedded:
180-
case AvailabilityDomain::Kind::Custom:
181-
return false;
182-
case AvailabilityDomain::Kind::Platform:
183-
// Platform availability only applies to the target triple that the
184-
// binary is being compiled for. Since the same declaration can be
185-
// potentially unavailable from a given context when compiling for one
186-
// platform, but available from that context when compiling for a
187-
// different platform, it is overly strict to enforce potential platform
188-
// unavailability constraints in contexts that are unavailable to that
189-
// platform.
190-
return true;
191-
}
192-
return constraint.getDomain().isPlatform();
193-
194175
case AvailabilityConstraint::Reason::UnavailableObsolete:
195176
case AvailabilityConstraint::Reason::UnavailableUnintroduced:
196-
return false;
177+
return domain.isVersioned();
197178
}
198179
}
199180

lib/Sema/TypeCheckAccess.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,11 +2073,6 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
20732073
// Don't bother checking errors.
20742074
if (type && type->hasError())
20752075
return;
2076-
2077-
// If the decl which references this type is unavailable on the current
2078-
// platform, don't diagnose the availability of the type.
2079-
if (Where.getAvailability().isUnavailable())
2080-
return;
20812076

20822077
diagnoseTypeAvailability(typeRepr, type, context->getLoc(),
20832078
Where.withReason(reason), flags);

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,12 @@ static void diagnoseIfDeprecated(SourceRange ReferenceRange,
15021502
// We match the behavior of clang to not report deprecation warnings
15031503
// inside declarations that are themselves deprecated on all deployment
15041504
// targets.
1505-
if (Availability.isDeprecated()) {
1505+
if (Availability.isDeprecated())
1506+
return;
1507+
1508+
// Skip diagnosing deprecated types in unavailable contexts.
1509+
if (Availability.isUnavailable() && isa<TypeDecl>(DeprecatedDecl))
15061510
return;
1507-
}
15081511

15091512
auto *ReferenceDC = Where.getDeclContext();
15101513
auto &Context = ReferenceDC->getASTContext();

test/ASTGen/embedded_availability.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct UnavailableInEmbedded {}
1111

1212
@available(*, unavailable, message: "always unavailable")
1313
public struct UniverallyUnavailable {}
14-
// expected-note@-1 {{'UniverallyUnavailable' has been explicitly marked unavailable here}}
14+
// expected-note@-1 3 {{'UniverallyUnavailable' has been explicitly marked unavailable here}}
1515

1616
@_unavailableInEmbedded
1717
public func unavailable_in_embedded() { }
@@ -43,7 +43,7 @@ public struct Available {}
4343
extension Available {
4444
public func unavailable_in_embedded_method( // expected-note {{'unavailable_in_embedded_method' has been explicitly marked unavailable here}}
4545
_ uie: UnavailableInEmbedded,
46-
_ uu: UniverallyUnavailable,
46+
_ uu: UniverallyUnavailable, // expected-error {{'UniverallyUnavailable' is unavailable: always unavailable}}
4747
_ a: Available,
4848
) {
4949
unavailable_in_embedded()
@@ -67,7 +67,7 @@ public func available(
6767
@_unavailableInEmbedded
6868
public func also_unavailable_in_embedded(
6969
_ uie: UnavailableInEmbedded, // OK
70-
_ uu: UniverallyUnavailable, // OK
70+
_ uu: UniverallyUnavailable, // expected-error {{'UniverallyUnavailable' is unavailable: always unavailable}}
7171
_ a: Available,
7272
) {
7373
unavailable_in_embedded() // OK

test/Availability/availability_custom_domains.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,11 @@ class DerivedLessAvailable: BaseAvailableInEnabledDomain { // expected-error {{'
522522
}
523523

524524
@available(EnabledDomain, unavailable)
525-
class DerivedUnavailable: BaseAvailableInEnabledDomain { }
525+
class DerivedUnavailable: BaseAvailableInEnabledDomain { } // expected-error {{'BaseAvailableInEnabledDomain' is only available in EnabledDomain}}
526526

527-
// FIXME: This shouldn't be accepted
528527
@available(DisabledDomain, unavailable)
529-
class DerivedUnavailable2: BaseAvailableInEnabledDomain { }
528+
class DerivedUnavailable2: BaseAvailableInEnabledDomain { } // expected-error {{'BaseAvailableInEnabledDomain' is only available in EnabledDomain}}
529+
// expected-note@-1 {{add '@available' attribute to enclosing class}}
530530

531531
@available(EnabledDomain)
532532
@available(DisabledDomain, unavailable)

test/Availability/availability_target_min_inlining.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public func alwaysUnavailable(
350350
_ = BetweenTargets()
351351
_ = AtDeploymentTarget()
352352
_ = AfterDeploymentTarget()
353-
_ = ObsoletedBetweenTargets() // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
353+
_ = ObsoletedBetweenTargets()
354354
_ = Unavailable()
355355

356356
if #available(macOS 11, *) {
@@ -630,20 +630,20 @@ public func spiDeployedUseNoAvailable( // expected-note 3 {{add '@available' att
630630
defer {
631631
_ = AtDeploymentTarget()
632632
_ = AfterDeploymentTarget()
633-
_ = ObsoletedBetweenTargets() // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
633+
_ = ObsoletedBetweenTargets()
634634
}
635635
_ = NoAvailable()
636636
_ = BeforeInliningTarget()
637637
_ = AtInliningTarget()
638638
_ = BetweenTargets()
639639
_ = AtDeploymentTarget()
640640
_ = AfterDeploymentTarget()
641-
_ = ObsoletedBetweenTargets() // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
641+
_ = ObsoletedBetweenTargets()
642642
_ = Unavailable()
643643

644644
if #available(macOS 11, *) {
645645
_ = AfterDeploymentTarget()
646-
_ = ObsoletedBetweenTargets() // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
646+
_ = ObsoletedBetweenTargets()
647647
}
648648
}
649649

@@ -930,7 +930,7 @@ public func defaultArgsUseUnavailable(
930930
_: Any = BetweenTargets.self,
931931
_: Any = AtDeploymentTarget.self,
932932
_: Any = AfterDeploymentTarget.self,
933-
_: Any = ObsoletedBetweenTargets.self, // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
933+
_: Any = ObsoletedBetweenTargets.self,
934934
_: Any = Unavailable.self
935935
) {}
936936

@@ -1056,7 +1056,7 @@ public struct PublicStruct { // expected-note 21 {{add '@available' attribute}}
10561056

10571057
@available(macOS, unavailable)
10581058
public var gUnavailable: ObsoletedBetweenTargets {
1059-
ObsoletedBetweenTargets() // expected-error {{'ObsoletedBetweenTargets' is unavailable in macOS}}
1059+
ObsoletedBetweenTargets()
10601060
}
10611061

10621062
// The inferred types of public properties are exposed.

test/Availability/conformance_availability.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public struct HasUnavailableConformance3 {}
7070

7171
@available(swift 12)
7272
extension HasUnavailableConformance3 : Horse {}
73-
// expected-note@-1 12{{conformance of 'HasUnavailableConformance3' to 'Horse' was introduced in Swift 12}}
73+
// expected-note@-1 6{{conformance of 'HasUnavailableConformance3' to 'Horse' was introduced in Swift 12}}
7474

7575
func passUnavailableConformance3(x: HasUnavailableConformance3) {
7676
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
@@ -83,20 +83,20 @@ func passUnavailableConformance3(x: HasUnavailableConformance3) {
8383

8484
@available(swift 12)
8585
func passUnavailableConformance3a(x: HasUnavailableConformance3) {
86-
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
87-
takesHorseExistential(x) // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
88-
x.giddyUp() // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
89-
_ = x.isGalloping // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
90-
_ = x[keyPath: \.isGalloping] // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
91-
_ = UsesHorse<HasUnavailableConformance3>.self // expected-error {{conformance of 'HasUnavailableConformance3' to 'Horse' is unavailable}}
86+
takesHorse(x)
87+
takesHorseExistential(x)
88+
x.giddyUp()
89+
_ = x.isGalloping
90+
_ = x[keyPath: \.isGalloping]
91+
_ = UsesHorse<HasUnavailableConformance3>.self
9292
}
9393

9494
// Platform obsoleted
9595
public struct HasUnavailableConformance4 {}
9696

9797
@available(macOS, obsoleted: 10.1)
9898
extension HasUnavailableConformance4 : Horse {}
99-
// expected-note@-1 12{{conformance of 'HasUnavailableConformance4' to 'Horse' was obsoleted in macOS 10.1}}
99+
// expected-note@-1 6{{conformance of 'HasUnavailableConformance4' to 'Horse' was obsoleted in macOS 10.1}}
100100

101101
func passUnavailableConformance4(x: HasUnavailableConformance4) {
102102
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable in macOS}}
@@ -109,20 +109,20 @@ func passUnavailableConformance4(x: HasUnavailableConformance4) {
109109

110110
@available(macOS, obsoleted: 10.1)
111111
func passUnavailableConformance4a(x: HasUnavailableConformance4) {
112-
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable in macOS}}
113-
takesHorseExistential(x) // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable in macOS}}
114-
x.giddyUp() // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable in macOS}}
115-
_ = x.isGalloping // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable}}
116-
_ = x[keyPath: \.isGalloping] // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable}}
117-
_ = UsesHorse<HasUnavailableConformance4>.self // expected-error {{conformance of 'HasUnavailableConformance4' to 'Horse' is unavailable in macOS}}
112+
takesHorse(x)
113+
takesHorseExistential(x)
114+
x.giddyUp()
115+
_ = x.isGalloping
116+
_ = x[keyPath: \.isGalloping]
117+
_ = UsesHorse<HasUnavailableConformance4>.self
118118
}
119119

120120
// Swift obsoleted
121121
public struct HasUnavailableConformance5 {}
122122

123123
@available(swift, obsoleted: 4)
124124
extension HasUnavailableConformance5 : Horse {}
125-
// expected-note@-1 12{{conformance of 'HasUnavailableConformance5' to 'Horse' was obsoleted in Swift 4}}
125+
// expected-note@-1 6{{conformance of 'HasUnavailableConformance5' to 'Horse' was obsoleted in Swift 4}}
126126

127127
func passUnavailableConformance5(x: HasUnavailableConformance5) {
128128
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
@@ -135,12 +135,12 @@ func passUnavailableConformance5(x: HasUnavailableConformance5) {
135135

136136
@available(swift, obsoleted: 4)
137137
func passUnavailableConformance5a(x: HasUnavailableConformance5) {
138-
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
139-
takesHorseExistential(x) // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
140-
x.giddyUp() // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
141-
_ = x.isGalloping // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
142-
_ = x[keyPath: \.isGalloping] // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
143-
_ = UsesHorse<HasUnavailableConformance5>.self // expected-error {{conformance of 'HasUnavailableConformance5' to 'Horse' is unavailable}}
138+
takesHorse(x)
139+
takesHorseExistential(x)
140+
x.giddyUp()
141+
_ = x.isGalloping
142+
_ = x[keyPath: \.isGalloping]
143+
_ = UsesHorse<HasUnavailableConformance5>.self
144144
}
145145

146146
// Unavailable with message

test/Availability/property_wrapper_availability.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct DeprecatedWrapper<T> {
2323

2424
@available(*, unavailable)
2525
@propertyWrapper
26-
struct UnavailableWrapper<T> { // expected-note 8 {{'UnavailableWrapper' has been explicitly marked unavailable here}}
26+
struct UnavailableWrapper<T> { // expected-note 12 {{'UnavailableWrapper' has been explicitly marked unavailable here}}
2727
var wrappedValue: T
2828
}
2929

@@ -113,8 +113,8 @@ struct UnavailableOnMacOSStruct {
113113
@DeprecatedWrapper var deprecatedExplicit: S
114114
@DeprecatedWrapper var deprecatedInferred = S()
115115

116-
@UnavailableWrapper var unavailableExplicit: S
117-
@UnavailableWrapper var unavailableInferred = S()
116+
@UnavailableWrapper var unavailableExplicit: S // expected-error {{'UnavailableWrapper' is unavailable}}
117+
@UnavailableWrapper var unavailableInferred = S() // expected-error {{'UnavailableWrapper' is unavailable}}
118118

119119
@WrappedValueUnavailableOnMacOS var unavailableWrappedValue: S
120120
@WrappedValueAvailable51 var wrappedValueAavailable51: S
@@ -175,14 +175,14 @@ func unavailableOnMacOSFunc(
175175
@AlwaysAvailableWrapper _ alwaysAvailable: S,
176176
@Available51Wrapper _ available51: S,
177177
@DeprecatedWrapper _ deprecated: S,
178-
@UnavailableWrapper _ unavailable: S,
178+
@UnavailableWrapper _ unavailable: S, // expected-error {{'UnavailableWrapper' is unavailable}}
179179
@WrappedValueUnavailableOnMacOS _ unavailableWrappedValue: S,
180180
@WrappedValueAvailable51 _ wrappedValueAavailable51: S
181181
) {
182182
@AlwaysAvailableWrapper var alwaysAvailableLocal = S()
183183
@Available51Wrapper var available51Local = S()
184184
@DeprecatedWrapper var deprecatedLocal = S()
185-
@UnavailableWrapper var unavailableLocal = S()
185+
@UnavailableWrapper var unavailableLocal = S() // expected-error {{'UnavailableWrapper' is unavailable}}
186186
@WrappedValueUnavailableOnMacOS var unavailableWrappedValueLocal = S()
187187
@WrappedValueAvailable51 var wrappedValueAavailable51 = S()
188188
}

0 commit comments

Comments
 (0)