Skip to content

Commit 6d5309a

Browse files
committed
[android] Modify test scripts for aarch64 and modern NDKs.
Many places on the testing scripts for Android have the ARMv7 architecture hardcoded. Modify all those instances to support both ARMv7 and AArch64. Besides the paths being modified depending on the architecture, the script is also modified to adapt to NDK beyond r14, where the headers are not under the SDK root, but under a unified sysroot. Two new include paths are passed to the compiler invocations (one the general one, one the architecture specific one). In order to link correctly, the -tools-directory is passed to the Swift compiler invocation. In order to use a modern linker, the selected linker in the CMake script is written in the lit.site.cfg.in files. The system will prefer lld, but will fallback to gold. Plain ld will not be used, since it cannot link correctly the binaries. There's a new CMake variable named SWIFT_ANDROID_${ARCH}_ICU_DATA that should point to libicudataswift.so for each architecture. This part of ICU is necessary while running the test in the host, so it needs to be uploaded. Since it is normally side by side with other ICU products, the linker was finding it for free.
1 parent 43e771e commit 6d5309a

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,15 @@ foreach(SDK ${SWIFT_SDKS})
229229
${PYTHON_EXECUTABLE} "${SWIFT_SOURCE_DIR}/utils/android/adb_push_built_products.py"
230230
--ndk "${SWIFT_ANDROID_NDK_PATH}"
231231
--destination "${SWIFT_ANDROID_DEPLOY_DEVICE_PATH}"
232+
--destination-arch "${ARCH}"
232233
# Build products like libswiftCore.so.
233234
"${SWIFTLIB_DIR}/android"
234235
# These two directories may contain the same libraries,
235236
# but upload both to device just in case. Duplicates will be
236237
# overwritten, and uploading doesn't take very long anyway.
237238
"${SWIFT_ANDROID_${ARCH}_ICU_UC}"
238-
"${SWIFT_ANDROID_${ARCH}_ICU_I18N}")
239+
"${SWIFT_ANDROID_${ARCH}_ICU_I18N}"
240+
"${SWIFT_ANDROID_${ARCH}_ICU_DATA}")
239241
endif()
240242
add_custom_target("upload-stdlib${VARIANT_SUFFIX}"
241243
${command_upload_stdlib}

test/lit.cfg

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -930,39 +930,68 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi
930930
"clang++ -target %s %s" %
931931
(config.variant_triple, clang_mcp_opt))
932932
config.target_ld = "ld -L%r" % (make_path(test_resource_dir, config.target_sdk_name))
933-
elif run_os == 'linux-androideabi':
933+
elif run_os == 'linux-androideabi' or run_os == 'linux-android':
934+
def get_architecture_value(**kwargs):
935+
result = kwargs[run_cpu]
936+
if result is None:
937+
if run_cpu == "armv7s" or run_cpu == "armv7k":
938+
result = kwargs["armv7"]
939+
elif run_cpu == "arm64":
940+
result = kwards["aarch64"]
941+
return result
942+
943+
ndk_platform_tuple = get_architecture_value(armv7="armeabi-v7a",
944+
aarch64="arm64-v8a")
945+
ndk_platform_triple = get_architecture_value(armv7="arm-linux-androideabi",
946+
aarch64="aarch64-linux-android")
947+
toolchain_directory_name = "{}-{}".format(ndk_platform_triple, config.android_ndk_gcc_version)
948+
tools_directory = make_path(config.android_ndk_path, "toolchains",
949+
toolchain_directory_name, "prebuilt", "linux-x86_64",
950+
ndk_platform_triple, "bin")
934951
lit_config.note("Testing Android " + config.variant_triple)
935952
config.target_object_format = "elf"
936953
config.target_shared_library_prefix = 'lib'
937954
config.target_shared_library_suffix = ".so"
955+
config.target_swiftmodule_name = get_architecture_value(armv7="arm.swiftmodule",
956+
aarch64="arm64.swiftmodule")
957+
config.target_swiftdoc_name = get_architecture_value(armv7="arm.swiftdoc",
958+
aarch64="arm64.swiftdoc")
938959
config.target_runtime = "native"
939960
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
940961
config.target_sdk_name = "android"
941-
android_linker_opt = "-L {libcxx} -L {libgcc}".format(
962+
android_link_paths_opt = "-L {libcxx} -L {libgcc}".format(
942963
libcxx=make_path(config.android_ndk_path,
943-
"sources", "cxx-stl", "llvm-libc++", "libs",
944-
"armeabi-v7a"),
964+
"sources", "cxx-stl", "llvm-libc++", "libs", ndk_platform_tuple),
945965
libgcc=make_path(config.android_ndk_path,
946-
"toolchains",
947-
"arm-linux-androideabi-{}".format(config.android_ndk_gcc_version),
948-
"prebuilt", "linux-x86_64", "lib", "gcc",
949-
"arm-linux-androideabi",
966+
"toolchains", toolchain_directory_name, "prebuilt",
967+
"linux-x86_64", "lib", "gcc", ndk_platform_triple,
950968
"{}.x".format(config.android_ndk_gcc_version)))
969+
# Since NDK r14 the headers are unified under $NDK_PATH/sysroot, so the -sdk
970+
# switch is not enough. Additionally we have to include both the unified
971+
# sysroot, and the architecture sysroot.
972+
android_include_paths_opt = "-I {sysroot} -I {sysroot_arch}".format(
973+
sysroot=make_path(config.android_ndk_path, "sysroot", "usr", "include"),
974+
sysroot_arch=make_path(config.android_ndk_path, "sysroot", "usr",
975+
"include", ndk_platform_triple))
951976
config.target_build_swift = (
952-
'%s -target %s -sdk %r %s -Xlinker -pie %s %s %s %s %s'
953-
% (config.swiftc, config.variant_triple, config.variant_sdk,
954-
android_linker_opt, resource_dir_opt, mcp_opt,
955-
config.swift_test_options,
977+
'%s -target %s -sdk %r -tools-directory %r %s %s '
978+
'-use-ld=%s %s %s %s %s %s'
979+
% (config.swiftc,
980+
config.variant_triple, config.variant_sdk,
981+
tools_directory, android_include_paths_opt, android_link_paths_opt,
982+
config.android_linker_name,
983+
resource_dir_opt, mcp_opt, config.swift_test_options,
956984
config.swift_driver_test_options, swift_execution_tests_extra_flags))
957985
config.target_codesign = "echo"
958986
config.target_build_swift_dylib = (
959987
"%s -parse-as-library -emit-library -o '\\1'"
960988
% (config.target_build_swift))
961989
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
962990
config.target_swift_frontend = (
963-
'%s -frontend -target %s -sdk %r %s %s %s %s'
991+
'%s -frontend -target %s -sdk %r %s %s %s %s %s %s'
964992
% (config.swift, config.variant_triple, config.variant_sdk,
965-
android_linker_opt, resource_dir_opt, mcp_opt,
993+
android_include_paths_opt, android_link_paths_opt, resource_dir_opt,
994+
mcp_opt, config.swift_test_options,
966995
config.swift_frontend_test_options))
967996
subst_target_swift_frontend_mock_sdk = config.target_swift_frontend
968997
subst_target_swift_frontend_mock_sdk_after = ""
@@ -978,19 +1007,18 @@ elif run_os == 'linux-androideabi':
9781007
subst_target_swift_ide_test_mock_sdk = config.target_swift_ide_test
9791008
subst_target_swift_ide_test_mock_sdk_after = ""
9801009
config.target_swiftc_driver = (
981-
"%s -target %s -sdk %r %s %s %s" %
1010+
"%s -target %s -sdk %r -tools-directory %s %s %s %s -use-ld=%s" %
9821011
(config.swiftc, config.variant_triple, config.variant_sdk,
983-
android_linker_opt, resource_dir_opt, mcp_opt))
1012+
tools_directory, android_link_paths_opt, resource_dir_opt, mcp_opt,
1013+
config.android_linker_name))
9841014
config.target_swift_modulewrap = (
9851015
'%s -modulewrap -target %s' %
9861016
(config.swiftc, config.variant_triple))
9871017
config.target_clang = (
988-
"clang++ -target %s %s" %
989-
(config.variant_triple, clang_mcp_opt))
1018+
"clang++ -target %s %s %s" %
1019+
(config.variant_triple, clang_mcp_opt, android_include_paths_opt))
9901020
config.target_ld = "{} -L{}".format(
991-
make_path(config.android_ndk_path, 'toolchains',
992-
'arm-linux-androideabi-{}'.format(config.android_ndk_gcc_version),
993-
'prebuilt', 'linux-x86_64', 'arm-linux-androideabi', 'bin'),
1021+
tools_directory,
9941022
make_path(test_resource_dir, config.target_sdk_name))
9951023
# The Swift interpreter is not available when targeting Android.
9961024
config.available_features.remove('swift_interpreter')

test/lit.site.cfg.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ if "@SWIFT_BUILD_SYNTAXPARSERLIB@" == "TRUE":
9191
if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
9292
config.available_features.add('sourcekit')
9393

94+
if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
95+
config.android_linker_name = "lld"
96+
else:
97+
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
98+
config.android_linker_name = "gold"
99+
94100
# Let the main config do the real work.
95101
if config.test_exec_root is None:
96102
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))

validation-test/lit.site.cfg.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ if "@CMAKE_GENERATOR@" == "Xcode":
8080

8181
config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")
8282

83+
if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
84+
config.android_linker_name = "lld"
85+
else:
86+
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
87+
config.android_linker_name = "gold"
88+
8389
# Let the main config do the real work.
8490
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
8591
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/validation-test/lit.cfg")
86-

0 commit comments

Comments
 (0)