Skip to content
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

Configure CMake build to install content into toolchain #581

Merged
merged 6 commits into from
Aug 10, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 26, 2024

(Supersedes #531)

This includes several changes to the CMake rules to support installing built content into a toolchain.

Motivation:

This is necessary to support including swift-testing in Swift 6 toolchains.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@rintaro rintaro force-pushed the toolchain branch 2 times, most recently from 0d05234 to a0b2146 Compare July 30, 2024 20:12
@rintaro rintaro force-pushed the toolchain branch 3 times, most recently from 35786c8 to 5e09d09 Compare August 1, 2024 21:37
@rintaro
Copy link
Member Author

rintaro commented Aug 3, 2024

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Aug 3, 2024

@swift-ci Please test

@@ -97,16 +97,9 @@ target_link_libraries(Testing PRIVATE
add_dependencies(Testing
TestingMacros)
target_compile_options(Testing PRIVATE
-enable-library-evolution)
-enable-library-evolution
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:Testing,Swift_MODULE_DIRECTORY>/Testing.swiftinterface)
Copy link
Member Author

@rintaro rintaro Aug 3, 2024

Choose a reason for hiding this comment

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

We might want to stop emitting .swiftinterface unless it's macOS because .swiftinterface is not installed and useless.

(Should we stop -enable-library-evolution too?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need -enable-library-evolution to avoid folks directly linking our C++ module?

@rintaro rintaro marked this pull request as ready for review August 3, 2024 14:12
@rintaro rintaro changed the title [WIP] Configure CMake build to install content into toolchain Configure CMake build to install content into toolchain Aug 3, 2024
# TestingMacros uses `ExternalProject` and we cannot directly query the
# properties of its targets here.
if(NOT SwiftTesting_BuildMacrosAsExecutables)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Copy link
Member

Choose a reason for hiding this comment

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

Should these not be checking CMAKE_HOST_SYSTEM_NAME?

target_link_options(TestingMacros PRIVATE "-no-toolchain-stdlib-rpath")
# Not setting RPATH means it requires all the dependencies are already loaded
# in the process, because 'plugin' directory wouldn't contain any dependencies.
set_property(TARGET TestingMacros PROPERTY INSTALL_RPATH)
Copy link
Member

Choose a reason for hiding this comment

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

You should use set_target_properties to avoid calling the function twice.

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 don't know how to unset a property using set_target_properties.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it critical to change it? Or just an efficiency thing?

Copy link
Member Author

@rintaro rintaro Aug 9, 2024

Choose a reason for hiding this comment

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

Efficiency and stylistic thing I think. I believe this also work,

set_target_properties(TestingMacros PROPERTIES
  INSTALL_RPATH ""
  BUILD_WITH_INSTALL_RPATH YES)

but I just wanted to clear the property. tbh, I'm not sure which is more correct. Explicit empty list ("") or clearing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can do both with set_property

set_property(TARGET TestingMacros
    PROPERTY INSTALL_RPATH
    PROPERTY BUILD_WITH_INSTALL_RPATH YES)

Copy link
Member Author

Choose a reason for hiding this comment

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

@rintaro
Copy link
Member Author

rintaro commented Aug 6, 2024

@swift-ci Please test

Add `SwiftTesting_MACRO` configuration option:
 * By default, the plugin is built using `SwiftTesting_MACRO_*` options
 * If it's explicitly "NO" (or other 'false' value), build Testing
   library without using the plugin
 * Otherwise, use the passed-in value as the plugin path

Update macOS install location to 'usr/lib/swift/testing' for libraries,
and 'usr/lib/host/plugins/testing' for plugin.

Correct the install RPATH.
@rintaro
Copy link
Member Author

rintaro commented Aug 6, 2024

@swift-ci Please test

@grynspan grynspan added enhancement New feature or request swiftpm-integration Swift Package Manager integration tools integration Integration of swift-testing into tools/IDEs swift-6 labels Aug 7, 2024
@rintaro rintaro removed their assignment Aug 9, 2024
@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@swift-ci Please test

set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER})
endif()
if(NOT SwiftTesting_MACRO_Swift_FLAGS)
set(SwiftTesting_MACRO_Swift_FLAGS ${CMAKE_Swift_FLAGS})
Copy link
Contributor

Choose a reason for hiding this comment

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

What flags are you hoping to pull here?
This seems risky given that these flags might be for an entirely different machine than the one the macros will build for/run on.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a leftover from when I was trying around. Let me remove this as a followup.

target_link_options(TestingMacros PRIVATE "-no-toolchain-stdlib-rpath")
# Not setting RPATH means it requires all the dependencies are already loaded
# in the process, because 'plugin' directory wouldn't contain any dependencies.
set_property(TARGET TestingMacros PROPERTY INSTALL_RPATH)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can do both with set_property

set_property(TARGET TestingMacros
    PROPERTY INSTALL_RPATH
    PROPERTY BUILD_WITH_INSTALL_RPATH YES)

@rintaro rintaro merged commit 264fbd9 into swiftlang:main Aug 10, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request swiftpm-integration Swift Package Manager integration tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants