Skip to content

Conversation

@owenv
Copy link
Collaborator

@owenv owenv commented Apr 3, 2025

This is the first pass at exporting targets so that SwiftPM can integrate Swift Build into its CMake build. It probably needs some iteration, I'll note where there are some changes I'm not certain of.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not confident target_include_directories is the right way to be propagating module search paths to clients

Copy link
Member

Choose a reason for hiding this comment

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

When you say clients, are you referring to external projects, or to other libraries within this project?

If swift-build is intended to be linked against by other projects, you'll want to be careful about exposing absolute paths into your build directory like this, unless the project is only ever intended to be used from the build directory.

target_include_directories(SWBAndroidPlatform PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  $<INSTALL_INTERFACE: -- wherever you're installing these files to -->)

https://cmake.org/cmake/help/latest/command/target_include_directories.html#creating-relocatable-packages

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@etcwilde thanks for taking a look! My plan was for the SwiftBuildSupport target in SwiftPM to statically link everything it uses from this repository (and eventually copy the necessary resources into its own installed resources), to mirror how the SwiftPM-based build is setup for now. Does that change your recommendation at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure this is the wrong way to ensure clients of this static library end up with a libc++ linkage

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, there isn't a great way to do this today. We need a mechanism to tell Swiftc to use clang++ as the clang-linker instead of clang, even when c++-interop isn't enabled. I've talked with @artemcm about it a bit, but will need something new in the driver. There are Swift runtime bits that the Swift driver knows about or I'd just say set the link language of the target to CXX, but that would break the Swift side.

Copy link
Member

Choose a reason for hiding this comment

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

When you say clients, are you referring to external projects, or to other libraries within this project?

If swift-build is intended to be linked against by other projects, you'll want to be careful about exposing absolute paths into your build directory like this, unless the project is only ever intended to be used from the build directory.

target_include_directories(SWBAndroidPlatform PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  $<INSTALL_INTERFACE: -- wherever you're installing these files to -->)

https://cmake.org/cmake/help/latest/command/target_include_directories.html#creating-relocatable-packages

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, there isn't a great way to do this today. We need a mechanism to tell Swiftc to use clang++ as the clang-linker instead of clang, even when c++-interop isn't enabled. I've talked with @artemcm about it a bit, but will need something new in the driver. There are Swift runtime bits that the Swift driver knows about or I'd just say set the link language of the target to CXX, but that would break the Swift side.

Copy link
Member

Choose a reason for hiding this comment

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

There's a special version of configure_file for generating project configs:
configure_package_config_file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like that requires specifying an install location, which I'm not sure we want here since we're just exporting static library targets for SwiftPM to link

@owenv
Copy link
Collaborator Author

owenv commented Apr 4, 2025

Linux:

CMake Error at Sources/SWBUtil/CMakeLists.txt:107 (target_link_libraries):
  Target "SWBUtil" links to:

    Crypto::Crypto

@owenv owenv force-pushed the cmake-exports branch 4 times, most recently from ffaeb0a to 584a77b Compare April 9, 2025 23:20
@owenv owenv force-pushed the cmake-exports branch 4 times, most recently from b6f270e to b12629b Compare April 23, 2025 16:43
@owenv owenv force-pushed the cmake-exports branch 2 times, most recently from 925c4a7 to 23eab7a Compare April 28, 2025 16:55
@owenv
Copy link
Collaborator Author

owenv commented Apr 29, 2025

@swift-ci test

@owenv owenv merged commit 8258eb5 into main Apr 29, 2025
3 checks passed
@owenv owenv deleted the cmake-exports branch April 29, 2025 16:15
owenv added a commit to swiftlang/swift-package-manager that referenced this pull request May 13, 2025
Build on swiftlang/swift-build#376 to begin
building Swift Build during the CMake bootstrap of SwiftPM

Depends on:
swiftlang/swift-installer-scripts#417
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