Do not add -sysroot flag when ANDROID_NDK_ROOT environment is set#1879
Do not add -sysroot flag when ANDROID_NDK_ROOT environment is set#1879finagolfin merged 3 commits intoswiftlang:mainfrom
Conversation
|
I've marked this ready for review, @jakepetroules, @finagolfin, and @compnerd. See also the discussion at swiftlang/swift-build#495 (comment) |
|
I agree with getting rid of this. As much as the idea is to automatically set things up and make things automatically work, I think it's better to have the user configure this themselves. For example, this env variable is automatically set on the github CI, so even if the user explicitly configures the Better to not have such magic and make the setup more explicit, as it would be after this pull. |
|
This is going to break all of our builds, please do not commit this as is. We need the ability to be able to pass the |
Then how about gating it within an |
This change isn't removing the ability to do that, right? It's just removing the default fallback. From what I understand, explicitly passing |
|
@compnerd Any thoughts on either @jakepetroules's questions or my suggestion? I'd really like to reach some solution so we can un-block the Android SDK work. |
Ah, right; this still will break our builds as we do rely on the default. Can we wire up the default through swift-build before we remove this? |
|
As far as I know, swift-build is already doing the right thing here, e.g. it will always pass a value for |
|
@compnerd or @weliveindetail, could you apply this change to your CI and let us know if it causes any error and what the full output is? Because that may turn up an underlying bug that is better fixed rather than papering over it with this Android default. |
|
This hasn't made it into the swift-6.2 brach, has it? I'm still seeing the build failures when I have @finagolfin Can you add this to the project board? |
|
Can we get this updated and landed? @compnerd do you still have concerns? |
|
I think that we should wait until @finagolfin's frontend/driver changes are done and then re-test before merging this. The |
|
My frontend change in swiftlang/swift#79621 only affects It is unclear why this env variable detection and Is there some ordering issue or something, on the TBC CI builds with this pull? If you guys would simply try this patch and replace it with manually passing in this flag to your build config, we could determine if this was really necessary to you or not, from the resulting error output, if any. |
|
@marcprux, mind rebasing? |
|
@swift-ci test |
|
@swift-ci test windows |
|
@Steelskin, can you apply this pull to your Windows CI, along with passing in this The problem with this default is that it forces everyone to use the NDK at |
I am in the process of changing our build to more closely match what is being done in Does that sound about correct to you or would you like me to edit some of the flags and/or the environment here? |
|
Are you sure you need both Other than that, I'd like you to run these flags you've pasted but using a swift-driver with this pull of Marc's applied: see if removing this |
Not sure, this is how the build is configured. I can toy with what arguments we actually need at a later time.
Alright, got it. All I did was change the |
|
@finagolfin Our CI succeeded with the current |
|
@compnerd, if you would approve or let us know if you need to test anything else, I'd like to get this in. |
|
Pinging @compnerd again, would like to get this into 6.2 next, as I have had to work around this override on my Android CI and so have others. If you have no further concerns, please approve and we'll get this in. |
|
Thanks for the explanation, this is making things a little clearer. Can you also clarify whether you're building via SwiftPM, or building with a different build system? If if let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath {
let sysrootFlags = [triple.isDarwin() ? "-isysroot" : "--sysroot", sdkDir.pathString]
self.extraFlags.cCompilerFlags.insert(contentsOf: sysrootFlags, at: 0)
}
What's still missing?
Could this have some smarter detection? e.g. don't add the default |
The build system is irrelevant, as these are Swift compiler flags that any build system has to use. I merely focused on SwiftPM because it is what most use, but these Swift compiler flags used for cross-compilation are the same regardless of build system, whether CMake or Bazel.
OK, I can see you are confused, so let me get into the slightly longer expanation. Until recently, there were supposed to be two options to cross-compile using the Well, when the The SwiftPM flag you pasted is correct under the The only reason the TBC CI is able to use
The main one is actually having this
Given all the A final aspect that I don't like is that we have an explicit flag for this in SwiftPM, better to use that than these magic environment variables. You think you're making life easier for the user, but you're really just introducing hidden variables that can break things in hard to debug ways. Let me finally note that I'm not against the |
|
Ping @compnerd or @jakepetroules, can we go ahead and get this in? The behavior this pull reverts is clearly not needed on Windows, where it can always be passed in manually, and as detailed above, it breaks most Android builds when used with SDK bundles, which only support This pull gets Android building again on CI environments which set this environment variable, where Marc and I have had to unset this variable to avoid this broken behavior and warn others to do the same. Since |
|
I chatted with @jakepetroules, @owenv, @compnerd and @etcwilde and have a proposal. One key thing we’d like to do is to better delineate is the use of the various discussed flags here. The ones we’re generally concerned with are:
One some platforms, sys root and SDK root are the same (read Apple platforms), in which case no explicit It’s also critical that we do not conflate the required Swift bits (resource dir and SDK) and the native system sysroot and keep those concepts separate. Regarding |
This is currently aspirational and doesn't really work on any platform, hence all the flags listed for Windows above too.
There would be value if
If and when |
|
I'd like to raise attention to this issue again, since it is still the case that trying to build for Android with If improving this PR to special-case Windows is not satisfactory, what would be an acceptable solution? Is there any way we can get some solution — even a stopgap one — in place before we start publishing the SDK? |
|
Their compromise will work to elide the broken code for most SDK bundles, but I think we should remove the broken Up to you what you want to do... |
|
Am I understanding correctly that having If so, the way I understand this, we have an environment variable that is intended to be used as a fallback actually overwriting things it shouldn't. While I understand the motivation for using a platform-standard environment variable (ANDROID_NDK_HOME) for configuring certain settings, the issue is that we have multiple redundant flags for kind of doing the same thing. This makes using the environment variable as a fallback "only" is not effective. The redundancy in question cannot be trivially removed though, and doing so would be a much larger fix. Is there an alternative of ensuring only one of the two sets of flags has an effect? |
Yes
Not merely redundant, they actually break the build in the vast majority of cases if that environment variable is set, as all SDK bundles currently set the
The way I would phrase it is that this is a convenience method to find the Android sysroot for you. However, since almost everybody uses Artem and the others above have put forth a compromise, ie only invoke this convenience method if |
|
I'll plead once more for attention to this. With the imminent release of the Swift SDK for Android, anyone who happens to have I just don't see why we are consulting this environment at all, at least on non-Windows platforms. |
@artemcm, let me demonstrate a core way in which this understanding you have laid out is blatantly wrong on all platforms. There is currently a test in the compiler validation suite that ensures that the resource directory, whether implicit or explicitly passed in with the This test is currently only run on Darwin CI, but the underlying logic is the same on all platforms, which is why I was able to enable it on linux and Windows also with a couple minor tweaks to the test format alone, ie no changes to the Swift compiler. This directly contradicts your claim that the All SDK bundles currently use the long-time I am not saying let's not move to the new approach: I'm simply saying let's not break the old approach by pushing the new approach in when it doesn't really work yet. This pull by Marc would give us more time to fix the new |
|
@swift-ci test |
|
@compnerd I think we should merge this at this point, since SwiftPM is already passing the necessary flags to activate the NDK without relying on the env var, and also: the code here is behind I think most of the other discussion on this PR is perhaps better had in swiftlang/swift#79657 |
|
@swift-ci test windows |
|
Discussed with @jakepetroules offline. The variable here is correct. This is the older variable. I think that we can merge this for now, but be okay with the idea of a quick revert if we find that things are broken. We are still fighting a Debug Info generation issue that was introduced in main and so cannot test this right away. I will want to see this restored in the future, as this avoids the need to pass |
|
The issue is not the name of the environment variable: the issue is that you only use this new As such, it will not make sense to ever bring these inserted flags back until there is some change in that SDK bundle JSON format that allows it. I realize you don't use SDK bundles on Windows yet, but since you can always pass this Regarding what to do in the future about helping Android devs configure this easier, we can discuss that more with Jake and decide, since he is baking some NDK support into the swift-build package. Merging now since we are in agreement and we can remove those linked CI workarounds once this fix is merged, then let's discuss more elsewhere and come up with a better solution if needed. |
|
Can we cherry-pick this for 6.3? |
(cherry picked from commit ed284e3)
When the environment
ANDROID_NDK_ROOTis set, the driver manually adds it as a--sysrootflag. This breaks building with an Android SDK when this variable is set, with confusing errors. I first saw this at finagolfin/swift-android-sdk#207 (comment), and more recently ran into it again (https://github.com/swift-android-sdk/swift-docker/actions/runs/14584558227/job/40907674425) while working on the official Android SDK build script, where it fails a build with:In both cases, manually un-setting
ANDROID_NDK_ROOT(which is set by default in GitHub workflows) resolved the issue.This flag has some history (#1560, #1681, and #1811), but I feel like it should just be excised altogether since the Android SDK can specify its own
sdkRootPathin theswift-sdk.jsonfile. If Windows needs it due to lack of Swift SDK support, then it could be gated inside an#if os(Windows)check.And BTW, the
#if arch(x86_64)check is incorrect: the Android NDK works on both Intel and ARM macOS machines, despite being stored under "darwin-x86_64", as the binaries are universal: