Change in optionality of "sdkRootPath" property of swift-sdk.json for Swift SDKs

The Swift SDKs for Cross-Compilation introduced in SE-0387 specifies a swift-sdk.json configuration file that enumerates the various supported triples and their properties like sdkRootPath, swiftResourcesPath, includeSearchPaths, etc. All these properties except sdkRootPath have heretofore been optional.

For the Swift Android SDK, we want to have the sdkRootPath be configurable by the end-user because it is going to need to point to an external NDK sysroot. This is both so we don't need to ship the NDK sysroot subset along with the Swift Android SDK, and also because a user may want to be able to control the version of the NDK that is associated with the cross-compilation process. This will be accomplished by running the swift sdk configure command to specify the intended sdkRootPath after the SDK has been installed.

As a concrete example, after running:

swift sdk configure swift-6.2-RELEASE-android-0.1 --sdk-root-path /opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot

…the ~/Library/org.swift.swiftpm/swift-sdks/swift-6.2-RELEASE-android-0.1.artifactbundle/swift-android/swift-sdk.json would wind up looking like this:

{
  "schemaVersion": "4.0",
  "targetTriples": {
    "aarch64-unknown-linux-android28": {
      "sdkRootPath": "/opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot",
      "swiftResourcesPath": "swift-resources/usr/lib/swift-aarch64",
      "swiftStaticResourcesPath": "swift-resources/usr/lib/swift_static-aarch64",
      "toolsetPaths": [ "swift-toolset.json" ]
    },
    "x86_64-unknown-linux-android28": {
      "sdkRootPath": "/opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot",
      "swiftResourcesPath": "swift-resources/usr/lib/swift-x86_64",
      "swiftStaticResourcesPath": "swift-resources/usr/lib/swift_static-x86_64",
      "toolsetPaths": [ "swift-toolset.json" ]
    },
    "armv7-unknown-linux-android28": {
      "sdkRootPath": "/opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot",
      "swiftResourcesPath": "swift-resources/usr/lib/swift-armv7",
      "swiftStaticResourcesPath": "swift-resources/usr/lib/swift_static-armv7",
      "toolsetPaths": [ "swift-toolset.json" ]
    }
}

Support for this has been added in Allow omitting the target triple for `swift sdk configure` by marcprux · Pull Request #8856 · swiftlang/swift-package-manager · GitHub. The only weird part is that since the sdkRootPath is non-optional, a freshly-installed and unconfigured Swift Android SDK still needs some placeholder for the sdkRootPath property. We would like to make this property optional so that it is clear that it needs to be manually configured after the SDK has been installed.

Does anyone see any issue with the sdkRootPath being optional? This would require updating the mention of the optionality of the property at proposals/0387-cross-compilation-destinations.md (which I've filed at Update sdkRootPath to be optional in swift-sdk.json by marcprux · Pull Request #2888 · swiftlang/swift-evolution · GitHub). I would be surprised if this directly affects any existing projects, since I don't think the swift sdk configure command is used by anyone.

4 Likes

One thing I've mentioned before elsewhere but is worth clarifying again for this audience: when using the in-development --build-system swiftbuild backend with swift build, the location of the NDK will be automatically detected if the Android NDK is installed at the default location on the system (e.g. if Android Studio is installed and is used to manage the Android SDK/NDK).

Thus it's not only desirable but essential that sdkRootPath be optional so that this default discovery mechanism can work and provide a great out-of-the-box experience for Android development with SPM -- just run swift sdk install and then build for an Android triple immediately with no additional configuration in the ideal case.

Therefore any instructions published for the Android SDK should make clear that (when using the swiftbuild backend) the sdkRootPath "can be manually configured if an Android NDK is not detected at the default system location or if you wish to impose a specific NDK installation", not that it "must be".

3 Likes