Skip to content

build: support static builds for Swift #397

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
Oct 18, 2018

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Oct 4, 2018

Adjust the paths for static runtime builds of Swift.

@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

CC: @kevints

@kevints
Copy link

kevints commented Oct 5, 2018

@compnerd looking at the build the test programs are failing due to undefined ICU symbols needed by swiftCore. This is due to the once-private link dependencies of swiftCore now being needed (as there's no portable way for unix static archives to contain library dependencies; we need swift autolinking, libtool archives, or clang autolinking with lld). The dispatch buildsystem currently creates an IMPORTED target for the swiftCore library without regard to its dependencies. This happens to work in the shared case but doesn't in the static case, but to make it work robustly is equivalent to duplicating the -static-stdlib feature of swiftc in the dispatch buildsystem, which is the feature we're trying to fix. A more robust approach would be to use swiftc (with the -static-stdlib flag when BUILD_SHARED_LIBS is NO) to link these test programs. We could also use an exported swiftCore target from the swift build system but I suspect that's not currently tractable.

@gottesmm
Copy link
Contributor

gottesmm commented Oct 5, 2018

@kevints We support creating exported targets from the parent swift cmake.

Use the exported target from swift rather than recreate the paths locally.  This
almost works to replace the use of the paths.  Unfortunately, swiftrt is not
currently exported.
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

Please test with following PRs:
swiftlang/swift#19834

@swift-ci please test

@@ -44,38 +44,32 @@ dispatch_common_warnings()
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})

# NOTE(abdulras) this is the CMake supported way to control whether we generate
Copy link

Choose a reason for hiding this comment

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

Consider linking straight to the reference: https://cmake.org/cmake/help/v3.4/variable/BUILD_SHARED_LIBS.html

Copy link
Member Author

Choose a reason for hiding this comment

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

I do like that better; I think Im going to do that in a follow up (to get this merged first). This was just moving the option around.

@compnerd
Copy link
Member Author

Also note that this fixes the builds for me with tests after @DougGregor's change (layout differences between Darwin and Linux bites us again). My follow up change will actually use the swift compiler to link the Swift SDK overlay and split it out, so that actually makes all this significantly more robust and easier to work with.

@gottesmm
Copy link
Contributor

This LGTM from the swift side of things. I think the cmake will work fine as well given that we are essentially going through cmake config and performing an identity transformation (since swift's config provides that same information). @MadCoder hows this look to you?

@compnerd
Copy link
Member Author

compnerd commented Oct 15, 2018

@MadCoder - ping

@ktopley-apple ktopley-apple merged commit 3ed78b5 into swiftlang:master Oct 18, 2018
@compnerd compnerd deleted the static-stdlib branch October 18, 2018 16:40
rokhinip pushed a commit that referenced this pull request Nov 5, 2021
build: support static builds for Swift
Signed-off-by: Kim Topley <ktopley@apple.com>
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.

4 participants