Skip to content

Commit d281fb8

Browse files
authored
Merge pull request #74883 from finagolfin/droid
[android] Enable several C++ Interop and other tests
2 parents f6844aa + 6ede1c2 commit d281fb8

25 files changed

+31
-56
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
414414

415415

416416
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
417-
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" MATCHES "WINDOWS|ANDROID" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8))
417+
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8))
418418
# In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
419-
# On Windows and Android, to workaround a build problem.
419+
# On Windows, to workaround a build problem.
420420
# If the host Swift version is less than 5.8, use pure mode to workaround a C++ interop compiler crash.
421421
set(BRIDGING_MODE "PURE")
422422
else()

docs/Android.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ Swift-to-Java bridging.
3131
To follow along with this guide, you'll need:
3232

3333
1. A Linux environment capable of building Swift from source, preferably
34-
Ubuntu 20.04 or Ubuntu 18.04. Before attempting to build for Android,
34+
Ubuntu 22.04 or Ubuntu 20.04. Before attempting to build for Android,
3535
please make sure you are able to build for Linux by following the
3636
instructions in the Swift project README.
3737
2. The latest build of the Swift compiler for your Linux distro, available at
3838
https://www.swift.org/download/ or sometimes your distro package manager.
39-
3. The latest version of the Android LTS NDK (r26c at the time of this writing),
39+
3. The latest version of the Android LTS NDK (r26d at the time of this writing),
4040
available to download here:
4141
https://developer.android.com/ndk/downloads
4242
4. An Android device with remote debugging enabled or the emulator. We require
@@ -54,9 +54,9 @@ and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
5454
have a Swift toolchain in your path):
5555

5656
```
57-
$ NDK_PATH=path/to/android-ndk-r26c
58-
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
59-
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a
57+
$ NDK_PATH=path/to/android-ndk-r26d
58+
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-07-09-a-ubuntu22.04/usr/bin
59+
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2024-07-09-a
6060
$ utils/build-script \
6161
-R \ # Build in ReleaseAssert mode.
6262
--android \ # Build for Android.
@@ -83,8 +83,8 @@ Then use the standalone Swift stdlib from the previous step to compile a Swift
8383
source file, targeting Android:
8484

8585
```
86-
$ NDK_PATH="path/to/android-ndk-r26c"
87-
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
86+
$ NDK_PATH="path/to/android-ndk-r26d"
87+
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-07-09-a-ubuntu22.04/usr/bin
8888
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
8989
# The location of the tools used to build Android binaries
9090
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
@@ -133,7 +133,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
133133
In addition, you'll also need to copy the Android NDK's libc++:
134134

135135
```
136-
$ adb push /path/to/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
136+
$ adb push /path/to/android-ndk-r26d/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
137137
```
138138

139139
Finally, you'll need to copy the `hello` executable you built in the
@@ -176,8 +176,8 @@ $ utils/build-script \
176176
-R \ # Build in ReleaseAssert mode.
177177
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
178178
--android \ # Build for Android.
179-
--android-ndk ~/android-ndk-r26c \ # Path to an Android NDK.
180-
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7
179+
--android-ndk ~/android-ndk-r26d \ # Path to an Android NDK.
180+
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7 or x86_64
181181
--android-api-level 21
182182
```
183183

test/Concurrency/Runtime/actor_assert_precondition_executor_checkIsolated_dispatch_dispatchMain_swift_6_mode.swift

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Darwin
2222
import Glibc
2323
#elseif canImport(Musl)
2424
import Musl
25+
#elseif canImport(Android)
26+
import Android
2527
#endif
2628

2729
@main struct Main {

test/Interop/Cxx/class/custom-new-operator-irgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// RUN: %target-swiftxx-frontend -I %S/Inputs %s -emit-ir | %FileCheck %s
22

3-
// XFAIL: OS=linux-android, OS=linux-androideabi
4-
53
import CustomNewOperator
64

75
var x = callsCustomNew()

test/Interop/Cxx/class/memory-layout-silgen.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-ir -o - %s | %FileCheck %s
22

3-
// XFAIL: OS=linux-android
4-
// XFAIL: OS=linux-androideabi
5-
63
import MemoryLayout
74

85
var v = PrivateMemberLayout()

test/Interop/Cxx/foreign-reference/move-only-irgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-experimental-cxx-interop -validate-tbd-against-ir=none -disable-llvm-verify -Xcc -fignore-exceptions -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import MoveOnly
64

test/Interop/Cxx/foreign-reference/move-only-module-interface.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=MoveOnly -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
// CHECK: class MoveOnly {
64
// CHECK-NOT: init

test/Interop/Cxx/foreign-reference/move-only-silgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-silgen %s -I %S/Inputs -enable-experimental-cxx-interop -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import MoveOnly
64

test/Interop/Cxx/foreign-reference/nullable-module-interface.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=Nullable -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
// CHECK: class Empty {
64
// CHECK: func test() -> Int32

test/Interop/Cxx/foreign-reference/pod-irgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-experimental-cxx-interop -validate-tbd-against-ir=none -disable-llvm-verify -Xcc -fignore-exceptions -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import POD
64

test/Interop/Cxx/foreign-reference/pod-module-interface.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=POD -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
// CHECK: class Empty {
64
// CHECK-NOT: init

test/Interop/Cxx/foreign-reference/pod-silgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-silgen %s -I %S/Inputs -enable-experimental-cxx-interop -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import POD
64

test/Interop/Cxx/foreign-reference/reference-counted-irgen.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-emit-irgen %s -I %S/Inputs -cxx-interoperability-mode=default -Xcc -fignore-exceptions -disable-availability-checking | %FileCheck %s
2-
// XFAIL: OS=linux-android, OS=linux-androideabi
32
// XFAIL: OS=windows-msvc
43

54
import ReferenceCounted

test/Interop/Cxx/foreign-reference/reference-counted-silgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-silgen %s -I %S/Inputs -enable-experimental-cxx-interop -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import POD
64
import ReferenceCounted

test/Interop/Cxx/foreign-reference/singleton-irgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-experimental-cxx-interop -validate-tbd-against-ir=none -disable-llvm-verify -Xcc -fignore-exceptions -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import Singleton
64

test/Interop/Cxx/foreign-reference/singleton-module-interface.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=Singleton -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
// CHECK: class DeletedDtor {
64
// CHECK-NOT: init

test/Interop/Cxx/foreign-reference/singleton-silgen.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %target-swift-emit-silgen %s -I %S/Inputs -enable-experimental-cxx-interop -disable-availability-checking | %FileCheck %s
2-
//
3-
// XFAIL: OS=linux-android, OS=linux-androideabi
42

53
import Singleton
64

test/Interop/SwiftToCxx/core/unsigned-return-type-no-zext.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: %FileCheck %s < %t/ir.ll
55

66
// UNSUPPORTED: OS=windows-msvc
7-
// XFAIL: OS=linux-android, OS=linux-androideabi
87

98
unsigned char getEnumTagi8(void *p);
109
unsigned getEnumTagi32(void *p);

test/Interop/SwiftToCxx/stdlib/stdlib-in-cxx-no-diagnostics-generated-header.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
// RUN: %target-interop-build-clangxx -std=gnu++20 -fsyntax-only -c %t/test-stdlib.cpp -I %t -Wall -Werror -Werror=ignored-attributes -Wno-error=unused-command-line-argument
99

10-
// XFAIL: OS=linux-android, OS=linux-androideabi
11-
1210
//--- print-string.swift
1311

1412
public func printString(_ s: String) {

test/Interop/SwiftToCxxToSwift/hide-swift-module-namespace-in-swift.swift

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftToCxxTest -I %t -source-filename=x -enable-experimental-cxx-interop -Xcc -DSWIFT_CXX_INTEROP_HIDE_SWIFT_ERROR | %FileCheck --check-prefix=INTERFACE %s
1313

14-
// XFAIL: OS=linux-android, OS=linux-androideabi
15-
1614
//--- header.h
1715
#ifndef FIRSTPASS
1816
#include "swiftMod.h"

test/Interop/SwiftToCxxToSwift/import-swift-class-back-to-swift.swift

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// RUN: %target-swift-frontend -typecheck %t/swiftMod.swift -typecheck -module-name SwiftMod -I %t -enable-experimental-cxx-interop -Xcc -DSWIFT_CXX_INTEROP_HIDE_SWIFT_ERROR -DSECOND_PASS -emit-sil -o - | %FileCheck --check-prefix=SIL %s
1111

1212
// UNSUPPORTED: OS=windows-msvc
13-
// XFAIL: OS=linux-android, OS=linux-androideabi
1413

1514
//--- header.h
1615
#ifndef FIRSTPASS

test/Interpreter/llvm_link_time_opt.swift

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// UNSUPPORTED: OS=windows-msvc
22
// static library is not well supported yet on Windows
33

4-
// XFAIL: OS=linux-android, OS=linux-androideabi
5-
64
// UNSUPPORTED: OS=xros
75

86
// For LTO, the linker dlopen()'s the libLTO library, which is a scenario that

test/lit.cfg

+14-5
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ if platform.system() == 'Darwin':
177177
# NOTE: this mirrors the kIsWindows from lit.lit.TestRunner in LLVM
178178
kIsWindows = platform.system() == 'Windows'
179179

180+
# The global environment in Android sets ANDROID_DATA, so if that variable is
181+
# set, we are probably running in Android.
182+
kIsAndroid = 'ANDROID_DATA' in os.environ
183+
180184
# testFormat: The test format to use to interpret tests.
181185

182186
# Choose between lit's internal shell pipeline runner and a real shell. If
@@ -428,6 +432,11 @@ if run_os.startswith('wasi'):
428432
# Parse the host triple
429433
(host_cpu, host_vendor, host_os, host_vers) = re.match('([^-]+)-([^-]+)-([^0-9-]+)(.*)', config.host_triple).groups()
430434

435+
# Manually set the host OS on Android, because the host OS from the triple says
436+
# `linux`.
437+
if kIsAndroid:
438+
host_os = 'android'
439+
431440
if f"{host_cpu}-{host_vendor}-{host_os}" == f"{run_cpu}-{run_vendor}-{run_os}":
432441
# Ignore the version on purpose, to account for scenario
433442
# in which the compiler has a different deployment target
@@ -1129,10 +1138,6 @@ elif platform.system() == 'Linux':
11291138
if swift_test_mode != 'only_non_executable':
11301139
config.available_features.add('swift_interpreter')
11311140

1132-
# The global environment in Android sets ANDROID_DATA, so if that variable is
1133-
# set, we are probably running in Android.
1134-
kIsAndroid = 'ANDROID_DATA' in os.environ
1135-
11361141
# swift-remoteast-test requires the ability to compile and run code
11371142
# for the system we compiled the swift-remoteast-test executable on.
11381143
# This is potentially a stronger constraint than just "can we interpret",
@@ -2470,8 +2475,12 @@ elif not kIsWindows and not run_os == 'wasi':
24702475
lit_config.note('Testing with the just-built libraries')
24712476

24722477
lit_config.note('Library load path: {0}'.format(os.path.pathsep.join(target_stdlib_path)))
2478+
env_path = "/usr/bin/env "
2479+
# Android doesn't have /usr/bin/
2480+
if kIsAndroid:
2481+
env_path = "/bin/env "
24732482
config.target_run = (
2474-
"/usr/bin/env " +
2483+
env_path +
24752484
construct_library_path_env(target_stdlib_path) +
24762485
config.target_run)
24772486

utils/build_swift/build_swift/driver_arguments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ def create_argument_parser():
13931393

13941394
option('--android-arch', store,
13951395
choices=['armv7', 'aarch64', 'x86_64'],
1396-
default='armv7',
1396+
default='aarch64',
13971397
help='The target architecture when building for Android. '
13981398
'Currently, only armv7, aarch64, and x86_64 are supported. '
13991399
'%(default)s is the default.')

utils/build_swift/tests/expected_options.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
'android_api_level': '21',
4242
'android_deploy_device_path': '/data/local/tmp',
4343
'android_ndk': None,
44-
'android_arch': 'armv7',
44+
'android_arch': 'aarch64',
4545
'assertions': True,
4646
'benchmark': False,
4747
'benchmark_num_o_iterations': 3,
@@ -764,7 +764,7 @@ class BuildScriptImplOption(_BaseOption):
764764
ChoicesOption('--swift-analyze-code-coverage',
765765
choices=['false', 'not-merged', 'merged']),
766766
ChoicesOption('--android-arch',
767-
choices=['armv7', 'aarch64']),
767+
choices=['armv7', 'aarch64', 'x86_64']),
768768

769769
StrOption('--android-api-level'),
770770
StrOption('--build-args'),

0 commit comments

Comments
 (0)