mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Build runtime library
Getting the runtime libraries building, while also ironing out more of the macro definitions and flags.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -92,3 +92,4 @@ Runtimes/**/*.def
|
||||
Runtimes/**/*.gyb
|
||||
Runtimes/**/*.apinotes
|
||||
Runtimes/**/*.yaml
|
||||
Runtimes/**/*.inc
|
||||
|
||||
@@ -1,4 +1,31 @@
|
||||
# Notes:
|
||||
#
|
||||
# The Demangling library uses `#if SWIFT_HAVE_CRASHREPORTERCLIENT` while the
|
||||
# runtime library uses `#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT` to toggle that
|
||||
# functionality. When building the demangling library, the macro should be set
|
||||
# to 0 or 1 to indicate the presence of the crashreporter.
|
||||
# When building the runtime library, the existence of the macro indicates the
|
||||
# presence of the crashreporter.
|
||||
#
|
||||
# Runtime library pulls sources and headers from compiler sources (ThreadSanitizer)
|
||||
# Demangling library pulls sources and headers from compiler sources (all)
|
||||
#
|
||||
#
|
||||
# gyb pulls sources from compiler sources
|
||||
|
||||
|
||||
# TODO:
|
||||
# Platform support:
|
||||
# - Work on/Verify cross-compiling
|
||||
# - Work on/Verify Windows and Linux native builds
|
||||
# Embedded
|
||||
# -- -Xfrontend -emit-empty-object-file
|
||||
# Catalyst Support
|
||||
# -- Will need shadow invocations to generate swiftmodules for Swift parts
|
||||
# Install *.abi.json, swiftdoc, and swiftsourceinfo
|
||||
|
||||
cmake_minimum_required(VERSION 3.26...3.29)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
|
||||
project(SwiftCore LANGUAGES C CXX Swift VERSION 6.1)
|
||||
|
||||
@@ -15,14 +42,30 @@ set(SwiftCore_SWIFTC_SOURCE_DIR
|
||||
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
|
||||
|
||||
include(CompilerSettings)
|
||||
include(DefaultSettings)
|
||||
|
||||
option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration" OFF)
|
||||
option(SwiftCore_ENABLE_OBJC_INTEROP "Enable runtime ObjC interop" OFF)
|
||||
option(SwiftCore_ENABLE_TYPE_PRINTING "Enable printing type names" OFF)
|
||||
|
||||
option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" ${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS_default})
|
||||
option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" ${SwiftCore_ENABLE_RIUNTIME_LEAK_CHECKER_default})
|
||||
option(SwiftCore_ENABLE_REFLECTION "" OFF)
|
||||
|
||||
option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support" OFF)
|
||||
set(SwiftCore_BACKTRACER_PATH "" CACHE STRING "Set a fixed path to the Swift backtracer")
|
||||
|
||||
set(SwiftCore_OBJECT_FORMAT ${SwiftCore_OBJECT_FORMAT} CACHE STRING "Object format")
|
||||
|
||||
add_compile_definitions(
|
||||
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_OBJC_INTEROP=$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>>
|
||||
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
|
||||
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
add_subdirectory(LLVMSupport)
|
||||
add_subdirectory(SwiftShims/swift/shims)
|
||||
add_subdirectory(Demangling)
|
||||
add_subdirectory(Threading)
|
||||
add_subdirectory(runtime)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# FIXME: Refactor demangling library so that we aren't pulling sources from
|
||||
# the compiler.
|
||||
add_library(swiftDemangling STATIC
|
||||
add_library(swiftDemangling OBJECT
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Context.cpp"
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Demangler.cpp"
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/ManglingUtils.cpp"
|
||||
@@ -9,27 +9,26 @@ add_library(swiftDemangling STATIC
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/NodeDumper.cpp"
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Errors.cpp")
|
||||
target_compile_definitions(swiftDemangling PRIVATE swiftCore_EXPORTS)
|
||||
target_compile_definitions(swiftDemangling PRIVATE swiftCore_EXPORTS
|
||||
-DSWIFT_SUPPORT_OLD_MANGLING=$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>
|
||||
$<$<BOOL:${SwiftCore_ENABLE_TYPE_PRINTING}>:-DSWIFT_STDLIB_HAS_TYPE_PRINTING>
|
||||
-DSWIFT_HAVE_CRASHREPORTERCLIENT=$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>)
|
||||
|
||||
target_include_directories(swiftDemangling
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/../../include")
|
||||
PRIVATE
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/include"
|
||||
"${PROJECT_BINARY_DIR}/include")
|
||||
|
||||
if(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT)
|
||||
target_compile_definitions(swiftDemangling PRIVATE SWIFT_HAVE_CRASHREPORTERCLIENT)
|
||||
target_sources(swiftDemangling PRIVATE "${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/CrashReporter.cpp")
|
||||
target_sources(swiftDemangling PRIVATE
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/CrashReporter.cpp")
|
||||
endif()
|
||||
|
||||
if(SwiftCore_ENABLE_OBJC_INTEROP)
|
||||
target_sources(swiftDemangling PRIVATE
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp")
|
||||
target_compile_options(swiftDemangling PRIVATE -DSWIFT_SUPPORT_OLD_MANGLING=1)
|
||||
else()
|
||||
target_compile_options(swiftDemangling PRIVATE -DSWIFT_SUPPORT_OLD_MANGLING=0)
|
||||
endif()
|
||||
|
||||
if(SwiftCore_ENABLE_TYPE_PRINTING)
|
||||
target_compile_definitions(swiftDemangling PRIVATE SWIFT_STDLIB_HAS_TYPE_PRINTING)
|
||||
endif()
|
||||
|
||||
if(LINUX OR BSD)
|
||||
|
||||
22
Runtimes/Core/cmake/modules/DefaultSettings.cmake
Normal file
22
Runtimes/Core/cmake/modules/DefaultSettings.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
# This file is designed to setup reasonable defaults for the various settings so
|
||||
# that configuring a build for a given platform is likely to build
|
||||
# out-of-the-box without customization. This does not mean that it is the only
|
||||
# way that will work. The config files under `cmake/configs` are build
|
||||
# configurations that are actually shipping.
|
||||
|
||||
set(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT_default OFF)
|
||||
set(SwiftCore_ENABLE_OBJC_INTEROP_default OFF)
|
||||
set(SwiftCore_ENABLE_TYPE_PRINTING_default ON)
|
||||
set(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS_default OFF)
|
||||
set(SwiftCore_ENABLE_BACKTRACING_default OFF)
|
||||
set(SwiftCore_BACKTRACER_PATH_default "")
|
||||
|
||||
if(APPLE)
|
||||
set(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT_default ON)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "WASM")
|
||||
set(SwiftCore_OBJECT_FORMAT_default "elf")
|
||||
elseif(LINUX)
|
||||
set(SwiftCore_OBJECT_FORMAT_default "elf")
|
||||
elseif(WIN32)
|
||||
set(SwiftCore_OBJECT_FORMAT_default "coff")
|
||||
endif()
|
||||
13
Runtimes/Core/runtime/CMakeConfig.h.in
Normal file
13
Runtimes/Core/runtime/CMakeConfig.h.in
Normal file
@@ -0,0 +1,13 @@
|
||||
// This file is processed by CMake.
|
||||
// See https://cmake.org/cmake/help/v3.0/command/configure_file.html.
|
||||
|
||||
#ifndef SWIFT_RUNTIME_CMAKECONFIG_H
|
||||
#define SWIFT_RUNTIME_CMAKECONFIG_H
|
||||
|
||||
#cmakedefine01 SWIFT_BNI_OS_BUILD
|
||||
#cmakedefine01 SWIFT_BNI_XCODE_BUILD
|
||||
|
||||
#define SWIFT_VERSION_MAJOR "@SwiftCore_VERSION_MAJOR@"
|
||||
#define SWIFT_VERSION_MINOR "@SwiftCore_VERSION_MINOR@"
|
||||
|
||||
#endif
|
||||
131
Runtimes/Core/runtime/CMakeLists.txt
Normal file
131
Runtimes/Core/runtime/CMakeLists.txt
Normal file
@@ -0,0 +1,131 @@
|
||||
# TODO: clean this up so it's less Apple-specific.
|
||||
# Detect B&I builds.
|
||||
set(SWIFT_BNI_OS_BUILD FALSE)
|
||||
set(SWIFT_BNI_XCODE_BUILD FALSE)
|
||||
if(DEFINED ENV{RC_XBS})
|
||||
if((NOT DEFINED ENV{RC_XCODE} OR NOT "$ENV{RC_XCODE}") AND (NOT DEFINED ENV{RC_PLAYGROUNDS} OR NOT "$ENV{RC_PLAYGROUNDS}"))
|
||||
set(SWIFT_BNI_OS_BUILD TRUE)
|
||||
else()
|
||||
set(SWIFT_BNI_XCODE_BUILD TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
configure_file("CMakeConfig.h.in"
|
||||
"${PROJECT_BINARY_DIR}/include/swift/Runtime/CMakeConfig.h"
|
||||
ESCAPE_QUOTES @ONLY)
|
||||
|
||||
add_library(swiftRuntime OBJECT
|
||||
"${PROJECT_SOURCE_DIR}/CompatibilityOverride/CompatibilityOverride.cpp"
|
||||
AnyHashableSupport.cpp
|
||||
Array.cpp
|
||||
AutoDiffSupport.cpp
|
||||
Bincompat.cpp
|
||||
BytecodeLayouts.cpp
|
||||
Casting.cpp
|
||||
CrashReporter.cpp
|
||||
Demangle.cpp
|
||||
DynamicCast.cpp
|
||||
Enum.cpp
|
||||
EnvironmentVariables.cpp
|
||||
ErrorObjectCommon.cpp
|
||||
ErrorObjectNative.cpp
|
||||
Errors.cpp
|
||||
ErrorDefaultImpls.cpp
|
||||
Exception.cpp
|
||||
Exclusivity.cpp
|
||||
ExistentialContainer.cpp
|
||||
Float16Support.cpp
|
||||
FoundationSupport.cpp
|
||||
FunctionReplacement.cpp
|
||||
GenericMetadataBuilder.cpp
|
||||
Heap.cpp
|
||||
HeapObject.cpp
|
||||
ImageInspectionCommon.cpp
|
||||
ImageInspectionMachO.cpp
|
||||
ImageInspectionELF.cpp
|
||||
ImageInspectionCOFF.cpp
|
||||
ImageInspectionStatic.cpp
|
||||
ImageInspectionWasm.cpp
|
||||
SymbolInfo.cpp
|
||||
KeyPaths.cpp
|
||||
KnownMetadata.cpp
|
||||
LibPrespecialized.cpp
|
||||
Metadata.cpp
|
||||
MetadataLookup.cpp
|
||||
Numeric.cpp
|
||||
Once.cpp
|
||||
Paths.cpp
|
||||
Portability.cpp
|
||||
ProtocolConformance.cpp
|
||||
RefCount.cpp
|
||||
ReflectionMirror.cpp
|
||||
RuntimeInvocationsTracking.cpp
|
||||
SwiftDtoa.cpp
|
||||
SwiftTLSContext.cpp
|
||||
ThreadingError.cpp
|
||||
Tracing.cpp
|
||||
AccessibleFunction.cpp
|
||||
Win32.cpp)
|
||||
|
||||
# TODO: Probably worth considering putting half of these in a RuntimeConfig.h.in
|
||||
# file rather than pushing them through macro flags.
|
||||
target_compile_definitions(swiftRuntime
|
||||
PRIVATE
|
||||
-DSWIFT_RUNTIME
|
||||
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntime
|
||||
-DswiftCore_EXPORTS
|
||||
-DSWIFT_LIBRARY_EVOLUTION=$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>
|
||||
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>
|
||||
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
|
||||
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
|
||||
$<$<BOOL:${SwiftCore_BACKTRACER_PATH}>:-DSWIFT_RUNTIME_FIXED_BACKTRACER_PATH="${SwiftCore_BACKTRACER_PATH}">)
|
||||
|
||||
target_include_directories(swiftRuntime PRIVATE
|
||||
"${PROJECT_BINARY_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
target_link_libraries(swiftRuntime PRIVATE swiftShims)
|
||||
|
||||
# FIXME: Refactor so that we're not pulling sources from the compiler files
|
||||
target_sources(swiftRuntime PRIVATE
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Threading/ThreadSanitizer.cpp")
|
||||
|
||||
# FIXME: Private.h uses `Demangler.h` and `TypeLookupError.h` from the compiler
|
||||
# headers. We should split out the parts that are needed by the runtime
|
||||
# to avoid pulling in headers from the compiler.
|
||||
target_include_directories(swiftRuntime PRIVATE
|
||||
"${SwiftCore_SWIFTC_SOURCE_DIR}/include")
|
||||
|
||||
if(SwiftCore_ENABLE_BACKTRACING)
|
||||
target_sources(swiftRuntime PRIVATE
|
||||
Backtrace.cpp
|
||||
BacktraceUtils.cpp
|
||||
CrashHandlerMacOS.cpp
|
||||
CrashHandlerLinux.cpp)
|
||||
endif()
|
||||
|
||||
if(SwiftCore_ENABLE_OBJC_INTEROP)
|
||||
target_sources(swiftRuntime PRIVATE
|
||||
ErrorObject.mm
|
||||
SwiftObject.mm
|
||||
SwiftValue.mm
|
||||
ReflectionMirrorObjC.mm
|
||||
ObjCRuntimeGetImageNameFromClass.mm)
|
||||
endif()
|
||||
|
||||
string(TOLOWER "${SwiftCore_OBJECT_FORMAT}x" SwiftCore_OBJECT_FORMAT)
|
||||
if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
|
||||
add_library(swiftrt OBJECT SwiftRT-ELF-WASM.cpp)
|
||||
target_compile_definitions(swiftrt PRIVATE
|
||||
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>)
|
||||
target_link_libraries(swiftrt PRIVATE swiftShims)
|
||||
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
|
||||
elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
|
||||
add_library(swiftrt OBJECT SwiftRT-COFF.cpp)
|
||||
target_compile_definitions(swiftrt PRIVATE
|
||||
-DSWIFT_ENABLE_BACKTRACING=$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>)
|
||||
target_link_libraries(swiftrt PRIVATE swiftShims)
|
||||
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
|
||||
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")
|
||||
message(SEND_ERROR "Unknown object format '${SwiftCore_OBJECT_FORMAT}'")
|
||||
endif()
|
||||
@@ -28,7 +28,8 @@ function(copy_library_sources name from_prefix to_prefix)
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.def"
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.gyb"
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.apinotes"
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.yaml")
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.yaml"
|
||||
"${StdlibSources}/${from_prefix}/${name}/*.inc")
|
||||
|
||||
foreach(file ${filenames})
|
||||
# Get and create the directory
|
||||
@@ -53,7 +54,9 @@ copy_library_sources(include "" "Core")
|
||||
|
||||
set(CoreLibs
|
||||
LLVMSupport
|
||||
SwiftShims)
|
||||
SwiftShims
|
||||
runtime
|
||||
CompatibilityOverride)
|
||||
|
||||
# Add these as we get them building
|
||||
# core
|
||||
|
||||
Reference in New Issue
Block a user