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

Automatically build FoundationMacros for local CMake builds #844

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

jmschonfeld
Copy link
Contributor

When building this project via CMake as a standalone project (not as part of a toolchain build) we automatically check out and build some dependencies such as swift-collections and swift-foundation-icu. Now that we've separated the macro build into a separate build, we need to do the same for FoundationMacros. This updates the CMake files so that when SwiftFoundation_MACROS is not specified, we add the macro target to the build graph and build a copy of the macro for the host to use while building the rest of the project. This builds the macro as an executable just like SwiftPM rather than as a library so that the macro can be built with a different copy of swift-syntax than what the compiler has.

While I was here, I also added some logging messages when checking out the dependencies to make it clear what build settings you can specify for local copies, as well as indicate why a cmake configuration was taking a while during git cloning

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

Full toolchain tests which cover the CMake changes passed in the linked PR

@jmschonfeld jmschonfeld merged commit fd4788a into swiftlang:main Aug 19, 2024
3 checks passed
@jmschonfeld jmschonfeld deleted the automatic-macro-build branch August 19, 2024 21:53
message(STATUS "SwiftFoundation_MACRO not provided, building Foundation macros locally for host")
# No path to Foundation macros was provided, so we must build it ourselves
set(FoundationMacros_BuildLocalExecutable YES)
FetchContent_Declare(FoundationMacros
Copy link
Contributor

Choose a reason for hiding this comment

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

The macros should build through ExternalProject. If we are cross-compiling Foundation, these macros will get built for the machine that we are cross-compiling to instead of the machine running the build, and therefore will not be usable.

# No path to Foundation macros was provided, so we must build it ourselves
set(FoundationMacros_BuildLocalExecutable YES)
FetchContent_Declare(FoundationMacros
SOURCE_DIR ${CMAKE_SOURCE_DIR}/Sources/FoundationMacros)

Choose a reason for hiding this comment

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

Wouldn't CMAKE_SOURCE_DIR be the swift-corelibs-foundation when this project is added as an external project from there? Would ${CMAKE_CURRENT_SOURCE_DIR}/../FoundationMacros be more correct here?

cthielen pushed a commit to cthielen/swift-foundation that referenced this pull request Nov 8, 2024
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