Skip to content
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

Don't add Toolchain.toolchainLibDir to the list of directories SwiftPM links against #6767

Closed
finagolfin opened this issue Aug 1, 2023 · 3 comments · Fixed by #6824
Closed
Labels

Comments

@finagolfin
Copy link
Member

finagolfin commented Aug 1, 2023

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

  1. Move the host runtime libraries to <sysroot>/usr/lib/.
  2. 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

@finagolfin finagolfin added the bug label Aug 1, 2023
@neonichu
Copy link
Contributor

neonichu commented Aug 1, 2023

Looks like this was about SwiftSyntax, so might generally not be needed anymore.

@neonichu
Copy link
Contributor

neonichu commented Aug 1, 2023

Specifically this is said in the radar:

Proposed solution: SwiftPM could always add a search path to toolchain's usr/lib directory, similar to how it adds the search path to SDK's framework directory. This will also handle any future libraries that we might start shipping as part of the toolchain.

I'm not sure if that's ever desirable anymore tbh.

@finagolfin
Copy link
Member Author

@neonichu, should I go ahead and submit a pull to remove that library lookup? Do you still need it on Darwin platforms?

finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 17, 2023
…to look up libraries for target triple

Also, update my github username in the mailmap.

Resolves swiftlang#6767
MaxDesiatov pushed a commit that referenced this issue Aug 22, 2023
…to look up libraries for target triple (#6824)

Also, update my github username in the mailmap.

Resolves #6767
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 22, 2023
…to look up libraries for target triple (swiftlang#6824)

Also, update my github username in the mailmap.

Resolves swiftlang#6767
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 23, 2023
…to look up libraries for target triple (swiftlang#6824)

Also, update my github username in the mailmap.

Resolves swiftlang#6767
tomerd pushed a commit that referenced this issue Aug 23, 2023
…to look up libraries for target triple (#6824) (#6837)

Also, update my github username in the mailmap.

Resolves #6767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants