Skip to content

[6.2][android] Fix the remaining tests and add a build flag that enables standalone cross-compilation SDKs #82186

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

Open
wants to merge 7 commits into
base: release/6.2
Choose a base branch
from

Conversation

finagolfin
Copy link
Member

Explanation: Fix several tests for Android and add a build-script flag that makes it possible to only build the Swift compiler for the host while disabling cross-compiling the Swift compiler, to efficiently build cross-compilation toolchains.

Scope: Tweak some tests and add a currently unused build flag

Issue: #78350

Original PR: #81398, #81643, #81695, #81841, #81312, #38441, #82163

Risk: None, only affects tests

Testing: Got the community Android CI, which builds trunk regularly, green again last month, and I fixed up some tests that broke other Darwin CI in subsequent pulls listed above.

Reviewer: @compnerd

The Swift core team tasked the Swift on Android workgroup with putting together an official 6.2 Android CI job, so @marcprux and I have been piecing together a pull for that, swift-android-sdk/swift-docker#8, and these are the trunk patches we had to backport to 6.2 so far. Once the remaining patches there have been reworked and merged to trunk, I will submit another 6.2 pull later on with those final patches. The new build flag will be used by these new Android CI.

finagolfin and others added 7 commits June 11, 2025 21:52
…roid CI (swiftlang#81398)

Also, fix and enable `IRGen/lto_autolink` for all non-Wasm targets and
`IRGen/static_initializer` for aarch64.

This should get [the community Android
CI](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-build/)
green
[again](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-arm64/).
…g#81643)

which generates IR without a llvm.trap function

All the normal CI generated this:
```
ret i32 %1
}

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #1

attributes #0 = { "frame-pointer"=
```
But the test-simulator CI doesn't for some reason, so just check for the
closing brace instead.
[test] Fix IRGen/lto_autolink on Darwin arm64 platforms too
Tests are failing with:

<unknown>:0: error: unknown target triple 'arm64_32-unknown-linux-gnu'
<unknown>:0: error: clang importer creation failed
…itly adding the sysroot and target triple (swiftlang#81312)

@weliveindetail noticed that these header checks when cross-compiling
are incorrectly checked against the host C and C++ headers and target,
so he added the cross-compilation sysroot for the C++ header check alone
more than a month ago in swiftlang#79185. However, that broke several C++ Interop
tests when running the compiler validation suite for Android on both
[the Windows toolchain
CI](https://ci-external.swift.org/job/swift-main-windows-toolchain/) and
[the community Android CI on a linux
host](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-arm64/):
```
FAIL: Swift(android-x86_64) :: Interop/SwiftToCxx/class/nested-classes-in-cxx.swift (4495 of 18856)
******************** TEST 'Swift(android-x86_64) :: Interop/SwiftToCxx/class/nested-classes-in-cxx.swift' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
rm -rf "T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp" && mkdir -p "T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp"
# executed command: rm -rf 'T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp'
# executed command: mkdir -p 'T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp'
# RUN: at line 2
t:\5\bin\swift-frontend.exe -target x86_64-unknown-linux-android -sdk T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot -resource-dir T:/x86_64-unknown-linux-android28/Runtime/./lib/swift -module-cache-path T:\x86_64-unknown-linux-android28\Runtime\swift-test-results\x86_64-unknown-linux-android\clang-module-cache -swift-version 4  -define-availability 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'SwiftStdlib 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'SwiftStdlib 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'SwiftStdlib 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftCompatibilitySpan 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1' -define-availability 'SwiftCompatibilitySpan 6.2:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -typo-correction-limit 10  C:\Users\swift-ci\jenkins\workspace\swift-main-windows-toolchain\swift\test\Interop\SwiftToCxx\class\nested-classes-in-cxx.swift -enable-library-evolution -typecheck -module-name Classes -clang-header-expose-decls=all-public -emit-clang-header-path T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h
# executed command: 't:\5\bin\swift-frontend.exe' -target x86_64-unknown-linux-android -sdk T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot -resource-dir T:/x86_64-unknown-linux-android28/Runtime/./lib/swift -module-cache-path 'T:\x86_64-unknown-linux-android28\Runtime\swift-test-results\x86_64-unknown-linux-android\clang-module-cache' -swift-version 4 -define-availability 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'SwiftStdlib 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'SwiftStdlib 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'SwiftStdlib 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftCompatibilitySpan 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1' -define-availability 'SwiftCompatibilitySpan 6.2:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -typo-correction-limit 10 'C:\Users\swift-ci\jenkins\workspace\swift-main-windows-toolchain\swift\test\Interop\SwiftToCxx\class\nested-classes-in-cxx.swift' -enable-library-evolution -typecheck -module-name Classes -clang-header-expose-decls=all-public -emit-clang-header-path 'T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h'
# RUN: at line 3
't:\\5\\bin\\clang++.exe' -fmodules-cache-path='T:\\x86_64-unknown-linux-android28\\Runtime\\swift-test-results\\x86_64-unknown-linux-android\\clang-module-cache' -fsyntax-only -x c++-header -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -Wno-auto-import -Wno-variadic-macros -Wno-c++98-compat-pedantic -Wno-poison-system-directories -Wno-unused-command-line-argument -Wno-nullability-extension  --sysroot 'T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot' -F 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-main-windows-toolchain\\swift\\test\\Inputs\\clang-importer-sdk'/frameworks -I T:\x86_64-unknown-linux-android28\LLVM\include  -isysroot 'C:/Users/swift-ci/jenkins/workspace/swift-main-windows-toolchain/swift\\test'/Inputs/clang-importer-sdk -std=c++14 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB -IT:/x86_64-unknown-linux-android28/Runtime/./lib/swift T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -std=c++17 && 't:\\5\\bin\\clang++.exe' -fmodules-cache-path='T:\\x86_64-unknown-linux-android28\\Runtime\\swift-test-results\\x86_64-unknown-linux-android\\clang-module-cache' -fsyntax-only -x c++-header -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -Wno-auto-import -Wno-variadic-macros -Wno-c++98-compat-pedantic -Wno-poison-system-directories -Wno-unused-command-line-argument -Wno-nullability-extension  --sysroot 'T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot' -F 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-main-windows-toolchain\\swift\\test\\Inputs\\clang-importer-sdk'/frameworks -I T:\x86_64-unknown-linux-android28\LLVM\include  -isysroot 'C:/Users/swift-ci/jenkins/workspace/swift-main-windows-toolchain/swift\\test'/Inputs/clang-importer-sdk -std=c++17 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB -IT:/x86_64-unknown-linux-android28/Runtime/./lib/swift T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -std=c++17 && 't:\\5\\bin\\clang++.exe' -fmodules-cache-path='T:\\x86_64-unknown-linux-android28\\Runtime\\swift-test-results\\x86_64-unknown-linux-android\\clang-module-cache' -fsyntax-only -x c++-header -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -Wno-auto-import -Wno-variadic-macros -Wno-c++98-compat-pedantic -Wno-poison-system-directories -Wno-unused-command-line-argument -Wno-nullability-extension  --sysroot 'T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot' -F 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-main-windows-toolchain\\swift\\test\\Inputs\\clang-importer-sdk'/frameworks -I T:\x86_64-unknown-linux-android28\LLVM\include  -isysroot 'C:/Users/swift-ci/jenkins/workspace/swift-main-windows-toolchain/swift\\test'/Inputs/clang-importer-sdk -std=c++20 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB -IT:/x86_64-unknown-linux-android28/Runtime/./lib/swift T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -std=c++17
# executed command: 't:\\5\\bin\\clang++.exe' '-fmodules-cache-path=T:\\x86_64-unknown-linux-android28\\Runtime\\swift-test-results\\x86_64-unknown-linux-android\\clang-module-cache' -fsyntax-only -x c++-header -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -Wno-auto-import -Wno-variadic-macros -Wno-c++98-compat-pedantic -Wno-poison-system-directories -Wno-unused-command-line-argument -Wno-nullability-extension --sysroot T:/android-ndk-r27c/toolchains/llvm/prebuilt/windows-x86_64/sysroot -F 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-main-windows-toolchain\\swift\\test\\Inputs\\clang-importer-sdk/frameworks' -I 'T:\x86_64-unknown-linux-android28\LLVM\include' -isysroot 'C:/Users/swift-ci/jenkins/workspace/swift-main-windows-toolchain/swift\\test/Inputs/clang-importer-sdk' -std=c++14 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB -IT:/x86_64-unknown-linux-android28/Runtime/./lib/swift 'T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h' -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -std=c++17
# .---command stderr------------
# | T:\x86_64-unknown-linux-android28\Runtime\test-android-x86_64\Interop\SwiftToCxx\class\Output\nested-classes-in-cxx.swift.tmp/classes.h:29:10: fatal error: 'cstdint' file not found
# |    29 | #include <cstdint>
# |       |          ^~~~~~~~~
# | 1 error generated.
# `-----------------------------
# error: command failed with exit status: 1
```
I experimented a bit and found that explicitly passing in the target
triple fixed these tests, so this pull does that for C++ and also
corrects the C header check.
… cross-compiling the compiler (swiftlang#38441)

This is useful when building cross-compilation toolchains where you want
the stdlib and corelibs cross-compiled but don't want the Swift compiler
cross-compiled too with `--cross-compile-hosts`.
…hen cross-compiling Foundation macros (swiftlang#82163)

Follow-on to swiftlang#38441, missed this there.
@finagolfin finagolfin requested a review from a team as a code owner June 11, 2025 17:13
@finagolfin finagolfin added Android Platform: Android 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Jun 11, 2025
@finagolfin
Copy link
Member Author

@swift-ci test

@@ -1,16 +1,8 @@
// REQUIRES: CPU=x86_64
// REQUIRES: OS=macosx || OS=ios || OS=tvos || OS=watchos, CPU=x86_64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cherry-pick, so this is fine, but I think that we can compress this to REQUIRES: VENDOR=apple.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will look at updating that in a subsequent trunk pull.

@xavgru12
Copy link

How does disabling cross-compiling the Swift compiler enable building cross-compilation toolchains efficiently?

@finagolfin
Copy link
Member Author

Simple, a cross-compilation toolchain requires a Swift compiler built for the host and SDKs, consisting of the stdlib and corelibs like Foundation or XCTest, cross-compiled for other platforms than the host platform.

However, the build-script used on non-Windows platforms doesn't really support that and builds everything for every platform specified- Windows has its own Powershell script build.ps1 which supports building such cross-compilation SDKs better- meaning it either builds the Swift compiler itself for every platform specified or none.

This new build flag allows disabling cross-compiling the Swift compiler and various macros, while still building and using them on the host, thus making putting together cross-compilation toolchains take much less time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Platform: Android 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants