Skip to content

build: adjust android build path #71927

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

Closed
wants to merge 1 commit into from

Conversation

compnerd
Copy link
Member

  • Remove custom SWIFT_ANDROID_NDK_PATH variable for the CMake variable CMAKE_ANDROID_NDK which is part of the default CMake tooling.
  • Adjust the default NDK sysroot to be the NDK sysroot, not the termux sysroot to match the SDK name.

- Remove custom `SWIFT_ANDROID_NDK_PATH` variable for the CMake variable
  `CMAKE_ANDROID_NDK` which is part of the default CMake tooling.
- Adjust the default NDK sysroot to be the NDK sysroot, not the termux
  sysroot to match the SDK name.
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

CC: @etcwilde @finagolfin

@compnerd
Copy link
Member Author

CC: @drodriguez

Copy link
Contributor

@drodriguez drodriguez left a comment

Choose a reason for hiding this comment

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

I am +1 in changing to a variable that CMake understands and might be used for other things. However a simple grepping of the variable name can find a lot of cases that are not dealt with here (the build-script-impl, the test files, CMake files for libdispatch).

BTW, the Android CI has been broken (and it cannot be launched on demand from a PR) since main required using Swift Syntax for some pieces of the toolchain.

@compnerd
Copy link
Member Author

I can likely go through the tests; I noticed the libdispatch issue locally and need to dig into that. I am running this locally for now. I will be putting up some changes subsequently to start building the Android SDKs on Windows to ensure that we don't regress those builds.

@etcwilde
Copy link
Member

Yeah, separating termux and Android makes sense since they are different userspaces.

@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

@@ -1094,8 +1092,9 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
set(SWIFT_HOST_VARIANT "android" CACHE STRING
"Deployment OS for Swift host tools (the compiler) [android]")

set(SWIFT_ANDROID_NATIVE_SYSROOT "/data/data/com.termux/files" CACHE STRING
"Path to Android sysroot, default initialized to the Termux app's layout")
Copy link
Member

Choose a reason for hiding this comment

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

You misunderstand what this is used for. SWIFT_ANDROID_NATIVE_SYSROOT is a native sysroot used in Android itself, eg the Termux app that runs on Android has its own native compilation sysroot and does not use the NDK. SWIFT_ANDROID_NDK_PATH is the path to the NDK and is only set when cross-compiling to Android.

That's why the code in cmake/modules/SwiftAndroidSupport.cmake below first checks if SWIFT_ANDROID_NDK_PATH is set, so it knows if it is cross-compiling with the NDK, then checks if natively compiling with an Android sysroot, ie in Termux, and if neither happens to be set, it errors.

Don't modify these two lines: it is not relevant to the normal Android cross-compilation workflow that you are using.

@finagolfin
Copy link
Member

Yeah, separating termux and Android makes sense since they are different userspaces.

They are already completely separated since I added this SWIFT_ANDROID_NATIVE_SYSROOT variable 5 years ago.

SWIFT_ANDROID_NDK_PATH is used when cross-compiling with the NDK and predates my involvement with Swift. SWIFT_ANDROID_NATIVE_SYSROOT is used when natively building in Termux on Android itself, which does not use the NDK and I presume you all are not doing, so it should not be touched by this pull.

@finagolfin
Copy link
Member

I am fine with the medium-term goal of pulling in CMake's built-in support for Android cross-compilation- provided the unrelated changes to SWIFT_ANDROID_NATIVE_SYSROOT, which is only used for natively compiling on an Android device, are removed from this pull- but we currently do not use that built-in support and roll our own cross-compilation for every platform, so without further changes, CMAKE_ANDROID_NDK will not be set. If you make those additional changes to define it, I suspect they will have to be fairly extensive in the CMake build config.

the Android CI has been broken (and it cannot be launched on demand from a PR) since main required using Swift Syntax for some pieces of the toolchain.

That is not required yet but yours is the only CI disabling it, so every time some issue like #71807 is fixed, new issues crop up, since all the official CI enable using the new swift-syntax parser.

@compnerd
Copy link
Member Author

Building the regular android path was definitely impacted by these changes - I'm happy to leave the removed variable around if it doesn't impact the android build, but we should rename it to reflect that it is for termux and not Android.

@finagolfin
Copy link
Member

What were you building, were you cross-compiling the Swift compiler itself from Windows to Android? Because unless the SWIFT_HOST_VARIANT_SDK is ANDROID, SWIFT_ANDROID_NATIVE_SYSROOT is not set.

we should rename it to reflect that it is for termux and not Android

It is for native compilation- not Termux, as there are other native compilation environments on Android- but simply default-initialized to Termux, as Termux is by far the most popular app used for that. The name SWIFT_ANDROID_NATIVE_SYSROOT was chosen to reflect native compilation on Android, feel free to rename it in this pull if you have a better name in mind.

@compnerd
Copy link
Member Author

What were you building, were you cross-compiling the Swift compiler itself from Windows to Android?

I'm building the runtime only not the compiler. I am cross-compiling from Windows to Android though.

@finagolfin
Copy link
Member

I'm building the runtime only not the compiler. I am cross-compiling from Windows to Android though.

OK, try removing the SWIFT_ANDROID_NATIVE_SYSROOT change here from your source and doing a clean build. I'm fairly certain removing it will make no difference, but if it does, let me know what error you see and I will fix it.

@compnerd compnerd closed this Nov 20, 2024
@compnerd compnerd deleted the android-is-android branch November 20, 2024 17:25
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