Skip to content

build: honour BUILD_SHARED_LIBS #396

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 4, 2018

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Oct 3, 2018

This is needed for proper shared linkage to the BlocksRuntime (e.g. when
building SourceKit). We now build BlocksRuntime shared or static as requested.

@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

Please test with following PRs:
swiftlang/swift#19674

@swift-ci please test

CMakeLists.txt Outdated
@@ -74,14 +74,12 @@ if(ENABLE_SWIFT)

set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/swift/${SWIFT_OS}" CACHE PATH "Path where the libraries will be installed")
set(INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR}/swift/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
set(INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR}/swift/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
Copy link

Choose a reason for hiding this comment

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

These directories should be swift or swift_static depending on the value of BUILD_SHARED_LIBS

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, though this issue has existed for some time now and is not made any worse by this change. I'll put up a separate PR to address that.

set_target_properties(BlocksRuntime
PROPERTIES
INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
target_link_libraries(BlocksRuntime
Copy link

Choose a reason for hiding this comment

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

This is a functional linkage change that should go into another PR (though I suspect this branch is never executed). If this is required then we need to change our approach to the module map as well (as we'd now need to link dl and objc).

Copy link
Member Author

Choose a reason for hiding this comment

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

INTERFACE doesn't work with shared libraries, so this should be public (since INTERFACE is equal to PUBLIC with shared).

@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

Please test with following PRs:
swiftlang/swift#19674

@swift-ci please test

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

As we discussed offline, can you add in a follow on commit:

  1. A comment here that explicitly says that we define BUILD_SHARED_LIBS to control shared/static.
  2. Above where we create the option BUILD_SHARED_LIBS can you include a comment that says that this is a way that cmake allows one to control globally whether add_library defaults to shared or static and that we always only produce one or the other.

The reason I am asking for these comments is that I am worried about less experienced cmake people not understanding what we are doing here since in other parts of swift.org cmake we are always explicit about shared vs static.

This is needed for proper shared linkage to the BlocksRuntime (e.g. when
building SourceKit).  We now build BlocksRuntime shared or static as requested.
@compnerd
Copy link
Member Author

compnerd commented Oct 4, 2018

Please test with following PRs:
swiftlang/swift#19674

@swift-ci please test

@compnerd compnerd merged commit c55ff6f into swiftlang:master Oct 4, 2018
@compnerd compnerd deleted the build-type-blocks branch October 4, 2018 22:32
@drodriguez
Copy link
Contributor

@compnerd: I might be wrong, but it seems that libBlocksRuntime.so ends up in the “root” build directory, not anywhere its sibling libdispatch.so. If I understand correctly, any Swift code that imports Dispatch will need libBlocksRuntime.so available (from the changes in the modulemap).

One of those is XCTest. While compiling it uses https://github.com/apple/swift-corelibs-xctest/blob/master/CMakeLists.txt#L48 to point to the libdispatch.so library, but it points the search path to …/src (where no libBlocksRuntime.so can be found).

Another is LLBuild. From https://github.com/apple/swift-llbuild/blob/master/products/llbuildSwift/CMakeLists.txt#L19-L24 it points the library search path to …/src/.libs.

I think those might need to be fixed, but I will wait until I can talk with you to confirm.

rokhinip pushed a commit that referenced this pull request Nov 5, 2021
build: honour `BUILD_SHARED_LIBS`
Signed-off-by: Kim Topley <[email protected]>
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.

5 participants