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" 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" ], 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..5090f4bc6a 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 @@ -123,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/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 diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index ea2fd38d6b..470364a0a2 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -155,6 +155,16 @@ 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") + set_target_properties(Foundation PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$") diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 5b738175eb..33d6872ae7 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -56,6 +56,18 @@ 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") + set_target_properties(FoundationNetworking PROPERTIES INSTALL_RPATH "$ORIGIN") diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index f7477e33ce..e27bd67308 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -31,6 +31,18 @@ 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") + set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN") 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()