Skip to content

Commit 9642995

Browse files
committed
Build runtime library
Getting the runtime libraries building, while also ironing out more of the macro definitions and flags.
1 parent 8dd5e50 commit 9642995

File tree

7 files changed

+225
-13
lines changed

7 files changed

+225
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ Runtimes/**/*.def
9292
Runtimes/**/*.gyb
9393
Runtimes/**/*.apinotes
9494
Runtimes/**/*.yaml
95+
Runtimes/**/*.inc

Runtimes/Core/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1+
# Notes:
2+
#
3+
# The Demangling library uses `#if SWIFT_HAVE_CRASHREPORTERCLIENT` while the
4+
# runtime library uses `#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT` to toggle that
5+
# functionality. When building the demangling library, the macro should be set
6+
# to 0 or 1 to indicate the presence of the crashreporter.
7+
# When building the runtime library, the existence of the macro indicates the
8+
# presence of the crashreporter.
9+
#
10+
# Runtime library pulls sources and headers from compiler sources (ThreadSanitizer)
11+
# Demangling library pulls sources and headers from compiler sources (all)
12+
#
13+
#
14+
# gyb pulls sources from compiler sources
15+
16+
17+
# TODO:
18+
# Platform support:
19+
# - Work on/Verify cross-compiling
20+
# - Work on/Verify Windows and Linux native builds
21+
# Embedded
22+
# -- -Xfrontend -emit-empty-object-file
23+
# Catalyst Support
24+
# -- Will need shadow invocations to generate swiftmodules for Swift parts
25+
# Install *.abi.json, swiftdoc, and swiftsourceinfo
26+
127
cmake_minimum_required(VERSION 3.26...3.29)
28+
229
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
330
project(SwiftCore LANGUAGES C CXX Swift VERSION 6.1)
431

@@ -15,14 +42,30 @@ set(SwiftCore_SWIFTC_SOURCE_DIR
1542
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
1643

1744
include(CompilerSettings)
45+
include(DefaultSettings)
1846

1947
option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration" OFF)
2048
option(SwiftCore_ENABLE_OBJC_INTEROP "Enable runtime ObjC interop" OFF)
2149
option(SwiftCore_ENABLE_TYPE_PRINTING "Enable printing type names" OFF)
2250

51+
option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" ${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS_default})
52+
option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" ${SwiftCore_ENABLE_RIUNTIME_LEAK_CHECKER_default})
53+
option(SwiftCore_ENABLE_REFLECTION "" OFF)
54+
55+
option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support" OFF)
56+
set(SwiftCore_BACKTRACER_PATH "" CACHE STRING "Set a fixed path to the Swift backtracer")
57+
58+
set(SwiftCore_OBJECT_FORMAT ${SwiftCore_OBJECT_FORMAT} CACHE STRING "Object format")
59+
60+
add_compile_definitions(
61+
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_OBJC_INTEROP=$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>>
62+
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
63+
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
64+
2365
include_directories(include)
2466

2567
add_subdirectory(LLVMSupport)
2668
add_subdirectory(SwiftShims/swift/shims)
2769
add_subdirectory(Demangling)
2870
add_subdirectory(Threading)
71+
add_subdirectory(runtime)

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# FIXME: Refactor demangling library so that we aren't pulling sources from
22
# the compiler.
3-
add_library(swiftDemangling STATIC
3+
add_library(swiftDemangling OBJECT
44
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Context.cpp"
55
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Demangler.cpp"
66
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/ManglingUtils.cpp"
@@ -9,27 +9,26 @@ add_library(swiftDemangling STATIC
99
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
1010
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/NodeDumper.cpp"
1111
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Errors.cpp")
12-
target_compile_definitions(swiftDemangling PRIVATE swiftCore_EXPORTS)
12+
target_compile_definitions(swiftDemangling PRIVATE swiftCore_EXPORTS
13+
-DSWIFT_SUPPORT_OLD_MANGLING=$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>
14+
$<$<BOOL:${SwiftCore_ENABLE_TYPE_PRINTING}>:-DSWIFT_STDLIB_HAS_TYPE_PRINTING>
15+
-DSWIFT_HAVE_CRASHREPORTERCLIENT=$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>)
1316

1417
target_include_directories(swiftDemangling
15-
PRIVATE "${PROJECT_SOURCE_DIR}/../../include")
18+
PRIVATE
19+
"${SwiftCore_SWIFTC_SOURCE_DIR}/include"
20+
"${PROJECT_BINARY_DIR}/include")
1621

1722
if(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT)
1823
target_compile_definitions(swiftDemangling PRIVATE SWIFT_HAVE_CRASHREPORTERCLIENT)
19-
target_sources(swiftDemangling PRIVATE "${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/CrashReporter.cpp")
24+
target_sources(swiftDemangling PRIVATE
25+
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/CrashReporter.cpp")
2026
endif()
2127

2228
if(SwiftCore_ENABLE_OBJC_INTEROP)
2329
target_sources(swiftDemangling PRIVATE
2430
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
2531
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp")
26-
target_compile_options(swiftDemangling PRIVATE -DSWIFT_SUPPORT_OLD_MANGLING=1)
27-
else()
28-
target_compile_options(swiftDemangling PRIVATE -DSWIFT_SUPPORT_OLD_MANGLING=0)
29-
endif()
30-
31-
if(SwiftCore_ENABLE_TYPE_PRINTING)
32-
target_compile_definitions(swiftDemangling PRIVATE SWIFT_STDLIB_HAS_TYPE_PRINTING)
3332
endif()
3433

3534
if(LINUX OR BSD)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is designed to setup reasonable defaults for the various settings so
2+
# that configuring a build for a given platform is likely to build
3+
# out-of-the-box without customization. This does not mean that it is the only
4+
# way that will work. The config files under `cmake/configs` are build
5+
# configurations that are actually shipping.
6+
7+
set(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT_default OFF)
8+
set(SwiftCore_ENABLE_OBJC_INTEROP_default OFF)
9+
set(SwiftCore_ENABLE_TYPE_PRINTING_default ON)
10+
set(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS_default OFF)
11+
set(SwiftCore_ENABLE_BACKTRACING_default OFF)
12+
set(SwiftCore_BACKTRACER_PATH_default "")
13+
14+
if(APPLE)
15+
set(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT_default ON)
16+
elseif(CMAKE_SYSTEM_NAME STREQUAL "WASM")
17+
set(SwiftCore_OBJECT_FORMAT_default "elf")
18+
elseif(LINUX)
19+
set(SwiftCore_OBJECT_FORMAT_default "elf")
20+
elseif(WIN32)
21+
set(SwiftCore_OBJECT_FORMAT_default "coff")
22+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is processed by CMake.
2+
// See https://cmake.org/cmake/help/v3.0/command/configure_file.html.
3+
4+
#ifndef SWIFT_RUNTIME_CMAKECONFIG_H
5+
#define SWIFT_RUNTIME_CMAKECONFIG_H
6+
7+
#cmakedefine01 SWIFT_BNI_OS_BUILD
8+
#cmakedefine01 SWIFT_BNI_XCODE_BUILD
9+
10+
#define SWIFT_VERSION_MAJOR "@SwiftCore_VERSION_MAJOR@"
11+
#define SWIFT_VERSION_MINOR "@SwiftCore_VERSION_MINOR@"
12+
13+
#endif

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# TODO: clean this up so it's less Apple-specific.
2+
# Detect B&I builds.
3+
set(SWIFT_BNI_OS_BUILD FALSE)
4+
set(SWIFT_BNI_XCODE_BUILD FALSE)
5+
if(DEFINED ENV{RC_XBS})
6+
if((NOT DEFINED ENV{RC_XCODE} OR NOT "$ENV{RC_XCODE}") AND (NOT DEFINED ENV{RC_PLAYGROUNDS} OR NOT "$ENV{RC_PLAYGROUNDS}"))
7+
set(SWIFT_BNI_OS_BUILD TRUE)
8+
else()
9+
set(SWIFT_BNI_XCODE_BUILD TRUE)
10+
endif()
11+
endif()
12+
13+
configure_file("CMakeConfig.h.in"
14+
"${PROJECT_BINARY_DIR}/include/swift/Runtime/CMakeConfig.h"
15+
ESCAPE_QUOTES @ONLY)
16+
17+
add_library(swiftRuntime OBJECT
18+
"${PROJECT_SOURCE_DIR}/CompatibilityOverride/CompatibilityOverride.cpp"
19+
AnyHashableSupport.cpp
20+
Array.cpp
21+
AutoDiffSupport.cpp
22+
Bincompat.cpp
23+
BytecodeLayouts.cpp
24+
Casting.cpp
25+
CrashReporter.cpp
26+
Demangle.cpp
27+
DynamicCast.cpp
28+
Enum.cpp
29+
EnvironmentVariables.cpp
30+
ErrorObjectCommon.cpp
31+
ErrorObjectNative.cpp
32+
Errors.cpp
33+
ErrorDefaultImpls.cpp
34+
Exception.cpp
35+
Exclusivity.cpp
36+
ExistentialContainer.cpp
37+
Float16Support.cpp
38+
FoundationSupport.cpp
39+
FunctionReplacement.cpp
40+
GenericMetadataBuilder.cpp
41+
Heap.cpp
42+
HeapObject.cpp
43+
ImageInspectionCommon.cpp
44+
ImageInspectionMachO.cpp
45+
ImageInspectionELF.cpp
46+
ImageInspectionCOFF.cpp
47+
ImageInspectionStatic.cpp
48+
ImageInspectionWasm.cpp
49+
SymbolInfo.cpp
50+
KeyPaths.cpp
51+
KnownMetadata.cpp
52+
LibPrespecialized.cpp
53+
Metadata.cpp
54+
MetadataLookup.cpp
55+
Numeric.cpp
56+
Once.cpp
57+
Paths.cpp
58+
Portability.cpp
59+
ProtocolConformance.cpp
60+
RefCount.cpp
61+
ReflectionMirror.cpp
62+
RuntimeInvocationsTracking.cpp
63+
SwiftDtoa.cpp
64+
SwiftTLSContext.cpp
65+
ThreadingError.cpp
66+
Tracing.cpp
67+
AccessibleFunction.cpp
68+
Win32.cpp)
69+
70+
# TODO: Probably worth considering putting half of these in a RuntimeConfig.h.in
71+
# file rather than pushing them through macro flags.
72+
target_compile_definitions(swiftRuntime
73+
PRIVATE
74+
-DSWIFT_RUNTIME
75+
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntime
76+
-DswiftCore_EXPORTS
77+
-DSWIFT_LIBRARY_EVOLUTION=$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>
78+
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>
79+
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
80+
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
81+
$<$<BOOL:${SwiftCore_BACKTRACER_PATH}>:-DSWIFT_RUNTIME_FIXED_BACKTRACER_PATH="${SwiftCore_BACKTRACER_PATH}">)
82+
83+
target_include_directories(swiftRuntime PRIVATE
84+
"${PROJECT_BINARY_DIR}/include"
85+
"${CMAKE_CURRENT_SOURCE_DIR}")
86+
87+
target_link_libraries(swiftRuntime PRIVATE swiftShims)
88+
89+
# FIXME: Refactor so that we're not pulling sources from the compiler files
90+
target_sources(swiftRuntime PRIVATE
91+
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Threading/ThreadSanitizer.cpp")
92+
93+
# FIXME: Private.h uses `Demangler.h` and `TypeLookupError.h` from the compiler
94+
# headers. We should split out the parts that are needed by the runtime
95+
# to avoid pulling in headers from the compiler.
96+
target_include_directories(swiftRuntime PRIVATE
97+
"${SwiftCore_SWIFTC_SOURCE_DIR}/include")
98+
99+
if(SwiftCore_ENABLE_BACKTRACING)
100+
target_sources(swiftRuntime PRIVATE
101+
Backtrace.cpp
102+
BacktraceUtils.cpp
103+
CrashHandlerMacOS.cpp
104+
CrashHandlerLinux.cpp)
105+
endif()
106+
107+
if(SwiftCore_ENABLE_OBJC_INTEROP)
108+
target_sources(swiftRuntime PRIVATE
109+
ErrorObject.mm
110+
SwiftObject.mm
111+
SwiftValue.mm
112+
ReflectionMirrorObjC.mm
113+
ObjCRuntimeGetImageNameFromClass.mm)
114+
endif()
115+
116+
string(TOLOWER "${SwiftCore_OBJECT_FORMAT}x" SwiftCore_OBJECT_FORMAT)
117+
if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
118+
add_library(swiftrt OBJECT SwiftRT-ELF-WASM.cpp)
119+
target_compile_definitions(swiftrt PRIVATE
120+
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>)
121+
target_link_libraries(swiftrt PRIVATE swiftShims)
122+
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
123+
elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
124+
add_library(swiftrt OBJECT SwiftRT-COFF.cpp)
125+
target_compile_definitions(swiftrt PRIVATE
126+
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>)
127+
target_link_libraries(swiftrt PRIVATE swiftShims)
128+
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
129+
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")
130+
message(SEND_ERROR "Unknown object format '${SwiftCore_OBJECT_FORMAT}'")
131+
endif()

Runtimes/Resync.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function(copy_library_sources name from_prefix to_prefix)
2828
"${StdlibSources}/${from_prefix}/${name}/*.def"
2929
"${StdlibSources}/${from_prefix}/${name}/*.gyb"
3030
"${StdlibSources}/${from_prefix}/${name}/*.apinotes"
31-
"${StdlibSources}/${from_prefix}/${name}/*.yaml")
31+
"${StdlibSources}/${from_prefix}/${name}/*.yaml"
32+
"${StdlibSources}/${from_prefix}/${name}/*.inc")
3233

3334
foreach(file ${filenames})
3435
# Get and create the directory
@@ -53,7 +54,9 @@ copy_library_sources(include "" "Core")
5354

5455
set(CoreLibs
5556
LLVMSupport
56-
SwiftShims)
57+
SwiftShims
58+
runtime
59+
CompatibilityOverride)
5760

5861
# Add these as we get them building
5962
# core

0 commit comments

Comments
 (0)