Skip to content

Decide on final semantics for Android NDK lookup #1279

Description

@jakepetroules

(continued from discussion with @finagolfin in swiftlang/swift#88282)

...which will cause SwifftPM+SwiftBuild to use that NDK version, since it respects ANDROID_NDK_ROOT.

I don't think we should rely on env vars like that above what the user specified.

I'm guessing by "what the user specified" you're referring to the sdkRootPath property in the Swift SDK, but environment variables are also a mechanism by which users specify the NDK location.

Swift Build does not look at the symlinked NDK in the Swift SDK bundle, as that is a native-build-system-specific workaround.

You could say both are workarounds for broken SwiftPM, but ours is actually tying into the documented way to find the platform C/C++ SDK for Swift SDK bundles, ie by setting sdkRootPath to the symlinked NDK sysroot.

It's by design that Swift Build handles the NDK location for you. Users should not have to take on the burden of manually setting up symlinks.

The reason that Swift Build has to ignore the path specified in the Android Swift SDK is becomes it comes with a path entry pointing to a non-existent location at the moment. So the user experience is that you install the Swift SDK and it's just broken out of the box (with native build). With Swift Build, it "just works" immediately if you have already installed the NDK, without having to run any scripts to mutate the SDK.

That said, I'm happy to discuss making some tweaks to the logic that will satisfy a broader set of folks' requirements.

I think something like the following might work:

  • sdkRootPath property is omitted from the Swift SDK by default, rather than containing a value pointing to a non-existing relative path like today
  • The setup script ONLY adds sdkRootPath to the JSON, pointing to an explicit NDK path, without mutating ANY files in the Swift SDK -- no symlinks to the clang resource directory, no copyright swiftrt.o around
  • (optional) add an error to the native build system if sdkRootPath is not set up. Currently it just silently proceeds to build the project with a macOS sysroot (or whatever the host sysroot is, or perhaps none) and an Android target triple 😬
  • We document that users only need to run the setup script if using the SwiftPM native build system, otherwise it is optional.
  • We document that setting a specific NDK can be done by setting ANDROID_NDK_ROOT in the environment OR using the script to set sdkRootPath in the Swift SDK
  • If Finally wire up the sdk configure settings to compilation swift-package-manager#9229 is finished soon, we can eliminate the script entirely, and direct users to swift sdk configure instead.
  • If sdkRootPath is not present and ANDROID_NDK_ROOT is not specified, Swift Build continues to use its existing lookup mechanism to find the newest NDK installed on the system

I think in that model the only potentially controversial piece is what happens when both ANDROID_NDK_ROOT is set and sdkRootPath is set in the Swift SDK (to potentially different values). Is that an error? Is that a warning, with one or the other chosen to win? Does one or the other win without emitting any diagnostic?

You seem to be advocating that the sdkRootPath win over the ANDROID_NDK_ROOT, I think I don't have a strong opinion.

One thing I want to be VERY clear about though: Swift Build is the final arbiter of the arguments and environment passed to the underlying build tools. In particular, it tends NOT to forward the calling environment down to tools, so we generally shouldn't have to worry about problems like with the native build system where the Swift SDK specified one Android NDK, but the ANDROID_NDK_ROOT "leaked" down to the compiler and pointed to a different NDK path. I suspect that's related to some of the issues you've seen in the past.

No we are not.

How are you picking up NDK 29 otherwise?

If ANDROID_NDK_ROOT is not specified, Swift Build chooses the latest installed NDK version if the NDK is installed in one of the known default locations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidSupport for the Android platform

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions