Skip to content

Re-core Foundation on top of swift-foundation (merge package branch into main) #5008

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

Merged
merged 98 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
3eb4fab
wip
parkera Feb 1, 2024
1115c11
wip
parkera Feb 1, 2024
5daa772
Basic Foundation package builds
parkera Feb 2, 2024
763145c
Reexport FoundationEssentials and start fixing build errors - error t…
parkera Feb 2, 2024
8017faa
Remove legacy Darwin files
parkera Feb 3, 2024
bf6c5e3
Builds with re-exported FoundationEssentials
parkera Feb 3, 2024
f1c0d8a
Remove a lot of old build stuff to focus on package
parkera Feb 3, 2024
8c08801
Ignore swiftpm file
parkera Feb 3, 2024
9582a2c
Remove more CMake cruft
parkera Feb 3, 2024
f816f15
Allow Date in plutil
parkera Feb 3, 2024
83a1f83
Moving tests WIP
parkera Feb 5, 2024
24dcbae
Got one test building
parkera Feb 6, 2024
6ba9edf
Add libcurl for CF
parkera Feb 6, 2024
9fc5349
Build CFXMLInterface and FoundationXML
parkera Feb 6, 2024
e09e811
Build FoundationNetworking
parkera Feb 7, 2024
55b2f94
Remove more cmake build files
parkera Feb 7, 2024
9db5173
Build FoundationXML/FoundationNetworking
parkera Feb 7, 2024
bfdf5f2
Don't rely on bridging for NSData
parkera Feb 7, 2024
f501e19
Work towards macOS build
parkera Feb 8, 2024
7914671
Ensure we're using the built-in CoreFoundation and not mixing things …
parkera Feb 10, 2024
0f87f9d
Use bridging again - relies on compiler from 2024-02-07 or later
parkera Feb 10, 2024
bd05761
Clean up export of essentials, and stop warning about resources
parkera Feb 10, 2024
11c4942
Use FoundationEssentials Locale
parkera Feb 10, 2024
e1e3bd3
Add deprecated API to Locale
parkera Feb 10, 2024
74b371d
Remove ability to unsafeBitCast from CFLocale to NSLocale
parkera Feb 12, 2024
60f6f7a
Recore Date
parkera Feb 15, 2024
1b88a3b
Stop assuming `CFSTR` is a constant-time expression with Clang 15 (#4…
kateinoigakukun Feb 15, 2024
7052e54
Depend on public branch of swift-foundation
parkera Feb 15, 2024
c54936a
Use SCL-F SPI import
parkera Feb 15, 2024
3d2c6cb
Use FoundationEssentials UUID
parkera Feb 15, 2024
2238ee6
Remove AttributedString from swift-corelibs-foundation in favor of sw…
parkera Feb 15, 2024
a5079cb
Fix a Locale bug
parkera Feb 15, 2024
ad4867b
Move Data support to NSData
parkera Feb 15, 2024
7dcee5e
Use Context to get package directory for relative paths in unicode data
parkera Feb 16, 2024
3b4b7b4
Use FoundationEssentials Calendar, TimeZone, DateComponents
parkera Feb 15, 2024
100517e
Remove obsolete Mirror test
parkera Feb 17, 2024
3e128d5
Use module bundle instead of main, for swiftpm compatibility
parkera Feb 22, 2024
53857d5
Fix bundle access, Calendar bridging
parkera Feb 22, 2024
1b4f09d
Merge changes from upstream swift-corelibs-foundation
parkera Mar 1, 2024
1df1dd8
Don't use SWIFT_CORELIBS_FOUNDATION_HAS_THREADS in header file
parkera Mar 1, 2024
431e765
Build xdgTestHelper
parkera Mar 1, 2024
4f91b6d
Fix some issues with Calendar identifier bridging
parkera Mar 1, 2024
fa7a2d1
Work towards fixing Data tests
parkera Mar 4, 2024
157195c
Merge upstream/main
parkera Mar 12, 2024
2fde124
Drop CocoaError from SCL-F, it is now in swift-foundation
parkera Mar 13, 2024
e141251
Remove duplicate error codes
parkera Mar 13, 2024
8f3ab77
Additional fixes for NSError
parkera Mar 13, 2024
dafd82b
Bridge from a CFTypeRef to a Swift value correctly
parkera Mar 13, 2024
97797b4
Adjust unit tests for new behaviors in swift-foundation
parkera Mar 13, 2024
5d08034
Ensure TimeZone is passed through to underlying components
parkera Mar 18, 2024
6a84869
Make sure to bridge self not just always the current locale
parkera Mar 18, 2024
5e6ca49
Update tests to account for new nonbreaking space behavior in formatt…
parkera Mar 18, 2024
5cd8466
Resolve a warning in the test build
parkera Mar 18, 2024
829f9cd
Avoid a warning in the test build
parkera Mar 20, 2024
b723193
Fix some expectations around process names
parkera Mar 20, 2024
249a466
Merge pull request #4927 from parkera/package
parkera Mar 27, 2024
f4566b9
Resolve -Wno-int-conversion warnings
jmschonfeld Mar 29, 2024
cd9a1a2
Make package SCF depend on Apple swift-foundation repo
jmschonfeld Mar 29, 2024
31c93c7
Fix Package test failures for Linux
jmschonfeld Apr 1, 2024
5b64137
Update swift-foundation/swift-foundation-icu dependencies (#4935)
jmschonfeld Apr 2, 2024
52d9d71
Remove SCF version of IndexPath (#4938)
jmschonfeld Apr 24, 2024
595a0d5
Remove SCF version of PropertyListEncoder/PropertyListDecoder (#4939)
jmschonfeld Apr 24, 2024
9494d4b
Remove ProcessInfo in favor of swift-foundation's implementation (#4945)
jmschonfeld May 2, 2024
d8f1bfe
Remove String APIs implemented in swift-foundation (#4946)
jmschonfeld May 6, 2024
6e5d962
Remove Collections+DataProtocol and some CocoaError extensions (#4956)
jmschonfeld May 14, 2024
cc5704d
Remove URL in favor of swift-foundation's URL (#4955)
jmschonfeld May 14, 2024
a9ffa77
CoreFoundation modularization and packaging improvements
parkera May 7, 2024
405627b
Merge pull request #4952 from parkera/parkera/build_package_macos
parkera May 16, 2024
6f4c134
Recore FileManager on top of FoundationEssentials.FileManager (#4957)
jmschonfeld May 17, 2024
2c5b4e2
Merge remote-tracking branch 'upstream/main' into package
parkera May 20, 2024
927e685
Merge pull request #4961 from parkera/package
parkera May 20, 2024
ce23015
Change the way we check for libcurl availability
parkera May 21, 2024
855f90f
Merge pull request #4962 from parkera/parkera/change_curl_feature_ava…
parkera May 21, 2024
19bde7e
Merge remote-tracking branch 'upstream/main' into package
parkera May 24, 2024
1b669a5
Merge pull request #4964 from parkera/package
parkera May 24, 2024
ad8bf7b
Remove URLQueryItem from swift-corelibs-foundation in favor of Founda…
iCharlesHu May 29, 2024
08e829c
Add upcall for FoundationEssentials to initialize NSNumbers (#4966)
jmschonfeld May 29, 2024
0f1a45b
Merge pull request #4967 from iCharlesHu/charles/remove-url-query-item
iCharlesHu May 29, 2024
a59a97a
NSData options should typealias to Data options (#4968)
jmschonfeld May 30, 2024
9a8e5ae
Remove additional unnecessary FileManager code (#4971)
jmschonfeld Jun 5, 2024
697cb9e
Merge main
parkera Jun 10, 2024
fbbe6fa
Merge pull request #4977 from parkera/package
parkera Jun 10, 2024
7e2f7fe
Include CFBase.h in CoreFoundation_Prefix.h (#4979)
jmschonfeld Jun 17, 2024
c772413
Introduce Cmake support for SwiftCorelibsFoundation
iCharlesHu May 18, 2024
e9e40df
Merge pull request #4959 from iCharlesHu/charles/cmake-support
iCharlesHu Jun 20, 2024
f4f5d7c
Various fixes to support building within the toolchain (#4985)
jmschonfeld Jun 21, 2024
67eb5cb
Add SWIFTCI_USE_LOCAL_DEPS build mode (#4986)
jmschonfeld Jun 21, 2024
1181ecb
[CMake] Add plutil to CMake build (#4987)
jmschonfeld Jun 24, 2024
27ae565
[CMake] Copy headers to known directory for direct client test builds…
jmschonfeld Jun 24, 2024
f28f4be
Remove Codable.swift (#4993)
jmschonfeld Jun 26, 2024
f186ff8
[Linux] Enable build-ids. (#4995)
al45tair Jun 27, 2024
f1c66e0
[CMake] Fix Windows Build (#4991)
jmschonfeld Jun 28, 2024
9118940
[CMake] Include GNUInstallDirs (#4996)
jmschonfeld Jun 28, 2024
06bd59d
Use FSR for Process executable path on Windows (#4999)
jmschonfeld Jul 8, 2024
082b0dc
Avoiding linking CF from outside of Foundation (#5003)
jmschonfeld Jul 11, 2024
ad15f44
[CMake] correctly apply -fcf-runtime-abi=swift on Windows (#5004)
jmschonfeld Jul 12, 2024
32cd74f
Fix include path to Dispatch
parkera Jun 24, 2024
fd80603
Merge pull request #5006 from parkera/parkera/fix_dispatch_path
parkera Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Mac OS X filesystem metadata
.DS_Store

Package.resolved

# Xcode user artifacts
xcuserdata/
project.xcworkspace
Expand All @@ -28,3 +30,4 @@ Build
*.swp
*.orig
.arcconfig
.swiftpm
248 changes: 120 additions & 128 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@

cmake_minimum_required(VERSION 3.15.1)
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2024 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.md for the list of Swift project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##

cmake_minimum_required(VERSION 3.24)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

# NOTE(compnerd) enable CMP0091 - select MSVC runtime based on
# CMAKE_MSVC_RUNTIME_LIBRARY. Requires CMake 3.15 or newer
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
if(POLICY CMP0156)
# Deduplicate linked libraries where appropriate
cmake_policy(SET CMP0156 NEW)
endif()

if(POLICY CMP0157)
# New Swift build model: improved incremental build performance and LSP support
cmake_policy(SET CMP0157 NEW)
endif()

if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER clang)
endif()

project(Foundation
LANGUAGES C Swift)
enable_testing()
LANGUAGES C Swift)

if(NOT SWIFT_SYSTEM_NAME)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
Expand All @@ -21,143 +41,115 @@ if(NOT SWIFT_SYSTEM_NAME)
endif()
endif()

# NOTE(compnerd) default to /MD or /MDd by default based on the configuration.
# Cache the variable to allow the user to alter the configuration.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE
STRING "MSVC Runtime Library")

if(CMAKE_VERSION VERSION_LESS 3.16.0)
if(NOT (CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin))
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ")
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP ":")
endif()
# Workaround for CMake 3.15 which doesn't link libraries properly on Windows
set(CMAKE_LINK_LIBRARY_FLAG "-l")
endif()

if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

option(BUILD_SHARED_LIBS "build shared libraries" ON)
option(BUILD_FULLY_STATIC "build fully static" NO)
option(HAS_LIBDISPATCH_API "has libdispatch API" ON)
option(FOUNDATION_ENABLE_FOUNDATION_NETWORKING "build FoundationNetworking module" ON)
option(FOUNDATION_BUILD_TOOLS "build tools" ON)
option(NS_CURL_ASSUME_FEATURES_MISSING "Assume that optional libcurl features are missing rather than test the library's version, for build debugging" NO)

if(HAS_LIBDISPATCH_API)
find_package(dispatch CONFIG REQUIRED)
endif()

find_package(ICU COMPONENTS uc i18n REQUIRED OPTIONAL_COMPONENTS data)

# This is needed if we're statically linking, otherwise we can't pull in Dispatch
# because we won't have RT::rt as a CMake target.
if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
find_package(LibRT)
# Optionally build tools (on by default) but only when building shared libraries
if(BUILD_SHARED_LIBS)
option(FOUNDATION_BUILD_TOOLS "build tools" ON)
endif()

include(SwiftSupport)
include(GNUInstallDirs)
include(XCTest)

set(CF_DEPLOYMENT_SWIFT YES CACHE BOOL "Build for Swift" FORCE)
set(CMAKE_POSITION_INDEPENDENT_CODE YES)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG OFF)
if(HAS_LIBDISPATCH_API)
find_package(Threads REQUIRED)
# Fetchable dependcies
include(FetchContent)
if (_SwiftFoundationICU_SourceDIR)
FetchContent_Declare(SwiftFoundationICU
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR})
else()
FetchContent_Declare(SwiftFoundationICU
GIT_REPOSITORY https://github.com/apple/swift-foundation-icu.git
GIT_TAG 0.0.8)
endif()

set(SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS NO)
add_subdirectory(CoreFoundation EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS})

# BlocksRuntime is already in libdispatch so it is only needed if libdispatch is
# NOT being used
if(NOT HAS_LIBDISPATCH_API)
add_subdirectory(Sources/BlocksRuntime)
if (_SwiftFoundation_SourceDIR)
FetchContent_Declare(SwiftFoundation
SOURCE_DIR ${_SwiftFoundation_SourceDIR})
else()
FetchContent_Declare(SwiftFoundation
GIT_REPOSITORY https://github.com/apple/swift-foundation.git
GIT_TAG main)
endif()

# Setup include paths for uuid/uuid.h
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/uuid-headers/uuid
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Sources/UUID/uuid.h ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h)
add_custom_target(uuid-headers
DEPENDS ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h)
add_dependencies(CoreFoundation uuid-headers)
target_include_directories(CoreFoundation PRIVATE
${CMAKE_BINARY_DIR}/uuid-headers
${CMAKE_CURRENT_BINARY_DIR}/CoreFoundation.framework/Headers)

add_subdirectory(Sources)
if(ENABLE_TESTING)
find_package(XCTest CONFIG REQUIRED)
add_subdirectory(Tests)
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)

include(CheckLinkerFlag)

check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)

# Precompute module triple for installation
if(NOT SwiftFoundation_MODULE_TRIPLE)
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()

if(NOT BUILD_SHARED_LIBS)
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
CoreFoundation CFXMLInterface)

if(NOT HAS_LIBDISPATCH_API)
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
BlocksRuntime)
endif()

install(TARGETS CoreFoundation CFXMLInterface
DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME})
# System dependencies (fail fast if dependencies are missing)
find_package(LibXml2 REQUIRED)
find_package(CURL REQUIRED)
find_package(dispatch CONFIG REQUIRED)

# Common build flags (_CFURLSessionInterface, _CFXMLInterface, CoreFoundation)
list(APPEND _Foundation_common_build_flags
"-DDEPLOYMENT_RUNTIME_SWIFT"
"-DCF_BUILDING_CF"
"-DDEPLOYMENT_ENABLE_LIBDISPATCH"
"-DHAVE_STRUCT_TIMESPEC"
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
"-Wno-shorten-64-to-32"
"-Wno-deprecated-declarations"
"-Wno-unreachable-code"
"-Wno-conditional-uninitialized"
"-Wno-unused-variable"
"-Wno-unused-function"
"-Wno-microsoft-enum-forward-reference"
"-Wno-int-conversion"
"-fblocks")

if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
list(APPEND _Foundation_common_build_flags
"-fconstant-cfstrings"
"-fdollars-in-identifiers"
"-fno-common"
"-fcf-runtime-abi=swift")

if(NOT CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
list(APPEND _Foundation_common_build_flags
"-fexceptions")
endif()
else()
list(APPEND _Foundation_common_build_flags
"/EHsc"
"/clang:-fcf-runtime-abi=swift")
endif()

if(FOUNDATION_ENABLE_FOUNDATION_NETWORKING)
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
CFURLSessionInterface)
install(TARGETS CFURLSessionInterface
DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME})
endif()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND _Foundation_common_build_flags
"-DDEBUG")
endif()

set(swift_lib_dir "lib/swift")
if(NOT BUILD_SHARED_LIBS)
set(swift_lib_dir "lib/swift_static")
# Swift build flags (Foundation, FoundationNetworking, FoundationXML)
set(_Foundation_swift_build_flags)
list(APPEND _Foundation_swift_build_flags
"-DDEPLOYMENT_RUNTIME_SWIFT"
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND _Foundation_common_build_flags
"-D_GNU_SOURCE"
"-I/usr/lib/swift") # dispatch
endif()

# TODO(compnerd) install as a Framework as that is how swift actually is built
install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/CoreFoundation.framework/Headers/
DESTINATION
${swift_lib_dir}/CoreFoundation
FILES_MATCHING PATTERN "*.h")
install(FILES
CoreFoundation/Base.subproj/$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:static/>module.map
DESTINATION
${swift_lib_dir}/CoreFoundation)
install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/CFURLSessionInterface.framework/Headers/
DESTINATION
${swift_lib_dir}/CFURLSessionInterface
FILES_MATCHING PATTERN "*.h")
install(FILES
CoreFoundation/URL.subproj/$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:static/>module.map
DESTINATION
${swift_lib_dir}/CFURLSessionInterface)
install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/CFXMLInterface.framework/Headers/
DESTINATION
${swift_lib_dir}/CFXMLInterface
FILES_MATCHING PATTERN "*.h")
install(FILES
CoreFoundation/Parsing.subproj/$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:static/>module.map
DESTINATION
${swift_lib_dir}/CFXMLInterface)
include(GNUInstallDirs)
include(FoundationSwiftSupport)

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
Loading