-
Notifications
You must be signed in to change notification settings - Fork 205
Introduce Cmake support for SwiftFoundation #573
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
Conversation
|
@swift-ci please test |
|
@swift-ci please build toolchian |
Sources/Foundation/CMakeLists.txt
Outdated
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|
|
||
| file(GLOB_RECURSE _FoundationPreviewSources "*.swift") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not build the "FoundationPreview" package in this mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are aware of the limitation here that if you add a new file or remove a file you will need to do a clean build as the added/removed source will not be reflected in the build.
Sources/Foundation/CMakeLists.txt
Outdated
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|
|
||
| file(GLOB_RECURSE _FoundationPreviewSources "*.swift") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are aware of the limitation here that if you add a new file or remove a file you will need to do a clean build as the added/removed source will not be reflected in the build.
9ddc89f to
e92d120
Compare
73a1642 to
55170ad
Compare
8a45d5b to
5fafa69
Compare
cmake/modules/SwiftSupport.cmake
Outdated
| # | ||
| # If the current architecture is supported by Swift, sets ${result_var_name} | ||
| # with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR. | ||
| function(get_swift_host_arch result_var_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than hard-code each architecture, we can ask the compiler what the module triple is based on either the default target triple for the toolchain or if someone is trying to cross-compile, based on CMAKE_Swift_COMPILER_TARGET:
if(NOT SwiftFoundation_MODULE_TRIPLE)
# TODO: This logic should migrate to CMake once CMake supports installing swiftmodules
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
if(CMAKE_Swift_COMPILER_TARGET)
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
endif()
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
set(SwiftFoundation_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files")
mark_as_advanced(SwiftFoundation_MODULE_TRIPLE)
endif()
cmake/modules/SwiftSupport.cmake
Outdated
| $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule | ||
| DESTINATION lib/${swift}/${swift_os}/${swift_arch}) | ||
| endif() | ||
| endfunction() No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing trailing newline
e26766c to
06d706e
Compare
943535f to
9b51995
Compare
|
Merged all commits. Now this PR is ready for review |
|
@swift-ci please test |
9b51995 to
9641641
Compare
| # If building at desk, check out and link against the SwiftSyntax repo's targets | ||
| FetchContent_Declare(SwiftSyntax | ||
| GIT_REPOSITORY https://github.com/apple/swift-syntax.git | ||
| GIT_TAG 510.0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do much about it at the moment, but it's unfortunate that this tag doesn't have the changes for picking up the SWIFT_HOST_MODULE_TRIPLE automatically. So just as a heads up, you're likely to get folks forgetting to set that and asking about an the error message:
CMake Error at build/_deps/swiftsyntax-src/CMakeLists.txt:80 (message):
Host module triple required
The correct response will be to run swiftc -print-target-info manually and pull out the triple under target > moduleTriple and pass that to their CMake invocation e.g. cmake -G 'Ninja' -DSWIFT_HOST_MODULE_TRIPLE=x86_64-unknown-linux-gnu ....
dd38a58 to
e776427
Compare
cmake/modules/SwiftSupport.cmake
Outdated
| if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
| install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc | ||
| DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule | ||
| RENAME ${swift_arch}.swiftdoc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwiftFoundation_MODULE_TRIPLE.swiftdock
cmake/modules/SwiftSupport.cmake
Outdated
| else() | ||
| install(FILES | ||
| $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc | ||
| $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule | ||
| DESTINATION lib/${swift}/${swift_os}/${swift_arch}) | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove and only use if for all platforms.
|
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work. I was able to successfully build and run code against this build locally.
In the string_shims.h, it might be worth figuring out where we're pulling that header in in C++ mode and wrapping the declarations in extern "C" {} to ensure that they get mangled correctly everywhere. If they don't, we'll get a linker error saying that some _Z... C++ symbol doesn't exist because it should actually be looking for the C mangle.
|
|
||
| set(BUILD_TESTING NO) | ||
|
|
||
| set(COLLECTIONS_SINGLE_MODULE YES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay to leave them for now, but we should probably move these settings into a separate CMake cache file so that if folks need to cross-compile SwiftFoundation for use outside of the prebuilt SDK, they can do so in a way that is configurable.
daad9de to
8a8c4e3
Compare
8a8c4e3 to
6c41fba
Compare
|
@swift-ci please test |
Add Cmake support for SwiftFoundation which includes
module.modulemapfor_CShimsNote: I had to change
uuid.h's header guard because it's somehow conflicting with system ones while using Cmake to build.Testing Notes
In order to build
SwiftFoundationwith Cmake you will need to installcmakeandninja:brew install cmake && brew install ninjaCurrently the Cmake build for
SwiftFoundationICU(SwiftFoundation's dependency) is hitting two compiler crashes. To work around these issues, first download the nightly Swift snapshot newer than 4/25's build. Then add the following lines in the mainCMakeLists.txtfile, right aftercmake_minimum_required:As of now, the main
CMakeLists.txtdoes not fetch dependencies for you (yet). You'll have to manually checkoutSwiftFoundation's two dependencies:charles/cmake-support)release/1.1)Next, go to each directory and manually build them:
cmake -S . -B ./build -G Ninja && cd ./build && ninjaFinally, add these two lines to
SwiftFoundation's mainCMakeLists.txt, right below the two lines you just added:Make sure to use the
buildfolder above. This will instruct Cmake to use the dependencies you just checked out.Now you can finally build SwiftFoundation with Cmake: