Skip to content

Commit f4f5d7c

Browse files
authored
Various fixes to support building within the toolchain (#4985)
* Add -Wno-int-conversion and -fPIC * Move block runtime sources into separate ignored folder * Install private static libs in static swift build * Don't include stdlib toolchain rpath * Autolink static libraries in static swift build * Bump WINVER/_WIN32_WINNT to Windows 10 * Repair package manifest
1 parent e9e40df commit f4f5d7c

File tree

13 files changed

+77
-25
lines changed

13 files changed

+77
-25
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
4646
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4747
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
4848

49+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
50+
4951
# Fetchable dependcies
5052
include(FetchContent)
5153
if (_SwiftFoundationICU_SourceDIR)
@@ -98,6 +100,7 @@ list(APPEND _Foundation_common_build_flags
98100
"-Wno-unused-variable"
99101
"-Wno-unused-function"
100102
"-Wno-microsoft-enum-forward-reference"
103+
"-Wno-int-conversion"
101104
"-fconstant-cfstrings"
102105
"-fexceptions" # TODO: not on OpenBSD
103106
"-fdollars-in-identifiers"

Package.swift

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let coreFoundationBuildSettings: [CSetting] = [
2020
"-Wno-unused-variable",
2121
"-Wno-unused-function",
2222
"-Wno-microsoft-enum-forward-reference",
23+
"-Wno-int-conversion",
2324
"-fconstant-cfstrings",
2425
"-fexceptions", // TODO: not on OpenBSD
2526
"-fdollars-in-identifiers",
@@ -29,13 +30,12 @@ let coreFoundationBuildSettings: [CSetting] = [
2930
"\(Context.packageDirectory)/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h",
3031
// /EHsc for Windows
3132
]),
32-
.unsafeFlags(["-I/usr/lib/swift"], .when(platforms: [.linux, .android])) // dispatch
33+
.unsafeFlags(["-I/usr/lib/swift/Block"], .when(platforms: [.linux, .android])) // dispatch
3334
]
3435

3536
// For _CFURLSessionInterface, _CFXMLInterface
3637
let interfaceBuildSettings: [CSetting] = [
3738
.headerSearchPath("../CoreFoundation/internalInclude"),
38-
.headerSearchPath("../CoreFoundation/include"),
3939
.define("DEBUG", .when(configuration: .debug)),
4040
.define("CF_BUILDING_CF"),
4141
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
@@ -50,14 +50,15 @@ let interfaceBuildSettings: [CSetting] = [
5050
"-Wno-unused-variable",
5151
"-Wno-unused-function",
5252
"-Wno-microsoft-enum-forward-reference",
53+
"-Wno-int-conversion",
5354
"-fconstant-cfstrings",
5455
"-fexceptions", // TODO: not on OpenBSD
5556
"-fdollars-in-identifiers",
5657
"-fno-common",
5758
"-fcf-runtime-abi=swift"
5859
// /EHsc for Windows
5960
]),
60-
.unsafeFlags(["-I/usr/lib/swift"], .when(platforms: [.linux, .android])) // dispatch
61+
.unsafeFlags(["-I/usr/lib/swift/Block"], .when(platforms: [.linux, .android])) // dispatch
6162
]
6263

6364
let swiftBuildSettings: [SwiftSetting] = [
@@ -78,11 +79,11 @@ let package = Package(
7879
dependencies: [
7980
.package(
8081
url: "https://github.com/apple/swift-foundation-icu",
81-
from: "0.0.7"
82+
from: "0.0.8"
8283
),
8384
.package(
8485
url: "https://github.com/apple/swift-foundation",
85-
revision: "3297fb33b49ba2d1161ba12757891c7b91c73a3e"
86+
revision: "ef8a7787c355edae3c142e4dff8767d05a32c51f"
8687
),
8788
],
8889
targets: [
@@ -91,7 +92,7 @@ let package = Package(
9192
dependencies: [
9293
.product(name: "FoundationEssentials", package: "swift-foundation"),
9394
.product(name: "FoundationInternationalization", package: "swift-foundation"),
94-
"_CoreFoundation"
95+
"CoreFoundation"
9596
],
9697
path: "Sources/Foundation",
9798
swiftSettings: swiftBuildSettings
@@ -100,8 +101,8 @@ let package = Package(
100101
name: "FoundationXML",
101102
dependencies: [
102103
.product(name: "FoundationEssentials", package: "swift-foundation"),
103-
.targetItem(name: "Foundation", condition: nil),
104-
"_CoreFoundation",
104+
"Foundation",
105+
"CoreFoundation",
105106
"_CFXMLInterface"
106107
],
107108
path: "Sources/FoundationXML",
@@ -111,25 +112,26 @@ let package = Package(
111112
name: "FoundationNetworking",
112113
dependencies: [
113114
.product(name: "FoundationEssentials", package: "swift-foundation"),
114-
.targetItem(name: "Foundation", condition: nil),
115-
"_CoreFoundation",
115+
"Foundation",
116+
"CoreFoundation",
116117
"_CFURLSessionInterface"
117118
],
118119
path: "Sources/FoundationNetworking",
119120
swiftSettings:swiftBuildSettings
120121
),
121122
.target(
122-
name: "_CoreFoundation",
123+
name: "CoreFoundation",
123124
dependencies: [
124125
.product(name: "_FoundationICU", package: "swift-foundation-icu"),
125126
],
126127
path: "Sources/CoreFoundation",
128+
exclude: ["BlockRuntime"],
127129
cSettings: coreFoundationBuildSettings
128130
),
129131
.target(
130132
name: "_CFXMLInterface",
131133
dependencies: [
132-
"_CoreFoundation",
134+
"CoreFoundation",
133135
"Clibxml2",
134136
],
135137
path: "Sources/_CFXMLInterface",
@@ -138,7 +140,7 @@ let package = Package(
138140
.target(
139141
name: "_CFURLSessionInterface",
140142
dependencies: [
141-
"_CoreFoundation",
143+
"CoreFoundation",
142144
"Clibcurl",
143145
],
144146
path: "Sources/_CFURLSessionInterface",
@@ -163,15 +165,15 @@ let package = Package(
163165
.executableTarget(
164166
name: "plutil",
165167
dependencies: [
166-
.targetItem(name: "Foundation", condition: nil)
168+
"Foundation"
167169
]
168170
),
169171
.executableTarget(
170172
name: "xdgTestHelper",
171173
dependencies: [
172-
.targetItem(name: "Foundation", condition: nil),
173-
.targetItem(name: "FoundationXML", condition: nil),
174-
.targetItem(name: "FoundationNetworking", condition: nil)
174+
"Foundation",
175+
"FoundationXML",
176+
"FoundationNetworking"
175177
]
176178
),
177179
.target(
@@ -181,16 +183,16 @@ let package = Package(
181183
// We believe Foundation is the only project that needs to take this rather drastic measure.
182184
name: "XCTest",
183185
dependencies: [
184-
.targetItem(name: "Foundation", condition: nil)
186+
"Foundation"
185187
],
186188
path: "Sources/XCTest"
187189
),
188190
.testTarget(
189191
name: "TestFoundation",
190192
dependencies: [
191-
.targetItem(name: "Foundation", condition: nil),
192-
.targetItem(name: "FoundationXML", condition: nil),
193-
.targetItem(name: "FoundationNetworking", condition: nil),
193+
"Foundation",
194+
"FoundationXML",
195+
"FoundationNetworking",
194196
.targetItem(name: "XCTest", condition: .when(platforms: [.linux])),
195197
"xdgTestHelper"
196198
],

Sources/CoreFoundation/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ add_library(CoreFoundation STATIC
9797
CFUUID.c
9898
CFWindowsUtilities.c
9999
CFXMLPreferencesDomain.c
100-
data.c
101-
runtime.c
102100
uuid.c)
103101

104102
target_include_directories(CoreFoundation
@@ -123,3 +121,10 @@ install(DIRECTORY
123121
include/
124122
DESTINATION
125123
lib/swift/CoreFoundation)
124+
125+
if(NOT BUILD_SHARED_LIBS)
126+
install(TARGETS CoreFoundation
127+
ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
128+
LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
129+
RUNTIME DESTINATION bin)
130+
endif()

Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ typedef char * Class;
119119
#define WIN32_LEAN_AND_MEAN
120120

121121
#ifndef WINVER
122-
#define WINVER 0x0601
122+
#define WINVER 0x0A00
123123
#endif
124124

125125
#ifndef _WIN32_WINNT
126-
#define _WIN32_WINNT 0x0601
126+
#define _WIN32_WINNT 0x0A00
127127
#endif
128128

129129
// The order of these includes is important

Sources/Foundation/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ target_link_libraries(Foundation
155155
FoundationEssentials
156156
FoundationInternationalization)
157157

158+
if(NOT BUILD_SHARED_LIBS)
159+
target_compile_options(Foundation PRIVATE
160+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
161+
target_compile_options(Foundation PRIVATE
162+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _FoundationICU>")
163+
endif()
164+
165+
target_link_options(Foundation PRIVATE
166+
"SHELL:-no-toolchain-stdlib-rpath")
167+
158168
set_target_properties(Foundation PROPERTIES
159169
INSTALL_RPATH "$ORIGIN"
160170
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>")

Sources/FoundationNetworking/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ target_link_libraries(FoundationNetworking
5656
PUBLIC
5757
Foundation)
5858

59+
if(NOT BUILD_SHARED_LIBS)
60+
target_compile_options(FoundationNetworking PRIVATE
61+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFURLSessionInterface>")
62+
target_compile_options(FoundationNetworking PRIVATE
63+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
64+
target_compile_options(FoundationNetworking PRIVATE
65+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend curl>")
66+
endif()
67+
68+
target_link_options(FoundationNetworking PRIVATE
69+
"SHELL:-no-toolchain-stdlib-rpath")
70+
5971
set_target_properties(FoundationNetworking PROPERTIES
6072
INSTALL_RPATH "$ORIGIN")
6173

Sources/FoundationXML/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ target_link_libraries(FoundationXML
3131
PUBLIC
3232
Foundation)
3333

34+
if(NOT BUILD_SHARED_LIBS)
35+
target_compile_options(FoundationXML PRIVATE
36+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFXMLInterface>")
37+
target_compile_options(FoundationXML PRIVATE
38+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend CoreFoundation>")
39+
target_compile_options(FoundationXML PRIVATE
40+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend xml2>")
41+
endif()
42+
43+
target_link_options(FoundationXML PRIVATE
44+
"SHELL:-no-toolchain-stdlib-rpath")
45+
3446
set_target_properties(FoundationXML PROPERTIES
3547
INSTALL_RPATH "$ORIGIN")
3648

Sources/_CFURLSessionInterface/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ target_link_libraries(_CFURLSessionInterface PRIVATE
3232

3333
if(NOT BUILD_SHARED_LIBS)
3434
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS _CFURLSessionInterface)
35+
install(TARGETS _CFURLSessionInterface
36+
ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
37+
LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
38+
RUNTIME DESTINATION bin)
3539
endif()

Sources/_CFXMLInterface/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ target_link_libraries(_CFXMLInterface PRIVATE
3131

3232
if(NOT BUILD_SHARED_LIBS)
3333
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS _CFXMLInterface)
34+
install(TARGETS _CFXMLInterface
35+
ARCHIVE DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
36+
LIBRARY DESTINATION lib/swift_static/${SWIFT_SYSTEM_NAME}
37+
RUNTIME DESTINATION bin)
3438
endif()

0 commit comments

Comments
 (0)