Skip to content

BuildPlan: infer -lc++ based on run-time triple #6581

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

Merged
merged 1 commit into from
May 18, 2023
Merged

Conversation

MaxDesiatov
Copy link
Contributor

Currently, when cross-compiling from Darwin to platforms that don't expect -lc++ by default (e.g. most Linux distributions), the build will fail because -lc++ is always passed. When should check the destination triple and not the host triple in the build plan code paths.

This leads to confusing build errors when cross-compiling more complex projects like Vapor.

rdar://107487090

Modifications:

Modified BuildPlan.swift to check the value of the triple property instead of hostTriple. Added a test that verifies this cross-compilation case.

Result:

Projects that contain C++ can now be cross-compiled from macOS to Linux.

Currently, when cross-compiling from Darwin to platforms that don't expect `-lc++` by default (e.g. most Linux distributions), the build will fail because `-lc++` is always passed. When should check the destination triple and not the host triple in the build plan code paths.

rdar://107487090
@MaxDesiatov
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I think that we should drop this entirely. The swift-driver has changed the behaviour for Darwin - it now uses clang as the linker driver. This is now something which we can control properly by using the driver. As long as we pass -enable-cxx-interop to the swift driver, it will correctly handle this - using clang++ to drive the linker which will add the C++ standard library to the linker invocation at the appropriate time. It also means that -Xclang-linker -stdlib= will do the proper thing.

@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented May 18, 2023

As long as we pass -enable-cxx-interop to the swift driver, it will correctly handle this

This is unrelated to -enable-cxx-interop support though. There are plenty of projects that don't use C++ interop, but fail to cross-compile because -lc++ is always passed when building on Darwin platforms. I'm happy to discuss the removal of this logic outside of the scope of this PR, but within it I'm only fixing the existing cross-compilation behavior without changing the reasoning behind the logic itself.

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) May 18, 2023 17:48
@MaxDesiatov MaxDesiatov merged commit 42fcece into main May 18, 2023
@MaxDesiatov MaxDesiatov deleted the maxd/libcpp-triple branch May 18, 2023 17:48
MaxDesiatov added a commit that referenced this pull request May 19, 2023
Cherry-pick of #6581

Currently, when cross-compiling from Darwin to platforms that don't expect `-lc++` by default (e.g. most Linux distributions), the build will fail because `-lc++` is always passed. When should check the destination triple and not the host triple in the build plan code paths.

This leads to confusing build errors when cross-compiling more complex projects like Vapor.

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

Successfully merging this pull request may close these issues.

3 participants