-
Couldn't load subscription status.
- Fork 1.4k
Description
Description
I recently reorganized the Swift package for the Termux app, so that the Swift runtime libraries for the host are placed in <sysroot>/usr/lib/, not in <sysroot>/usr/lib/swift/android/. This caused issues when cross-compiling, because SwiftPM sets a toolchainLibDir relative to the Swift compiler, which is then used to search for libraries to link against.
This was added by Ankit in #2035 several years ago and is incorrect when cross-compiling, as most platforms don't use fat binaries that can all be placed in a single directory. I don't know why it was added, as I don't have access to that rdar.
This caused an issue for me as the linker would find the host runtime libraries for Swift in <sysroot>/usr/lib/ and complain, rather than using the ones in the cross-compilation SDK I provided. I've since reverted this library lookup in the Termux package for Swift, termux/termux-packages@222274616, and cross-compilation works well again.
This currently does not affect the official toolchains only because they place no Swift runtime libraries in <sysroot>/usr/lib/, placing everything in <sysroot>/usr/lib/swift/<os>/<arch>? instead. However, some distros have Swift packages and reorganize where they put things, and @etcwilde has said that he'd like to see them normalize where they place these Swift host runtime libraries, ie in <sysroot>/usr/lib/ instead. That will break cross-compilation with SwiftPM, as it has for me in Termux.
Expected behavior
Cross-compilation to only look in the SDK provided
Actual behavior
It looks in <sysroot>/usr/bin/swiftc/../../lib/ too.
Steps to reproduce
- Move the host runtime libraries to
<sysroot>/usr/lib/. - Try to cross-compile with another SDK.
Swift Package Manager version/commit hash
5.8
Swift & OS version (output of swift --version ; uname -a)
5.8
All ELF platforms, probably Windows too