Skip to content

Various fixes to support building within the toolchain #4985

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 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
44 changes: 23 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand All @@ -50,14 +50,15 @@ 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",
"-fno-common",
"-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] = [
Expand All @@ -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: [
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -138,7 +140,7 @@ let package = Package(
.target(
name: "_CFURLSessionInterface",
dependencies: [
"_CoreFoundation",
"CoreFoundation",
"Clibcurl",
],
path: "Sources/_CFURLSessionInterface",
Expand All @@ -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(
Expand All @@ -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"
],
Expand Down
9 changes: 7 additions & 2 deletions Sources/CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ add_library(CoreFoundation STATIC
CFUUID.c
CFWindowsUtilities.c
CFXMLPreferencesDomain.c
data.c
runtime.c
uuid.c)

target_include_directories(CoreFoundation
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Sources/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ target_link_libraries(Foundation
FoundationEssentials
FoundationInternationalization)

if(NOT BUILD_SHARED_LIBS)
target_compile_options(Foundation PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
target_compile_options(Foundation PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-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 "$<TARGET_FILE_DIR:swiftDispatch>")
Expand Down
12 changes: 12 additions & 0 deletions Sources/FoundationNetworking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ target_link_libraries(FoundationNetworking
PUBLIC
Foundation)

if(NOT BUILD_SHARED_LIBS)
target_compile_options(FoundationNetworking PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFURLSessionInterface>")
target_compile_options(FoundationNetworking PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
target_compile_options(FoundationNetworking PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-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")

Expand Down
12 changes: 12 additions & 0 deletions Sources/FoundationXML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ target_link_libraries(FoundationXML
PUBLIC
Foundation)

if(NOT BUILD_SHARED_LIBS)
target_compile_options(FoundationXML PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFXMLInterface>")
target_compile_options(FoundationXML PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
target_compile_options(FoundationXML PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-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")

Expand Down
4 changes: 4 additions & 0 deletions Sources/_CFURLSessionInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 4 additions & 0 deletions Sources/_CFXMLInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()