Skip to content

Android: Use CMAKE_SYSROOT for Android sysroot#87293

Merged
etcwilde merged 2 commits into
swiftlang:mainfrom
etcwilde:ewilde/runtimes-android-sysroot
Apr 25, 2026
Merged

Android: Use CMAKE_SYSROOT for Android sysroot#87293
etcwilde merged 2 commits into
swiftlang:mainfrom
etcwilde:ewilde/runtimes-android-sysroot

Conversation

@etcwilde
Copy link
Copy Markdown
Member

The NDK configures CMAKE_SYSROOT in android-legacy.toolchain.cmake. I've verified this from Android NDK r26b to r29.

This gets the build system cross-compiling to Android from a non-Windows builder.

The NDK configures `CMAKE_SYSROOT` in `android-legacy.toolchain.cmake`.
I've verified this from Android NDK r26b to r29.

This gets the build system cross-compiling to Android from a non-Windows
builder.
@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test

@etcwilde
Copy link
Copy Markdown
Member Author

The Windows bits don't appear to be using the Android NDK toolchain file, which might be why CMAKE_SYSROOT wasn't getting set up. I suspect that this won't pass as-is. I may change build.ps1 here a bit to follow the Google documentation, which is how I've been testing/building this: https://developer.android.com/ndk/guides/cmake.

@etcwilde
Copy link
Copy Markdown
Member Author

Linux test failure:

********************
Failed Tests (1):
  lldb-api :: lang/swift/expression/no_calculator/TestSwiftNoProcess.py

This is not affected by the Android build.

macOS failure was a clang segfault while building parts of compiler-rt for the iOS simulator:

FAILED: compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.iossim.dir/asan_thread.cpp.o 

Also unrelated to changes to Android.

When cross-compiling, the toolchain file is supposed to set the
`CMAKE_SYSROOT` variable, which
In this case, there is no toolchain file to set it as build.ps1 is
passing everything through explicitly.
Setting it explicitly now for the C and C++ bits and for computing
flags.

CMake doesn't yet support passing `CMAKE_SYSROOT` to the Swift compiler
via the `sysroot` flag though:
https://gitlab.kitware.com/cmake/cmake/-/work_items/27717

For now, we need to keep passing it as an explicit Swift flag.
@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test

@etcwilde etcwilde force-pushed the ewilde/runtimes-android-sysroot branch from 7ed0f2d to 0cef5bc Compare March 24, 2026 22:34
@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test

Copy link
Copy Markdown
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I definitely like the removal of --sysroot from C/CXX FLAGS

@etcwilde
Copy link
Copy Markdown
Member Author

The Windows failure is unrelated and should have been fixed by swiftlang/swift-build#1236

@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test Windows

@finagolfin
Copy link
Copy Markdown
Member

The pre-commit Windows CI do nothing with Android, so if you want to test this, I suggest you temporarily add the -Android flag in the batch file and run the Windows toolchain CI command.

That linked pull is so we can add building Android SDKs to the pre-commit Windows CI and avoid manual testing workarounds like this.

@etcwilde
Copy link
Copy Markdown
Member Author

The pre-commit Windows CI do nothing with Android

Yeah, I know. I'm just trying to get this merged.

@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test macOS

@finagolfin
Copy link
Copy Markdown
Member

I'm just worried this may break the trunk Windows snapshot toolchain CI, which adds that flag I linked and builds the Android SDKs but only after these pulls are merged, so suggesting this be tested first.

@etcwilde
Copy link
Copy Markdown
Member Author

@swift-ci please test macOS

@finagolfin
Copy link
Copy Markdown
Member

I hope you weren't waiting for me to sign off on this, Evan. All I meant last month is that the current pre-merge Windows CI do not build the Android SDKs, #87867, so I have been testing Android changes like this on Windows by modifying that batch file and running the PR toolchain CI, then removing that flag before merging.

I was simply suggesting you do the same, but not a problem at all if you don't, as the post-merge Windows trunk snapshot toolchain CI will give us that signal anyway.

@etcwilde
Copy link
Copy Markdown
Member Author

Ah, okay. I tested it on my Windows box locally. I'll keep an eye out for failures on Windows from this.

@etcwilde etcwilde merged commit ae50c88 into swiftlang:main Apr 25, 2026
6 checks passed
@etcwilde etcwilde deleted the ewilde/runtimes-android-sysroot branch April 27, 2026 16:44
speednoisemovement added a commit to compnerd/swift-build that referenced this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants