Skip to content

linkerSettings appears to work differently on macOS than linux #6257

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

Open
finagolfin opened this issue Mar 10, 2023 · 6 comments
Open

linkerSettings appears to work differently on macOS than linux #6257

finagolfin opened this issue Mar 10, 2023 · 6 comments
Labels

Comments

@finagolfin
Copy link
Member

Description

I was just trying to pass -no-toolchain-stdlib-rpath to the build when installing sourcekit-lsp in swiftlang/sourcekit-lsp#715 and Alex ran a full toolchain build to make sure it worked well. Strangely, it passed on linux and Windows builds sourcekit-lsp using CMake, not SPM, so it only failed on macOS, because it appears to incorrectly pass this Swift linker flag to clang:

0%: Link sourcekit-lsp (x86_64)
clang: error: unknown argument: '-no-toolchain-stdlib-rpath'

I'm not sure why it does this on macOS only, as the SPM source clearly shows the linker command-line running through the Swift compiler.

Expected behavior

No differences in linkerSettings behavior on different platforms

Actual behavior

The given example works on linux, but not macOS.

Steps to reproduce

Add a linkerSettings with a Swift flag like -no-toolchain-stdlib-rpath and build on macOS.

Swift Package Manager version/commit hash

1750a26

Swift & OS version (output of swift --version && uname -a)

Taken from the linked macOS CI run as I don't build on macOS:
Swift compiler commit - 642386290e84e9eeeed8ba70f07d5c3628be728a

@finagolfin finagolfin added the bug label Mar 10, 2023
@neonichu
Copy link
Contributor

That build seems to be using --build-system xcode which uses clang as the linker driver, not Swift.

@finagolfin
Copy link
Member Author

Alright, should we simply document this somewhere or is a change needed? It is convenient to be able to pass Swift compiler flags like this that affect linking, but it can't be done for this one build config of XCode.

@neonichu
Copy link
Contributor

I wonder if we ultimately need a way to differentiate? For now, I'd suggest just checking #if os(macOS) to not pass it if that is true.

@finagolfin
Copy link
Member Author

I wonder if we ultimately need a way to differentiate?

Unsure what you mean, have a way to pass different flags if it's the XCode build config of SPM?

For now, I'd suggest just checking #if os(macOS) to not pass it if that is true.

Oh, went one better and only pass it for the linux target now, that pull was merged.

@neonichu
Copy link
Contributor

Unsure what you mean, have a way to pass different flags if it's the XCode build config of SPM?

I think it would be on the axis of whether the linker driver is clang or swiftc, maybe something like unsafeSwiftFlags/unsafeCFlags in addition to unsafeFlags.

@finagolfin
Copy link
Member Author

Interesting, that might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants