From b92f9a743d1e350a9e2963a9a91f01130b2df7c0 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 17 Jun 2024 16:27:58 -0700 Subject: [PATCH 1/7] Add -Wno-int-conversion and -fPIC --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d6164e5f5..45faa45826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ 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) +set(CMAKE_POSITION_INDEPENDENT_CODE YES) + # Fetchable dependcies include(FetchContent) if (_SwiftFoundationICU_SourceDIR) @@ -98,6 +100,7 @@ list(APPEND _Foundation_common_build_flags "-Wno-unused-variable" "-Wno-unused-function" "-Wno-microsoft-enum-forward-reference" + "-Wno-int-conversion" "-fconstant-cfstrings" "-fexceptions" # TODO: not on OpenBSD "-fdollars-in-identifiers" From 770860b16e77102c10cfcdd4351be4d14463399f Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 17 Jun 2024 16:34:00 -0700 Subject: [PATCH 2/7] Move block runtime sources into separate ignored folder --- Sources/CoreFoundation/{ => BlockRuntime}/data.c | 0 .../{internalInclude => BlockRuntime/include}/Block.h | 0 .../{internalInclude => BlockRuntime/include}/Block_private.h | 0 Sources/CoreFoundation/{ => BlockRuntime}/runtime.c | 0 Sources/CoreFoundation/CMakeLists.txt | 2 -- 5 files changed, 2 deletions(-) rename Sources/CoreFoundation/{ => BlockRuntime}/data.c (100%) rename Sources/CoreFoundation/{internalInclude => BlockRuntime/include}/Block.h (100%) rename Sources/CoreFoundation/{internalInclude => BlockRuntime/include}/Block_private.h (100%) rename Sources/CoreFoundation/{ => BlockRuntime}/runtime.c (100%) diff --git a/Sources/CoreFoundation/data.c b/Sources/CoreFoundation/BlockRuntime/data.c similarity index 100% rename from Sources/CoreFoundation/data.c rename to Sources/CoreFoundation/BlockRuntime/data.c diff --git a/Sources/CoreFoundation/internalInclude/Block.h b/Sources/CoreFoundation/BlockRuntime/include/Block.h similarity index 100% rename from Sources/CoreFoundation/internalInclude/Block.h rename to Sources/CoreFoundation/BlockRuntime/include/Block.h diff --git a/Sources/CoreFoundation/internalInclude/Block_private.h b/Sources/CoreFoundation/BlockRuntime/include/Block_private.h similarity index 100% rename from Sources/CoreFoundation/internalInclude/Block_private.h rename to Sources/CoreFoundation/BlockRuntime/include/Block_private.h diff --git a/Sources/CoreFoundation/runtime.c b/Sources/CoreFoundation/BlockRuntime/runtime.c similarity index 100% rename from Sources/CoreFoundation/runtime.c rename to Sources/CoreFoundation/BlockRuntime/runtime.c diff --git a/Sources/CoreFoundation/CMakeLists.txt b/Sources/CoreFoundation/CMakeLists.txt index b5e62d7943..f55c892af9 100644 --- a/Sources/CoreFoundation/CMakeLists.txt +++ b/Sources/CoreFoundation/CMakeLists.txt @@ -97,8 +97,6 @@ add_library(CoreFoundation STATIC CFUUID.c CFWindowsUtilities.c CFXMLPreferencesDomain.c - data.c - runtime.c uuid.c) target_include_directories(CoreFoundation From 2bcd9bc00e716adcbb7a4c0c877a71734b25f418 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 17 Jun 2024 17:07:52 -0700 Subject: [PATCH 3/7] Install private static libs in static swift build --- Sources/CoreFoundation/CMakeLists.txt | 7 +++++++ Sources/_CFURLSessionInterface/CMakeLists.txt | 4 ++++ Sources/_CFXMLInterface/CMakeLists.txt | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/Sources/CoreFoundation/CMakeLists.txt b/Sources/CoreFoundation/CMakeLists.txt index f55c892af9..5090f4bc6a 100644 --- a/Sources/CoreFoundation/CMakeLists.txt +++ b/Sources/CoreFoundation/CMakeLists.txt @@ -121,3 +121,10 @@ install(DIRECTORY include/ DESTINATION lib/swift/CoreFoundation) + +if(NOT BUILD_SHARED_LIBS) + install(TARGETS CoreFoundation + ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + RUNTIME DESTINATION bin) +endif() diff --git a/Sources/_CFURLSessionInterface/CMakeLists.txt b/Sources/_CFURLSessionInterface/CMakeLists.txt index 09a6275fc1..d3a1b1b67f 100644 --- a/Sources/_CFURLSessionInterface/CMakeLists.txt +++ b/Sources/_CFURLSessionInterface/CMakeLists.txt @@ -32,4 +32,8 @@ target_link_libraries(_CFURLSessionInterface PRIVATE if(NOT BUILD_SHARED_LIBS) set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS _CFURLSessionInterface) + install(TARGETS _CFURLSessionInterface + ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + RUNTIME DESTINATION bin) endif() diff --git a/Sources/_CFXMLInterface/CMakeLists.txt b/Sources/_CFXMLInterface/CMakeLists.txt index 03bcec15c7..45085aadd5 100644 --- a/Sources/_CFXMLInterface/CMakeLists.txt +++ b/Sources/_CFXMLInterface/CMakeLists.txt @@ -31,4 +31,8 @@ target_link_libraries(_CFXMLInterface PRIVATE if(NOT BUILD_SHARED_LIBS) set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS _CFXMLInterface) + install(TARGETS _CFXMLInterface + ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME} + RUNTIME DESTINATION bin) endif() From ea3f3cd2ed7df5cef4c0d93b9ff147e7ddc35b55 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 17 Jun 2024 18:02:54 -0700 Subject: [PATCH 4/7] Don't include stdlib toolchain rpath --- Sources/Foundation/CMakeLists.txt | 3 +++ Sources/FoundationNetworking/CMakeLists.txt | 3 +++ Sources/FoundationXML/CMakeLists.txt | 3 +++ 3 files changed, 9 insertions(+) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index ea2fd38d6b..8be4f9c59d 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -155,6 +155,9 @@ target_link_libraries(Foundation FoundationEssentials FoundationInternationalization) +target_link_options(Foundation PRIVATE + "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(Foundation PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$") diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 5b738175eb..e863aac3d4 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -56,6 +56,9 @@ target_link_libraries(FoundationNetworking PUBLIC Foundation) +target_link_options(FoundationNetworking PRIVATE + "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(FoundationNetworking PROPERTIES INSTALL_RPATH "$ORIGIN") diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index f7477e33ce..44f0b01c6b 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -31,6 +31,9 @@ target_link_libraries(FoundationXML PUBLIC Foundation) +target_link_options(FoundationXML PRIVATE + "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN") From 70f6c715c51b0e08d66d26ca17c7bc3beba18536 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Tue, 18 Jun 2024 13:09:12 -0700 Subject: [PATCH 5/7] Autolink static libraries in static swift build --- Sources/Foundation/CMakeLists.txt | 7 +++++++ Sources/FoundationNetworking/CMakeLists.txt | 9 +++++++++ Sources/FoundationXML/CMakeLists.txt | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 8be4f9c59d..470364a0a2 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -155,6 +155,13 @@ target_link_libraries(Foundation FoundationEssentials FoundationInternationalization) +if(NOT BUILD_SHARED_LIBS) + target_compile_options(Foundation PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>") + target_compile_options(Foundation PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend _FoundationICU>") +endif() + target_link_options(Foundation PRIVATE "SHELL:-no-toolchain-stdlib-rpath") diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index e863aac3d4..33d6872ae7 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -56,6 +56,15 @@ target_link_libraries(FoundationNetworking PUBLIC Foundation) +if(NOT BUILD_SHARED_LIBS) + target_compile_options(FoundationNetworking PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend _CFURLSessionInterface>") + target_compile_options(FoundationNetworking PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>") + target_compile_options(FoundationNetworking PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend curl>") +endif() + target_link_options(FoundationNetworking PRIVATE "SHELL:-no-toolchain-stdlib-rpath") diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index 44f0b01c6b..e27bd67308 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -31,6 +31,15 @@ target_link_libraries(FoundationXML PUBLIC Foundation) +if(NOT BUILD_SHARED_LIBS) + target_compile_options(FoundationXML PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend _CFXMLInterface>") + target_compile_options(FoundationXML PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>") + target_compile_options(FoundationXML PRIVATE + "SHELL:$<$:-Xfrontend -public-autolink-library -Xfrontend xml2>") +endif() + target_link_options(FoundationXML PRIVATE "SHELL:-no-toolchain-stdlib-rpath") From 5537f13f2e7cbc66628f6abad14554ee722ca10a Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Thu, 20 Jun 2024 09:41:09 -0700 Subject: [PATCH 6/7] Bump WINVER/_WIN32_WINNT to Windows 10 --- .../CoreFoundation/internalInclude/CoreFoundation_Prefix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h b/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h index 2c41d2861f..9ef8f64a6c 100644 --- a/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h +++ b/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h @@ -119,11 +119,11 @@ typedef char * Class; #define WIN32_LEAN_AND_MEAN #ifndef WINVER -#define WINVER 0x0601 +#define WINVER 0x0A00 #endif #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0601 +#define _WIN32_WINNT 0x0A00 #endif // The order of these includes is important From 2f62b80711431ef215c0251c4d2d83bf518cbdbd Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Thu, 20 Jun 2024 15:27:14 -0700 Subject: [PATCH 7/7] Repair package manifest --- Package.swift | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Package.swift b/Package.swift index e31b1f1a18..1c34ce2981 100644 --- a/Package.swift +++ b/Package.swift @@ -20,6 +20,7 @@ let coreFoundationBuildSettings: [CSetting] = [ "-Wno-unused-variable", "-Wno-unused-function", "-Wno-microsoft-enum-forward-reference", + "-Wno-int-conversion", "-fconstant-cfstrings", "-fexceptions", // TODO: not on OpenBSD "-fdollars-in-identifiers", @@ -29,13 +30,12 @@ let coreFoundationBuildSettings: [CSetting] = [ "\(Context.packageDirectory)/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h", // /EHsc for Windows ]), - .unsafeFlags(["-I/usr/lib/swift"], .when(platforms: [.linux, .android])) // dispatch + .unsafeFlags(["-I/usr/lib/swift/Block"], .when(platforms: [.linux, .android])) // dispatch ] // For _CFURLSessionInterface, _CFXMLInterface let interfaceBuildSettings: [CSetting] = [ .headerSearchPath("../CoreFoundation/internalInclude"), - .headerSearchPath("../CoreFoundation/include"), .define("DEBUG", .when(configuration: .debug)), .define("CF_BUILDING_CF"), .define("DEPLOYMENT_ENABLE_LIBDISPATCH"), @@ -50,6 +50,7 @@ let interfaceBuildSettings: [CSetting] = [ "-Wno-unused-variable", "-Wno-unused-function", "-Wno-microsoft-enum-forward-reference", + "-Wno-int-conversion", "-fconstant-cfstrings", "-fexceptions", // TODO: not on OpenBSD "-fdollars-in-identifiers", @@ -57,7 +58,7 @@ let interfaceBuildSettings: [CSetting] = [ "-fcf-runtime-abi=swift" // /EHsc for Windows ]), - .unsafeFlags(["-I/usr/lib/swift"], .when(platforms: [.linux, .android])) // dispatch + .unsafeFlags(["-I/usr/lib/swift/Block"], .when(platforms: [.linux, .android])) // dispatch ] let swiftBuildSettings: [SwiftSetting] = [ @@ -78,11 +79,11 @@ let package = Package( dependencies: [ .package( url: "https://github.com/apple/swift-foundation-icu", - from: "0.0.7" + from: "0.0.8" ), .package( url: "https://github.com/apple/swift-foundation", - revision: "3297fb33b49ba2d1161ba12757891c7b91c73a3e" + revision: "ef8a7787c355edae3c142e4dff8767d05a32c51f" ), ], targets: [ @@ -91,7 +92,7 @@ let package = Package( dependencies: [ .product(name: "FoundationEssentials", package: "swift-foundation"), .product(name: "FoundationInternationalization", package: "swift-foundation"), - "_CoreFoundation" + "CoreFoundation" ], path: "Sources/Foundation", swiftSettings: swiftBuildSettings @@ -100,8 +101,8 @@ let package = Package( name: "FoundationXML", dependencies: [ .product(name: "FoundationEssentials", package: "swift-foundation"), - .targetItem(name: "Foundation", condition: nil), - "_CoreFoundation", + "Foundation", + "CoreFoundation", "_CFXMLInterface" ], path: "Sources/FoundationXML", @@ -111,25 +112,26 @@ let package = Package( name: "FoundationNetworking", dependencies: [ .product(name: "FoundationEssentials", package: "swift-foundation"), - .targetItem(name: "Foundation", condition: nil), - "_CoreFoundation", + "Foundation", + "CoreFoundation", "_CFURLSessionInterface" ], path: "Sources/FoundationNetworking", swiftSettings:swiftBuildSettings ), .target( - name: "_CoreFoundation", + name: "CoreFoundation", dependencies: [ .product(name: "_FoundationICU", package: "swift-foundation-icu"), ], path: "Sources/CoreFoundation", + exclude: ["BlockRuntime"], cSettings: coreFoundationBuildSettings ), .target( name: "_CFXMLInterface", dependencies: [ - "_CoreFoundation", + "CoreFoundation", "Clibxml2", ], path: "Sources/_CFXMLInterface", @@ -138,7 +140,7 @@ let package = Package( .target( name: "_CFURLSessionInterface", dependencies: [ - "_CoreFoundation", + "CoreFoundation", "Clibcurl", ], path: "Sources/_CFURLSessionInterface", @@ -163,15 +165,15 @@ let package = Package( .executableTarget( name: "plutil", dependencies: [ - .targetItem(name: "Foundation", condition: nil) + "Foundation" ] ), .executableTarget( name: "xdgTestHelper", dependencies: [ - .targetItem(name: "Foundation", condition: nil), - .targetItem(name: "FoundationXML", condition: nil), - .targetItem(name: "FoundationNetworking", condition: nil) + "Foundation", + "FoundationXML", + "FoundationNetworking" ] ), .target( @@ -181,16 +183,16 @@ let package = Package( // We believe Foundation is the only project that needs to take this rather drastic measure. name: "XCTest", dependencies: [ - .targetItem(name: "Foundation", condition: nil) + "Foundation" ], path: "Sources/XCTest" ), .testTarget( name: "TestFoundation", dependencies: [ - .targetItem(name: "Foundation", condition: nil), - .targetItem(name: "FoundationXML", condition: nil), - .targetItem(name: "FoundationNetworking", condition: nil), + "Foundation", + "FoundationXML", + "FoundationNetworking", .targetItem(name: "XCTest", condition: .when(platforms: [.linux])), "xdgTestHelper" ],