Skip to content

Commit 03ba118

Browse files
committed
Add swiftCore library
This patch hooks up the swiftCore library build and gets it installing. This means that we have library evolution hooked up and vector types. Building it dynamically found that we had duplicate symbols, so fixed the swiftDemanglingCR library. Needed to hook up the availability macros. The flag configuration is for macOS, so we'll need to go through and figure out what it should look like for the other platforms too.
1 parent f3b5fcd commit 03ba118

File tree

11 files changed

+479
-5
lines changed

11 files changed

+479
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ Runtimes/**/*.gyb
9393
Runtimes/**/*.apinotes
9494
Runtimes/**/*.yaml
9595
Runtimes/**/*.inc
96+
Runtimes/**/*.json
97+
Runtimes/**/*.modulemap

Runtimes/Core/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
cmake_minimum_required(VERSION 3.26...3.29)
3333

3434
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
35+
include(CMakeWorkarounds)
3536
project(SwiftCore LANGUAGES C CXX Swift VERSION 6.1)
3637

3738
# The Swift standard library is not intended for use as a sub-library as part of
@@ -46,19 +47,27 @@ set(SwiftCore_SWIFTC_SOURCE_DIR
4647
"${PROJECT_SOURCE_DIR}/../../"
4748
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
4849

50+
include(GNUInstallDirs)
51+
include(AvailabilityMacros)
4952
include(CompilerSettings)
5053
include(DefaultSettings)
54+
include(EmitSwiftInterface)
5155
include(PlatformInfo)
5256
include(gyb)
5357

58+
option(SwiftCore_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries" OFF)
59+
5460
option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration" OFF)
5561
option(SwiftCore_ENABLE_OBJC_INTEROP "Enable runtime ObjC interop" OFF)
5662
option(SwiftCore_ENABLE_TYPE_PRINTING "Enable printing type names" OFF)
63+
option(SwiftCore_ENABLE_VECTOR_TYPES "Enable vector support" OFF)
5764

5865
option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" ${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS_default})
5966
option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" ${SwiftCore_ENABLE_RIUNTIME_LEAK_CHECKER_default})
6067
option(SwiftCore_ENABLE_REFLECTION "" OFF)
6168

69+
option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argument support" OFF)
70+
6271
option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support" OFF)
6372
set(SwiftCore_BACKTRACER_PATH "" CACHE STRING "Set a fixed path to the Swift backtracer")
6473

@@ -69,6 +78,8 @@ add_compile_definitions(
6978
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
7079
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
7180

81+
add_compile_options( $<$<AND:$<COMPILE_LANGUAGE:Swift>,$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>>:-enable-library-evolution>)
82+
7283
include_directories(include)
7384

7485
add_subdirectory(LLVMSupport)
@@ -77,3 +88,4 @@ add_subdirectory(Demangling)
7788
add_subdirectory(Threading)
7889
add_subdirectory(runtime)
7990
add_subdirectory(stubs)
91+
add_subdirectory(core)

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ target_include_directories(swiftDemangling
1919
"${SwiftCore_SWIFTC_SOURCE_DIR}/include"
2020
"${PROJECT_BINARY_DIR}/include")
2121

22+
target_link_libraries(swiftDemangling PRIVATE swiftShims)
23+
2224
if(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT)
23-
target_compile_definitions(swiftDemangling PRIVATE SWIFT_HAVE_CRASHREPORTERCLIENT)
24-
target_sources(swiftDemangling PRIVATE
25+
# We could likely pull the copy from the runtime sources
26+
add_library(swiftDemanglingCR OBJECT
2527
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/CrashReporter.cpp")
28+
target_link_libraries(swiftDemanglingCR PRIVATE swiftShims)
2629
endif()
2730

2831
if(SwiftCore_ENABLE_OBJC_INTEROP)

Runtimes/Core/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ target_include_directories(swiftShims INTERFACE
3434
$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}/../../>
3535
$<$<COMPILE_LANGUAGE:Swift>:${CMAKE_CURRENT_SOURCE_DIR}>)
3636
target_compile_options(swiftShims INTERFACE
37-
$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc$<SEMICOLON>-fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>)
37+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(STRINGS "${PROJECT_SOURCE_DIR}/../../utils/availability-macros.def" availability_defs)
2+
list(FILTER availability_defs EXCLUDE REGEX "^\\s*(#.*)?$")
3+
foreach(def ${availability_defs})
4+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -define-availability -Xfrontend \"${def}\">")
5+
endforeach()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file contains workarounds for dealing with bugs between CMake and the
2+
# Swift compiler.
3+
4+
# FIXME: This is a workaround for the broken Swift compiler that cannot
5+
# typecheck the Swift stdlib without crashing. <ADD RADAR HERE>.
6+
# This is manipulating undocumented CMake-internal variables that may
7+
# change behavior at any time and should not be relied on.
8+
set(CMAKE_Swift_NUM_THREADS 0)
9+
if(POLICY CMP0157)
10+
set(CMAKE_Swift_COMPILE_OBJECT "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -c <DEFINES> <FLAGS> <INCLUDES> <SOURCE>")
11+
12+
set(CMAKE_Swift_COMPILATION_MODE wholemodule)
13+
14+
if(NOT SwiftStdlib_NUM_LINK_JOBS MATCHES "^[0-9]+$")
15+
cmake_host_system_information(RESULT SwiftStdlib_NUM_LINK_JOBS QUERY NUMBER_OF_LOGICAL_CORES)
16+
endif()
17+
18+
set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -num-threads ${SwiftStdlib_NUM_LINK_JOBS} -emit-executable -o <TARGET> <FLAGS> <OBJECTS> <LINK_FLAGS> <LINK_LIBRARIES>")
19+
set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${SwiftStdlib_NUM_LINK_JOBS} -emit-library <CMAKE_SHARED_LIBRARY_Swift_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <SONAME_FLAG> <TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
20+
else()
21+
set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>")
22+
23+
set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
24+
25+
set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
26+
27+
set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>")
28+
set(CMAKE_Swift_ARCHIVE_FINISH "")
29+
30+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-wmo>)
31+
endif()

Runtimes/Core/cmake/modules/CompilerSettings.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
include(CheckSourceCompiles)
2+
include(CheckCompilerFlag)
3+
14
# Use C+17
25
set(SwiftCore_MIN_CXX_STANDARD 17)
36
# Unset CMAKE_CXX_STANDARD if it's too low and in the CMakeCache.txt
@@ -15,3 +18,39 @@ endif()
1518
set(CMAKE_CXX_STANDARD ${SwiftCore_MIN_CXX_STANDARD} CACHE STRING "C++ standard to conform to")
1619
set(CMAKE_CXX_STANDARD_REQUIRED YES)
1720
set(CMAKE_CXX_EXTENSIONS NO)
21+
22+
check_source_compiles(CXX
23+
"#if !(__has_attribute(swiftcall) && \
24+
__has_attribute(swift_context) && \
25+
__has_attribute(swift_error_result) && \
26+
__has_attribute(swift_indirect_result))
27+
#error CXX compiler must support Swift calling conventions
28+
#endif
29+
int main(void) { return 0; }"
30+
HAVE_SWIFTCALL)
31+
32+
if(NOT HAVE_SWIFTCALL)
33+
message(SEND_ERROR "CXX Compiler must support Swift calling conventions")
34+
endif()
35+
36+
check_source_compiles(CXX
37+
"#if !(__has_attribute(swiftasynccall) && \
38+
__has_attribute(swift_async_context))
39+
#error CXX compiler must support Swift async calling conventions
40+
#endif
41+
int main(void) { return 0; }"
42+
HAVE_SWIFT_ASYNC_CALL)
43+
44+
if(NOT HAVE_SWIFT_ASYNC_CALL)
45+
message(SEND_ERROR "CXX Compiler must support Swift async calling conventions")
46+
endif()
47+
48+
check_compiler_flag(Swift "-color-diagnostics" HAVE_SWIFT_COLOR_DIAGNOSTICS)
49+
if(HAVE_SWIFT_COLOR_DIAGNOSTICS)
50+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>)
51+
endif()
52+
53+
check_compiler_flag(Swift "-diagnostic-style swift" HAVE_SWIFT_DIAGNOSTIC_STYLE)
54+
if(HAVE_SWIFT_DIAGNOSTIC_STYLE)
55+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-diagnostic-style$<SEMICOLON>swift>)
56+
endif()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generate and install swift interface files
2+
3+
# TODO: CMake should learn how to model library evolution and generate this
4+
# stuff automatically.
5+
6+
7+
# Generate a swift interface file for the target if library evolution is enabled
8+
function(emit_swift_interface target)
9+
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
10+
target_compile_options(${target} PRIVATE
11+
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface>
12+
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface>
13+
$<$<COMPILE_LANGUAGE:Swift>:-library-level$<SEMICOLON>api>
14+
$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend$<SEMICOLON>-require-explicit-availability=ignore>)
15+
endif()
16+
endfunction()
17+
18+
# Install the generated swift interface file for the target if library evolution
19+
# is enabled.
20+
function(install_swift_interface target)
21+
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
22+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface"
23+
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftinterface"
24+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
25+
26+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface"
27+
RENAME "${SwiftCore_MODULE_TRIPLE}.private.swiftinterface"
28+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
29+
endif()
30+
endfunction()

0 commit comments

Comments
 (0)