Skip to content

Don't link runtime compatibility library in pure Clang targets. #2134

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

Conversation

jckarter
Copy link
Contributor

swiftlang/swift#25030 introduces a compatibility library that can be statically linked into binaries
in order to back-deploy runtime fixes and new features to OSes that shipped with older Swift
runtimes. This library depends on the Swift runtime being linked into the executable, so it will
cause link errors for pure Clang products (and even if it didn't, it would be a waste of code
size). When building a product without any Swift in it, ask Swift to drive the linker without
introducing any runtime compatibility libraries (and shake out a few other unnecessary linker
flags while we're here).

rdar://problem/50057445

@jckarter jckarter requested a review from aciidgh May 28, 2019 21:35
@jckarter
Copy link
Contributor Author

Please test with following pull request:
swiftlang/swift#25030

@swift-ci Please test


/// True if this product contains Swift targets.
public var containsSwiftTargets: Bool {
return targets.contains { $0.underlyingTarget is SwiftTarget }
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this is just top-level targets; should it search for any targets?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you probably want to flatMap the recursiveDependencies first. Something like:

targets.flatMap { $0.recursiveDependencies }.contains { $0.underlyingTarget is SwiftTarget }

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if target.lazy.flatMap will help with performance here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no reason to build a temporary here, so lazy would work, or targets.contains { $0.recursiveDependencies.contains { ... } }

Copy link
Contributor

Choose a reason for hiding this comment

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

One complications here is that we should be stopping this search at the first dynamic product in the dependency graph because the top-level product could be just made up of C targets and getting Swift targets via a dylib.

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing though is that C targets can't import Swift targets in SwiftPM (at least not right now), so we can just do this for the top-level targets (as you've already done) and handle the other complications when we do start supporting the other case. Can you add a comment and file a JIRA for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

swiftlang/swift#25030 introduces a compatibility library that can be statically linked into binaries
in order to back-deploy runtime fixes and new features to OSes that shipped with older Swift
runtimes. This library depends on the Swift runtime being linked into the executable, so it will
cause link errors for pure Clang products (and even if it didn't, it would be a waste of code
size). When building a product without any Swift in it, ask Swift to drive the linker without
introducing any runtime compatibility libraries (and shake out a few other unnecessary linker
flags while we're here).

rdar://problem/50057445
@jckarter jckarter force-pushed the runtime-compat-lib-clang-targets branch from 86df6bb to 1a35ac7 Compare May 29, 2019 18:20
@jckarter
Copy link
Contributor Author

@swift-ci Please smoke test

@jckarter
Copy link
Contributor Author

Please test with following pull request:
swiftlang/swift#25030

@swift-ci Please smoke test

@jckarter
Copy link
Contributor Author

@aciidb0mb3r This look OK for now?

@aciidgh
Copy link
Contributor

aciidgh commented May 29, 2019

Yep, this looks good!

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

Successfully merging this pull request may close these issues.

3 participants