Skip to content

[pull] swiftwasm from main #4631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ce6005d
[Concurrency] fix grammatically incorrect phrase
Jager-yoo Jun 4, 2022
0772f68
Sema: Fix operator function witness lookup for local adoptees
AnthonyLatsis Jun 3, 2022
1431b6f
Add regression test to close #44672
AnthonyLatsis Jun 5, 2022
0e9a3cb
Add regression test to close #45389
AnthonyLatsis Jun 5, 2022
4bcb371
Add regression test to close #56100
AnthonyLatsis Jun 5, 2022
927d099
Add regression test to close #52024
AnthonyLatsis Jun 6, 2022
f03274b
Add regression test to close #51217
AnthonyLatsis Jun 6, 2022
9d5a7a5
[android] Update to LTS NDK 23c
finagolfin Jun 6, 2022
94796e0
Add regression test to close #52588
AnthonyLatsis Jun 6, 2022
ffb37ed
Inline the Swift 5.6 concurrency library as a separate back-deploy li…
DougGregor Jun 6, 2022
588a1eb
Ensure that we enabled override hooks in the concurrency back-deploym…
DougGregor Jun 6, 2022
7a11b43
Merge pull request #59271 from AnthonyLatsis/sr-2063
AnthonyLatsis Jun 6, 2022
6de3268
Sema: Diagnose `@_backDeploy` attributes on initializers and deinitia…
tshortli Jun 6, 2022
65a30d2
Merge pull request #59270 from Jager-yoo/fix-grammatical-incorrection
amartini51 Jun 6, 2022
7589520
Make back-deployed concurrency library testable on OS's that have the…
DougGregor Jun 6, 2022
b43e864
Generalize tests for Apple Silicon
DougGregor Jun 6, 2022
0fe2d7b
Merge pull request #59282 from DougGregor/back-deploy-concurrency-reb…
DougGregor Jun 6, 2022
e63df1e
Merge pull request #59283 from tshortli/diagnose-back-deploy-on-init-…
tshortli Jun 6, 2022
e365fd1
Tests: Mark test/stdlib/StringCreate.swift as unsupported on back dep…
tshortli Jun 7, 2022
de2394d
Merge pull request #59246 from AnthonyLatsis/local-conformance-operator
AnthonyLatsis Jun 7, 2022
cfcef44
Merge pull request #59286 from DougGregor/back-deploy-concurrency-on-…
DougGregor Jun 7, 2022
e5b149e
Merge pull request #59289 from tshortli/string-create-tests-unsupport…
swift-ci Jun 7, 2022
aff121b
Merge pull request #59281 from buttaface/ndk-23c
swift-ci Jun 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING

set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.8" CACHE STRING
set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.9" CACHE STRING
"The Clang version to use when building for Android.")
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
Expand Down
65 changes: 42 additions & 23 deletions docs/Android.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Getting Started with Swift on Android

The Swift stdlib can be compiled for Android armv7, x86_64, and aarch64 targets,
which makes it possible to execute Swift code on a mobile device running
Android or an emulator. This guide explains:
The Swift standard library (stdlib) can be compiled for Android armv7, x86_64,
and aarch64 targets, which makes it possible to execute Swift code on a mobile
device running Android or an emulator. This guide explains:

1. How to run a simple "Hello, world" program on your Android device.
2. How to run the Swift test suite on an Android device.
Expand All @@ -12,7 +12,7 @@ bug using https://bugs.swift.org/.

## FAQ

Let's answer a few frequently asked questions right off the bat:
Let's answer a frequently asked question right off the bat:

### Does this mean I can write Android applications in Swift?

Expand All @@ -30,32 +30,44 @@ Swift-to-Java bridging.
To follow along with this guide, you'll need:

1. A Linux environment capable of building Swift from source, preferably
Ubuntu 18.04 or Ubuntu 16.04. Before attempting to build for Android,
Ubuntu 20.04 or Ubuntu 18.04. Before attempting to build for Android,
please make sure you are able to build for Linux by following the
instructions in the Swift project README.
2. The latest version of the Android NDK (r23b at the time of this writing),
2. The latest build of the Swift compiler for your Linux distro, available at
https://www.swift.org/download/ or sometimes your distro package manager.
3. The latest version of the Android LTS NDK (r23c at the time of this writing),
available to download here:
https://developer.android.com/ndk/downloads/index.html.
3. An Android device with remote debugging enabled or the emulator. We require
https://developer.android.com/ndk/downloads
4. An Android device with remote debugging enabled or the emulator. We require
remote debugging in order to deploy built stdlib products to the device. You
may turn on remote debugging by following the official instructions:
https://developer.chrome.com/devtools/docs/remote-debugging.
https://developer.chrome.com/devtools/docs/remote-debugging .

## "Hello, world" on Android

### 1. Building the Swift stdlib for Android
### 1. Building the standalone Swift stdlib for Android

Enter your Swift directory, then run the build script, passing the path to the
Android NDK:
Enter your Swift directory, check out the tag corresponding to the prebuilt
Swift compiler, then run the build script, passing the path to the Android NDK
and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
have a Swift toolchain in your path):

```
$ NDK_PATH=path/to/android-ndk-r23b
$ NDK_PATH=path/to/android-ndk-r23c
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2022-05-31-a-ubuntu20.04/usr/bin
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2022-05-31-a
$ utils/build-script \
-R \ # Build in ReleaseAssert mode.
--android \ # Build for Android.
--android-ndk $NDK_PATH \ # Path to an Android NDK.
--android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64 or x86_64
--android-api-level 21 # The Android API level to target. Swift only supports 21 or greater.
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7 or x86_64
--android-api-level 21 \ # The Android API level to target. Swift only supports 21 or greater.
--stdlib-deployment-targets=android-aarch64 \ # Only cross-compile the stdlib for Android, ie don't build the native stdlib for Linux
--native-swift-tools-path=$SWIFT_PATH \ # Path to your prebuilt Swift compiler
--native-clang-tools-path=$SWIFT_PATH \ # Path to a prebuilt clang compiler, one comes with the Swift toolchain
--build-swift-tools=0 \ # Don't build the Swift compiler and other host tools
--build-llvm=0 \ # Don't build the LLVM libraries, but generate some CMake files needed by the Swift stdlib build
--skip-build-cmark # Don't build the CommonMark library that's only needed by the Swift compiler
```

### 2. Compiling `hello.swift` to run on an Android device
Expand All @@ -66,15 +78,16 @@ Create a simple Swift file named `hello.swift`:
print("Hello, Android")
```

Then use the built Swift compiler from the previous step to compile a Swift
Then use the standalone Swift stdlib from the previous step to compile a Swift
source file, targeting Android:

```
$ NDK_PATH="path/to/android-ndk-r23b"
$ build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc \ # The Swift compiler built in the previous step
$ NDK_PATH="path/to/android-ndk-r23c"
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2022-05-31-a-ubuntu20.04/usr/bin
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
# The location of the tools used to build Android binaries
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
-target armv7-unknown-linux-androideabi21 \ # Targeting Android armv7 at API 21
-target aarch64-unknown-linux-android21 \ # Targeting Android aarch64 at API 21
-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.
-resource-dir build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift
hello.swift
Expand Down Expand Up @@ -111,12 +124,15 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswi
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswiftGlibc.so /data/local/tmp
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswiftSwiftOnoneSupport.so /data/local/tmp
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswiftRemoteMirror.so /data/local/tmp
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswift_Concurrency.so /data/local/tmp
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libdispatch.so /data/local/tmp
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlocksRuntime.so /data/local/tmp
```

In addition, you'll also need to copy the Android NDK's libc++:

```
$ adb push /path/to/android-ndk-r23b/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp
$ adb push /path/to/android-ndk-r23c/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp
```

Finally, you'll need to copy the `hello` executable you built in the
Expand Down Expand Up @@ -157,9 +173,12 @@ device. As in part three, you'll need to connect your Android device via USB:
```
$ utils/build-script \
-R \ # Build in ReleaseAssert mode.
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the linux host).
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
--android \ # Build for Android.
--android-ndk ~/android-ndk-r23b \ # Path to an Android NDK.
--android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64
--android-ndk ~/android-ndk-r23c \ # Path to an Android NDK.
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7
--android-api-level 21
```

This will build the Swift compiler and other host tools first, so expect a much
longer build.
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,9 @@ WARNING(access_control_non_objc_open_member,none,

ERROR(invalid_decl_attribute,none,
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
ERROR(attr_invalid_on_decl_kind,none,
"'%0' attribute cannot be applied to %1 declarations",
(DeclAttribute, DescriptiveDeclKind))
ERROR(invalid_decl_modifier,none,
"%0 modifier cannot be applied to this declaration", (DeclAttribute))
ERROR(attribute_does_not_apply_to_type,none,
Expand Down
19 changes: 0 additions & 19 deletions include/swift/SIL/SILNodes.def.rej

This file was deleted.

6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3662,6 +3662,12 @@ void AttributeChecker::checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs) {
}
}

if (isa<DestructorDecl>(D) || isa<ConstructorDecl>(D)) {
diagnoseAndRemoveAttr(Attr, diag::attr_invalid_on_decl_kind, Attr,
D->getDescriptiveKind());
continue;
}

auto AtLoc = Attr->AtLoc;
auto Platform = Attr->Platform;

Expand Down
34 changes: 27 additions & 7 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,25 +1315,41 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {
auto reqName = req->createNameRef();
auto reqBaseName = reqName.withoutArgumentLabels();

if (req->isOperator()) {
// Operator lookup is always global.
// An operator function is the only kind of witness that requires global
// lookup. However, because global lookup doesn't enter local contexts,
// an additional, qualified lookup is warranted when the conforming type
// is declared in a local context.
const bool doUnqualifiedLookup = req->isOperator();
const bool doQualifiedLookup =
!req->isOperator() || DC->getParent()->getLocalContext();

if (doUnqualifiedLookup) {
auto lookup = TypeChecker::lookupUnqualified(DC->getModuleScopeContext(),
reqBaseName, SourceLoc(),
defaultUnqualifiedLookupOptions);
for (auto candidate : lookup) {
auto decl = candidate.getValueDecl();
if (swift::isMemberOperator(cast<FuncDecl>(decl), Adoptee)) {
if (!isa<ProtocolDecl>(decl->getDeclContext()) &&
swift::isMemberOperator(cast<FuncDecl>(decl), Adoptee)) {
witnesses.push_back(decl);
}
}
} else {
// Variable/function/subscript requirements.
}

if (doQualifiedLookup) {
auto *nominal = Adoptee->getAnyNominal();
nominal->synthesizeSemanticMembersIfNeeded(reqName.getFullName());

// Unqualified lookup would have already found candidates from protocol
// extensions, including those that match only by base name. Take care not
// to restate them in the resulting list, or else an otherwise valid
// conformance will become ambiguous.
const NLOptions options =
doUnqualifiedLookup ? NLOptions(0) : NL_ProtocolMembers;

SmallVector<ValueDecl *, 4> lookupResults;
bool addedAny = false;
DC->lookupQualified(nominal, reqName, NL_ProtocolMembers, lookupResults);
DC->lookupQualified(nominal, reqName, options, lookupResults);
for (auto *decl : lookupResults) {
if (!isa<ProtocolDecl>(decl->getDeclContext())) {
witnesses.push_back(decl);
Expand All @@ -1345,7 +1361,7 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {
// again using only the base name.
if (!addedAny && ignoringNames) {
lookupResults.clear();
DC->lookupQualified(nominal, reqBaseName, NL_ProtocolMembers, lookupResults);
DC->lookupQualified(nominal, reqBaseName, options, lookupResults);
for (auto *decl : lookupResults) {
if (!isa<ProtocolDecl>(decl->getDeclContext()))
witnesses.push_back(decl);
Expand All @@ -1358,6 +1374,10 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {
removeShadowedDecls(witnesses, DC);
}

assert(llvm::none_of(witnesses, [](ValueDecl *decl) {
return isa<ProtocolDecl>(decl->getDeclContext());
}));

return witnesses;
}

Expand Down
Loading