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

build: initial support for building with CMake #76

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Feb 3, 2025

Add support for building with CMake which is required to get the toolchain bootstrapped. This partially addresses #7.

Copy link

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

Lots of leading newlines that should probably be the license header assuming those are still required.

Do you know if the macro bits are macro-macros, or are they support within Swift-Build for building macros for projects that Swift-Build is building?

Sources/SWBMacro/CMakeLists.txt Show resolved Hide resolved
Sources/SwiftBuild/CMakeLists.txt Show resolved Hide resolved
Sources/SWBUtil/CMakeLists.txt Show resolved Hide resolved
SwiftDriver
TSCBasic)

target_include_directories(SWBMacro PUBLIC
Copy link

Choose a reason for hiding this comment

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

What is going on here? What bits aren't getting picked up by the linking?

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 not understand why these are not getting picked up. There are two cases where I had to explicitly workaround the target_link_libraries being insufficient.

@compnerd
Copy link
Member Author

compnerd commented Feb 3, 2025

I've tested this only on Windows so far with:

cmake -B out -G Ninja -S . -D CMAKE_BUILD_TYPE=Releaes -D SwiftSystem_DIR=S:\b\21\cmake\modules -D ArgumentParser_DIR=S:\b\14\cmake\modules -D TSC_DIR=S:\b\12\cmake\modules -D SwiftDriver_DIR=S:\b\15\cmake\modules -D LLBuild_DIR=S:\b\13\cmake\modules -D SQLite3_LIBRARY=S:\Library\sqlite-3.46.0\usr\lib\SQLite3.lib -D SQLite3_INCLUDE_DIR=S:\Library\sqlite-3.46.0\usr\include\ -D CMAKE_STATIC_LIBRARY_PREFIX_Swift=lib -D BUILD_SHARED_LIBS=YES -D "CMAKE_Swift_FLAGS=`"-LS:\b\5\lib`""

@owenv
Copy link
Collaborator

owenv commented Feb 3, 2025

Thanks, really appreciate your work here! I'll see if I can test this on some of the other platforms

@compnerd
Copy link
Member Author

compnerd commented Feb 3, 2025

@owenv I can guarantee that it won't work on Linux at least! The missing piece is the find_package(SwiftCrypto) to wire up the swift-crypto dependency.

CMakeLists.txt Show resolved Hide resolved
@jakepetroules
Copy link
Collaborator

I know it's not typical CMake convention, but could we consider using some kind of wildcard pattern to pick up the swift files instead of listing them individually?

@compnerd
Copy link
Member Author

compnerd commented Feb 4, 2025

I know it's not typical CMake convention, but could we consider using some kind of wildcard pattern to pick up the swift files instead of listing them individually?

We can't do that reliably. The wild-carding (glob) would be applied at configure time. Any changes after the initial configuration (renaming, removal, addition) would be ignored.

@etcwilde
Copy link

etcwilde commented Feb 4, 2025

I know it's not typical CMake convention, but could we consider using some kind of wildcard pattern to pick up the swift files instead of listing them individually?

As noted on the comment above:

Globbing source files does not work and frequently causes issues with files being mysteriously omitted from the library when people try: https://discourse.cmake.org/t/cmake-doesnt-register-new-files-when-i-add-new-files

Dirtying the CMakeLists.txt file is what tells Ninja/underlying build system that it needs to re-run CMake to get the new definition of the target when doing incremental builds.

CMakeLists.txt Outdated Show resolved Hide resolved
@jakepetroules
Copy link
Collaborator

I know it's not typical CMake convention, but could we consider using some kind of wildcard pattern to pick up the swift files instead of listing them individually?

As noted on the comment above:

Globbing source files does not work and frequently causes issues with files being mysteriously omitted from the library when people try: https://discourse.cmake.org/t/cmake-doesnt-register-new-files-when-i-add-new-files

Dirtying the CMakeLists.txt file is what tells Ninja/underlying build system that it needs to re-run CMake to get the new definition of the target when doing incremental builds.

I haven't done any serious CMake work in 10+ years and had some slight hope the situation with wildcards might've improved since then, but I guess we'll just have to deal with the static lists for now. Thanks for confirming.

out/CMakeCache.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@owenv owenv left a comment

Choose a reason for hiding this comment

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

I won't claim to be a CMake expert, but this set of changes lgtm

@compnerd
Copy link
Member Author

compnerd commented Feb 5, 2025

This change now depends on #95. I believe that we are building everything but the tests now.

@compnerd compnerd force-pushed the cmake branch 2 times, most recently from 002a6f6 to 322ea2d Compare February 10, 2025 17:46
@compnerd
Copy link
Member Author

@swift-ci please smoke test

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
@compnerd
Copy link
Member Author

@swift-ci please test

Add support for building with CMake which is required to get the
toolchain bootstrapped. This partially addresses swiftlang#7.
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

Okay, this is finally ready. I've built with CMake and SPM locally. SPM's warnings about the unrecognized files are also gone. I think that we can go ahead and get this merged. We cannot enable the CI checks for this yet as this requires an updated toolchain on the Linux builders. That issue can be followed along at swiftlang/swift#79117

@owenv
Copy link
Collaborator

owenv commented Feb 12, 2025

@swift-ci please test macOS

@compnerd compnerd merged commit 97b2233 into swiftlang:main Feb 12, 2025
1 of 3 checks passed
@compnerd compnerd deleted the cmake branch February 12, 2025 22:44
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.

6 participants