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
SwiftDriver: initial work to properly handle android cross-compilation #1560
base: main
Are you sure you want to change the base?
Conversation
if let sdk = parsedOptions.getLastArgument(.sdk)?.asSingle ?? env["SDKROOT"], !sdk.isEmpty { | ||
rsrc = try VirtualPath(path: AbsolutePath(validating: sdk) | ||
.appending(components: "usr", "lib", "swift") | ||
.pathString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if -resource-dir
is not specified, this behavior is already the default, so the only reason to do this is to override -resource-dir
. Any reason why you need that? I think this is a bad idea to silently override it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the default - this is going to try to prefer the resources in the SDK rather than the toolchain (which allows us to have platform specific resources).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, never mind, what I'm saying was true of the old C++ Driver, but is not true of this new swift-driver, after manually testing it on linux.
I think this is a genuine discrepancy between the two drivers that we should find the root cause and fix, rather than putting in partial workarounds like this.
With this set of changes I am down to:
The bits that I would like to remove:
This feels like we are failing to setup the library search path when we have a
This is due to my builds missing clang_rt.builtins-... for Android and so we need to pull some files from the NDK. Addressing those two issues would give us the following invocation:
and with
|
The reason this entire approach doesn't already work is because of a regression in this new Swift Driver, see #1562. We should fix that for all platforms, not paper over it with these Android-specific changes. |
The intent here is to permit the Windows/macOS style cross-compilation for Android. This involves passing `-sdk` with the path to the "Swift SDK" which overlays the system's native SDK (NDK). The `ANDROID_NDK_ROOT` is a well-defined environment variable (setup by the SDK installer as well as a general expectation for Android development) that identifies the root of the installation of the NDK. This allows us to locate the native SDK root (`--sysroot`) for driving the linker driver amongst other paths.
I'm not sure I'm following the "papering over" here. The idea here is to default the |
There are two aspects to this pull, having this new swift driver read environment variables like I don't think we should hard-code such environment variables in this driver, but always "explicitly specify" them, as you say. As for finding build files, the reason that doesn't work already is #1562: take a look at my detailed writeup from a couple weeks ago for why. |
I disagree with you on that point. I would like the default value behavior for the targets where possible, much as it works on macOS. Fixing the behavior to work with the parameters however should be done. |
The intent here is to permit the Windows/macOS style cross-compilation for Android. This involves passing
-sdk
with the path to the "Swift SDK" which overlays the system's native SDK (NDK). TheANDROID_NDK_ROOT
is a well-defined environment variable (setup by the SDK installer as well as a general expectation for Android development) that identifies the root of the installation of the NDK. This allows us to locate the native SDK root (--sysroot
) for driving the linker driver amongst other paths.