-
Notifications
You must be signed in to change notification settings - Fork 10.5k
add %SDKROOT%\usr\include as -isystem for non-Windows non-Darwin #78649
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
base: main
Are you sure you want to change the base?
add %SDKROOT%\usr\include as -isystem for non-Windows non-Darwin #78649
Conversation
@compnerd this the change we put together locally last week |
I don't think this is necessary normally on linux/macOS, as the sdk root is passed in as the clang sysroot already and clang automatically checks |
Normally these paths are added in the clang driver/toolchain, I don't think we should be adding these in Swift |
Maybe we need to add an Android toolchain at https://github.com/llvm/llvm-project/tree/main/clang/lib/Driver/ToolChains ? Or add Android affordances in the MinGW/MSVC toolchain? |
@finagolfin @ian-twilightcoder thank you for the feedback! I will look into this issue further and revise the approach. My goal here is to simplify Swift for Android builds to they only require two paths be manually specified:
However, currently when building a simple CMake project that includes Swift, two other paths must be explicitly provided via Specifically:
and
The toolchain should be able to derive these paths, and this PR was my attempt at deriving the second one. I would truly appreciate any pointers to the component(s) where it makes the most sense to address this issue. Thank you! |
The question is, why isn't it looking in that directory already? To determine that, leave off the |
And that sounds great! But probably not Swift specific, which is why I suggest moving this into the llvm toolchain that's being used for your build.
Yep, I just think "that toolchain" is probably the llvm one and not the swift one. |
Having investigated a bit more today, I actually don't think the current PR is too far off from being correct. Here's my current assessment:
Since cross-compilation requires both paths be provided, only the sysroot is passed to the compiler-- it is never told to search the Swift SDK Please let me know what you think; I could still be wildly off because I'm not very familiar with the Swift build tools yet. If my assessment looks right, I'll revise the PR and update the description to properly describe the issue and the fix. |
If I understand you right, you're saying that when you do |
Can you paste that output here? It would be good to know precisely which header it's missing. Try also adding the flags There are currently some issues when compiling for ELF platforms with the trunk swift-driver because of the ongoing work to change the meaning of certain core flags in the Swift compiler, such as #76381 which I filed. It is possible this is a consequence of those changes, which have still not been completed. |
A build without the additional
The include search path passed to clang:
The clang importer args:
|
That's a weird value for |
I just confirmed that explicitly appending the "usr/include" to the sdk root is required here or it doesn't search that location. |
No, it isn't required: the static linux Musl SDK and my Android SDK bundle build just fine today without it. However, I disable using swift-driver from 6.1 onwards because of recent regressions in how it works, so it's possible you're hitting those too. The current swift-driver Unix config for 6.1 onwards is a mess that will have to be cleaned up, while this pull simply adds yet another workaround for likely that underlying problem. I will discuss it with Saleem and some others and let you know. |
That sounds like another issue in the clang driver. Which driver do you end up getting? |
OK, I finally spent some time looking into this. All current Unix toolchains and bundles expect Dispatch to be in the Swift I'm not blaming you for this, but I've had a brief discussion about this with Saleem and Alex in the past and it sounds like your TBC Android SDK moves a bunch of files around and places them in highly non-standard locations. I suppose that's fine if you all want to do that in your local SDKs, but you can't expect upstream to start supporting such non-standard layouts, especially since you have never explicitly detailed and proposed this new layout upstream. If we add this change you're proposing, that means the Swift compiler will also start looking in I suggest you go talk to your TBC team and either change your SDK layout to match what all other linux and Unix toolchains and bundles are doing, or come up with an explicit proposal for how these SDK layouts should be changed upstream. |
Purpose
Automatically add
%SDKROOT%\usr\include
as the-isystem
argument toclang
when both SDK and sysroot are provided.Background
Without this change, cross-compiling a Swift program for Android requires explicitly adding
-Xswiftc -I -Xswiftc %SDKROOT%\usr\include
toswift build
or-Xcc -I%SDKROOT%\usr\include
toCMAKE_Swift_FLAGS
forcmake
builds.Validation
Built
swift-argument-parser
for Android on Windows without manually specifying%SDKROOT%\usr\include
.Using Swift build:
Using CMake