Skip to content

Commit 87d1a97

Browse files
committed
Make CF buildable outside of Foundation
1 parent 1d1ddba commit 87d1a97

File tree

7 files changed

+260
-5
lines changed

7 files changed

+260
-5
lines changed

CoreFoundation/Base.subproj/CFBase.h

+15
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,30 @@ CF_EXTERN_C_BEGIN
302302

303303

304304
#if !__has_feature(nullability)
305+
#ifndef _Nullable
306+
#define _Nullable
307+
#endif
308+
305309
#ifndef __nullable
306310
#define __nullable
307311
#endif
312+
308313
#ifndef __nonnull
309314
#define __nonnull
310315
#endif
316+
317+
#ifndef _Nonnull
318+
#define _Nonnull
319+
#endif
320+
311321
#ifndef __null_unspecified
312322
#define __null_unspecified
313323
#endif
324+
325+
#ifndef _Null_unspecified
326+
#define _Null_unspecified
327+
#endif
328+
314329
#endif
315330

316331

CoreFoundation/String.subproj/CFCharacterSetData.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
.global _C_LABEL(__CFCharacterSetBitmapData)
1313
_C_LABEL(__CFCharacterSetBitmapData):
14-
.incbin "CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap"
14+
.incbin CF_CHARACTERSET_BITMAP
1515

1616
.global _C_LABEL(__CFCharacterSetBitmapDataEnd)
1717
_C_LABEL(__CFCharacterSetBitmapDataEnd):

CoreFoundation/String.subproj/CFUniCharPropertyDatabase.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
.global _C_LABEL(__CFUniCharPropertyDatabase)
1313
_C_LABEL(__CFUniCharPropertyDatabase):
14-
.incbin "CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data"
14+
.incbin CF_CHARACTERSET_UNICHAR_DB
1515

1616
.global _C_LABEL(__CFUniCharPropertyDatabaseEnd)
1717
_C_LABEL(__CFUniCharPropertyDatabaseEnd):

CoreFoundation/String.subproj/CFUnicodeData.S

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#if defined(__BIG_ENDIAN__)
1313
.global _C_LABEL(__CFUnicodeDataB)
1414
_C_LABEL(__CFUnicodeDataB):
15-
.incbin "CoreFoundation/CharacterSets/CFUnicodeData-B.mapping"
15+
.incbin CF_CHARACTERSET_UNICODE_DATA_B
1616

1717
.global _C_LABEL(__CFUnicodeDataBEnd)
1818
_C_LABEL(__CFUnicodeDataBEnd):
@@ -24,7 +24,7 @@ _C_LABEL(__CFUnicodeDataBSize):
2424
#else
2525
.global _C_LABEL(__CFUnicodeDataL)
2626
_C_LABEL(__CFUnicodeDataL):
27-
.incbin "CoreFoundation/CharacterSets/CFUnicodeData-L.mapping"
27+
.incbin CF_CHARACTERSET_UNICODE_DATA_L
2828

2929
.global _C_LABEL(__CFUnicodeDataLEnd)
3030
_C_LABEL(__CFUnicodeDataLEnd):

CoreFoundation/build.py

+225
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
script = Script()
2+
3+
cf = StaticLibrary("CoreFoundation")
4+
5+
cf.GCC_PREFIX_HEADER = 'Base.subproj/CoreFoundation_Prefix.h'
6+
7+
if Configuration.current.target.sdk == OSType.Linux:
8+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE '
9+
Configuration.current.requires_pkg_config = True
10+
elif Configuration.current.target.sdk == OSType.FreeBSD:
11+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 '
12+
elif Configuration.current.target.sdk == OSType.MacOSX:
13+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_MACOSX '
14+
15+
cf.ASFLAGS = " ".join([
16+
'-DCF_CHARACTERSET_BITMAP=\\"CharacterSets/CFCharacterSetBitmaps.bitmap\\"','
17+
'-DCF_CHARACTERSET_UNICHAR_DB=\\"CharacterSets/CFUniCharPropertyDatabase.data\\"','
18+
'-DCF_CHARACTERSET_UNICODE_DATA_B=\\"CharacterSets/CFUnicodeData-B.mapping\\"','
19+
'-DCF_CHARACTERSET_UNICODE_DATA_L=\\"CharacterSets/CFUnicodeData-L.mapping\\"','
20+
])
21+
22+
cf.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift"
23+
cf.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
24+
cf.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
25+
cf.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
26+
cf.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
27+
28+
cf.CFLAGS += " ".join([
29+
'-DU_SHOW_DRAFT_API',
30+
'-DCF_BUILDING_CF',
31+
'-DDEPLOYMENT_RUNTIME_SWIFT',
32+
'-fconstant-cfstrings',
33+
'-fexceptions',
34+
'-Wno-shorten-64-to-32',
35+
'-Wno-deprecated-declarations',
36+
'-Wno-unreachable-code',
37+
'-Wno-conditional-uninitialized',
38+
'-Wno-unused-variable',
39+
'-Wno-int-conversion',
40+
'-Wno-unused-function',
41+
'-I${SYSROOT}/usr/include/libxml2',
42+
'-I./',
43+
])
44+
45+
headers = CopyHeaders(
46+
module = 'Base.subproj/module.modulemap',
47+
public = [
48+
'Stream.subproj/CFStream.h',
49+
'String.subproj/CFStringEncodingExt.h',
50+
'Base.subproj/SwiftRuntime/CoreFoundation.h',
51+
'Base.subproj/SwiftRuntime/TargetConditionals.h',
52+
'RunLoop.subproj/CFMessagePort.h',
53+
'Collections.subproj/CFBinaryHeap.h',
54+
'PlugIn.subproj/CFBundle.h',
55+
'Locale.subproj/CFCalendar.h',
56+
'Collections.subproj/CFBitVector.h',
57+
'Base.subproj/CFAvailability.h',
58+
'Collections.subproj/CFTree.h',
59+
'NumberDate.subproj/CFTimeZone.h',
60+
'Error.subproj/CFError.h',
61+
'Collections.subproj/CFBag.h',
62+
'PlugIn.subproj/CFPlugIn.h',
63+
'Parsing.subproj/CFXMLParser.h',
64+
'String.subproj/CFString.h',
65+
'Collections.subproj/CFSet.h',
66+
'Base.subproj/CFUUID.h',
67+
'NumberDate.subproj/CFDate.h',
68+
'Collections.subproj/CFDictionary.h',
69+
'Base.subproj/CFByteOrder.h',
70+
'AppServices.subproj/CFUserNotification.h',
71+
'Base.subproj/CFBase.h',
72+
'Preferences.subproj/CFPreferences.h',
73+
'Locale.subproj/CFLocale.h',
74+
'RunLoop.subproj/CFSocket.h',
75+
'Parsing.subproj/CFPropertyList.h',
76+
'Collections.subproj/CFArray.h',
77+
'RunLoop.subproj/CFRunLoop.h',
78+
'URL.subproj/CFURLAccess.h',
79+
'Locale.subproj/CFDateFormatter.h',
80+
'RunLoop.subproj/CFMachPort.h',
81+
'PlugIn.subproj/CFPlugInCOM.h',
82+
'Base.subproj/CFUtilities.h',
83+
'Parsing.subproj/CFXMLNode.h',
84+
'URL.subproj/CFURLComponents.h',
85+
'URL.subproj/CFURL.h',
86+
'Locale.subproj/CFNumberFormatter.h',
87+
'String.subproj/CFCharacterSet.h',
88+
'NumberDate.subproj/CFNumber.h',
89+
'Collections.subproj/CFData.h',
90+
'String.subproj/CFAttributedString.h',
91+
],
92+
private = [
93+
'Base.subproj/ForSwiftFoundationOnly.h',
94+
'Base.subproj/ForFoundationOnly.h',
95+
'String.subproj/CFBurstTrie.h',
96+
'Error.subproj/CFError_Private.h',
97+
'URL.subproj/CFURLPriv.h',
98+
'Base.subproj/CFLogUtilities.h',
99+
'PlugIn.subproj/CFBundlePriv.h',
100+
'StringEncodings.subproj/CFStringEncodingConverter.h',
101+
'Stream.subproj/CFStreamAbstract.h',
102+
'Base.subproj/CFInternal.h',
103+
'Parsing.subproj/CFXMLInputStream.h',
104+
'Parsing.subproj/CFXMLInterface.h',
105+
'PlugIn.subproj/CFPlugIn_Factory.h',
106+
'String.subproj/CFStringLocalizedFormattingInternal.h',
107+
'PlugIn.subproj/CFBundle_Internal.h',
108+
'StringEncodings.subproj/CFStringEncodingConverterPriv.h',
109+
'Collections.subproj/CFBasicHash.h',
110+
'StringEncodings.subproj/CFStringEncodingDatabase.h',
111+
'StringEncodings.subproj/CFUnicodeDecomposition.h',
112+
'Stream.subproj/CFStreamInternal.h',
113+
'PlugIn.subproj/CFBundle_BinaryTypes.h',
114+
'Locale.subproj/CFICULogging.h',
115+
'Locale.subproj/CFLocaleInternal.h',
116+
'StringEncodings.subproj/CFUnicodePrecomposition.h',
117+
'Base.subproj/CFPriv.h',
118+
'StringEncodings.subproj/CFUniCharPriv.h',
119+
'URL.subproj/CFURL.inc.h',
120+
'NumberDate.subproj/CFBigNumber.h',
121+
'StringEncodings.subproj/CFUniChar.h',
122+
'StringEncodings.subproj/CFStringEncodingConverterExt.h',
123+
'Collections.subproj/CFStorage.h',
124+
'Base.subproj/CFRuntime.h',
125+
'String.subproj/CFStringDefaultEncoding.h',
126+
'String.subproj/CFCharacterSetPriv.h',
127+
'Stream.subproj/CFStreamPriv.h',
128+
'StringEncodings.subproj/CFICUConverters.h',
129+
'String.subproj/CFRegularExpression.h',
130+
'String.subproj/CFRunArray.h',
131+
],
132+
project = [
133+
])
134+
135+
cf.add_phase(headers)
136+
137+
sources = CompileSources([
138+
'Base.subproj/CFBase.c',
139+
'Base.subproj/CFFileUtilities.c',
140+
'Base.subproj/CFPlatform.c',
141+
'Base.subproj/CFRuntime.c',
142+
'Base.subproj/CFSortFunctions.c',
143+
'Base.subproj/CFSystemDirectories.c',
144+
'Base.subproj/CFUtilities.c',
145+
'Base.subproj/CFUUID.c',
146+
'Collections.subproj/CFArray.c',
147+
'Collections.subproj/CFBag.c',
148+
'Collections.subproj/CFBasicHash.c',
149+
'Collections.subproj/CFBinaryHeap.c',
150+
'Collections.subproj/CFBitVector.c',
151+
'Collections.subproj/CFData.c',
152+
'Collections.subproj/CFDictionary.c',
153+
'Collections.subproj/CFSet.c',
154+
'Collections.subproj/CFStorage.c',
155+
'Collections.subproj/CFTree.c',
156+
'Error.subproj/CFError.c',
157+
'Locale.subproj/CFCalendar.c',
158+
'Locale.subproj/CFDateFormatter.c',
159+
'Locale.subproj/CFLocale.c',
160+
'Locale.subproj/CFLocaleIdentifier.c',
161+
'Locale.subproj/CFLocaleKeys.c',
162+
'Locale.subproj/CFNumberFormatter.c',
163+
'NumberDate.subproj/CFBigNumber.c',
164+
'NumberDate.subproj/CFDate.c',
165+
'NumberDate.subproj/CFNumber.c',
166+
'NumberDate.subproj/CFTimeZone.c',
167+
'Parsing.subproj/CFBinaryPList.c',
168+
'Parsing.subproj/CFOldStylePList.c',
169+
'Parsing.subproj/CFPropertyList.c',
170+
'Parsing.subproj/CFXMLInputStream.c',
171+
'Parsing.subproj/CFXMLNode.c',
172+
'Parsing.subproj/CFXMLParser.c',
173+
'Parsing.subproj/CFXMLTree.c',
174+
'Parsing.subproj/CFXMLInterface.c',
175+
'PlugIn.subproj/CFBundle.c',
176+
'PlugIn.subproj/CFBundle_Binary.c',
177+
'PlugIn.subproj/CFBundle_Grok.c',
178+
'PlugIn.subproj/CFBundle_InfoPlist.c',
179+
'PlugIn.subproj/CFBundle_Locale.c',
180+
'PlugIn.subproj/CFBundle_Resources.c',
181+
'PlugIn.subproj/CFBundle_Strings.c',
182+
'PlugIn.subproj/CFPlugIn.c',
183+
'PlugIn.subproj/CFPlugIn_Factory.c',
184+
'PlugIn.subproj/CFPlugIn_Instance.c',
185+
'PlugIn.subproj/CFPlugIn_PlugIn.c',
186+
'Preferences.subproj/CFApplicationPreferences.c',
187+
'Preferences.subproj/CFPreferences.c',
188+
'RunLoop.subproj/CFRunLoop.c',
189+
'RunLoop.subproj/CFSocket.c',
190+
'Stream.subproj/CFConcreteStreams.c',
191+
'Stream.subproj/CFSocketStream.c',
192+
'Stream.subproj/CFStream.c',
193+
'String.subproj/CFBurstTrie.c',
194+
'String.subproj/CFCharacterSet.c',
195+
'String.subproj/CFString.c',
196+
'String.subproj/CFStringEncodings.c',
197+
'String.subproj/CFStringScanner.c',
198+
'String.subproj/CFStringUtilities.c',
199+
'String.subproj/CFStringTransform.c',
200+
'StringEncodings.subproj/CFBuiltinConverters.c',
201+
'StringEncodings.subproj/CFICUConverters.c',
202+
'StringEncodings.subproj/CFPlatformConverters.c',
203+
'StringEncodings.subproj/CFStringEncodingConverter.c',
204+
'StringEncodings.subproj/CFStringEncodingDatabase.c',
205+
'StringEncodings.subproj/CFUniChar.c',
206+
'StringEncodings.subproj/CFUnicodeDecomposition.c',
207+
'StringEncodings.subproj/CFUnicodePrecomposition.c',
208+
'URL.subproj/CFURL.c',
209+
'URL.subproj/CFURLAccess.c',
210+
'URL.subproj/CFURLComponents.c',
211+
'URL.subproj/CFURLComponents_URIParser.c',
212+
'String.subproj/CFCharacterSetData.S',
213+
'String.subproj/CFUnicodeData.S',
214+
'String.subproj/CFUniCharPropertyDatabase.S',
215+
'String.subproj/CFRegularExpression.c',
216+
'String.subproj/CFAttributedString.c',
217+
'String.subproj/CFRunArray.c',
218+
])
219+
220+
sources.add_dependency(headers)
221+
cf.add_phase(sources)
222+
script.add_product(cf)
223+
script.generate()
224+
225+

Foundation.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,10 @@
24192419
"-Wno-int-conversion",
24202420
"-Wno-unused-function",
24212421
"-DHAVE_STRUCT_TIMESPEC",
2422+
"-DCF_CHARACTERSET_UNICODE_DATA_L=\\\\\"CoreFoundation/CharacterSets/CFUnicodeData-L.mapping\\\\\"",
2423+
"-DCF_CHARACTERSET_UNICODE_DATA_B=\\\\\"CoreFoundation/CharacterSets/CFUnicodeData-B.mapping\\\\\"",
2424+
"-DCF_CHARACTERSET_UNICHAR_DB=\\\\\"CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data\\\\\"",
2425+
"-DCF_CHARACTERSET_BITMAP=\\\\\"CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap\\\\\"",
24222426
);
24232427
PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
24242428
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2454,6 +2458,10 @@
24542458
"-Wno-int-conversion",
24552459
"-Wno-unused-function",
24562460
"-DHAVE_STRUCT_TIMESPEC",
2461+
"-DCF_CHARACTERSET_UNICODE_DATA_L=\\\\\"CoreFoundation/CharacterSets/CFUnicodeData-L.mapping\\\\\"",
2462+
"-DCF_CHARACTERSET_UNICODE_DATA_B=\\\\\"CoreFoundation/CharacterSets/CFUnicodeData-B.mapping\\\\\"",
2463+
"-DCF_CHARACTERSET_UNICHAR_DB=\\\\\"CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data\\\\\"",
2464+
"-DCF_CHARACTERSET_BITMAP=\\\\\"CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap\\\\\"",
24572465
);
24582466
PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
24592467
PRODUCT_NAME = "$(TARGET_NAME)";

build.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
foundation.GCC_PREFIX_HEADER = 'CoreFoundation/Base.subproj/CoreFoundation_Prefix.h'
1515

1616
if Configuration.current.target.sdk == OSType.Linux:
17-
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE '
17+
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -DCF_CHARACTERSET_DATA_DIR="CoreFoundation/CharacterSets"'
1818
foundation.LDFLAGS = '${SWIFT_USE_LINKER} -Wl,@./CoreFoundation/linux.ld -lswiftGlibc `${PKG_CONFIG} icu-uc icu-i18n --libs` -Wl,-defsym,__CFConstantStringClassReference=_TMC10Foundation19_NSCFConstantString -Wl,-Bsymbolic '
1919
Configuration.current.requires_pkg_config = True
2020
elif Configuration.current.target.sdk == OSType.FreeBSD:
@@ -27,6 +27,13 @@
2727
if Configuration.current.build_mode == Configuration.Debug:
2828
foundation.LDFLAGS += ' -lswiftSwiftOnoneSupport '
2929

30+
foundation.ASFLAGS = " ".join([
31+
'-DCF_CHARACTERSET_BITMAP=\\"CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap\\"',
32+
'-DCF_CHARACTERSET_UNICHAR_DB=\\"CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data\\"',
33+
'-DCF_CHARACTERSET_UNICODE_DATA_B=\\"CoreFoundation/CharacterSets/CFUnicodeData-B.mapping\\"',
34+
'-DCF_CHARACTERSET_UNICODE_DATA_L=\\"CoreFoundation/CharacterSets/CFUnicodeData-L.mapping\\"',
35+
])
36+
3037
# For now, we do not distinguish between public and private headers (they are all private to Foundation)
3138
# These are really part of CF, which should ultimately be a separate target
3239
foundation.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift"

0 commit comments

Comments
 (0)