Skip to content

Commit f9d84c4

Browse files
committed
Update CoreFoundation/build.py to match /build.py more closely.
1 parent b39800c commit f9d84c4

File tree

2 files changed

+120
-21
lines changed

2 files changed

+120
-21
lines changed

CoreFoundation/build.py

100644100755
+117-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,61 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
#
9+
110
script = Script()
211

3-
cf = StaticLibrary("CoreFoundation")
12+
cf = DynamicLibrary("CoreFoundation", uses_swift_runtime_object=False)
413

514
cf.GCC_PREFIX_HEADER = 'Base.subproj/CoreFoundation_Prefix.h'
615

716
if Configuration.current.target.sdk == OSType.Linux:
8-
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE '
17+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -DCF_CHARACTERSET_DATA_DIR="CharacterSets" '
18+
cf.LDFLAGS = '-Wl,@./linux.ld -Wl,-Bsymbolic '
919
Configuration.current.requires_pkg_config = True
1020
elif Configuration.current.target.sdk == OSType.FreeBSD:
11-
cf.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 '
21+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include/curl '
22+
cf.LDFLAGS = ''
1223
elif Configuration.current.target.sdk == OSType.MacOSX:
1324
cf.CFLAGS = '-DDEPLOYMENT_TARGET_MACOSX '
25+
cf.LDFLAGS = '-licucore -twolevel_namespace -Wl,-alias_list,Base.subproj/DarwinSymbolAliases -sectcreate __UNICODE __csbitmaps CharacterSets/CFCharacterSetBitmaps.bitmap -sectcreate __UNICODE __properties CharacterSets/CFUniCharPropertyDatabase.data -sectcreate __UNICODE __data CharacterSets/CFUnicodeData-L.mapping -segprot __UNICODE r r '
26+
elif Configuration.current.target.sdk == OSType.Win32 and Configuration.current.target.environ == EnvironmentType.Cygnus:
27+
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -mcmodel=large '
28+
cf.LDFLAGS = '${SWIFT_USE_LINKER} -lswiftGlibc `icu-config --ldflags` -Wl,--allow-multiple-definition '
1429

1530
cf.ASFLAGS = " ".join([
16-
'-DCF_CHARACTERSET_BITMAP=\\"CharacterSets/CFCharacterSetBitmaps.bitmap\\"',
31+
'-DCF_CHARACTERSET_BITMAP=\\"CharacterSets/CFCharacterSetBitmaps.bitmap\\"',
1732
'-DCF_CHARACTERSET_UNICHAR_DB=\\"CharacterSets/CFUniCharPropertyDatabase.data\\"',
1833
'-DCF_CHARACTERSET_UNICODE_DATA_B=\\"CharacterSets/CFUnicodeData-B.mapping\\"',
1934
'-DCF_CHARACTERSET_UNICODE_DATA_L=\\"CharacterSets/CFUnicodeData-L.mapping\\"',
2035
])
2136

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"
37+
cf.CFLAGS += " ".join([
38+
'-I${DSTROOT}${PREFIX}/include',
39+
'-I${DSTROOT}${PREFIX}/local/include',
40+
]) + " "
41+
cf.LDFLAGS += " ".join([
42+
'-L${DSTROOT}${PREFIX}/lib',
43+
'-L${DSTROOT}${PREFIX}/local/lib',
44+
]) + " "
45+
46+
# For now, we do not distinguish between public and private headers (they are all private to Foundation)
47+
# These are really part of CF, which should ultimately be a separate target
48+
cf.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/include"
49+
cf.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
50+
cf.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
51+
cf.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
52+
53+
cf.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
2754

2855
cf.CFLAGS += " ".join([
29-
'-DU_SHOW_DRAFT_API',
30-
'-DCF_BUILDING_CF',
31-
'-DDEPLOYMENT_RUNTIME_SWIFT',
56+
'-DU_SHOW_DRAFT_API=1',
57+
'-DCF_BUILDING_CF=1',
58+
'-DDEPLOYMENT_RUNTIME_C=1',
3259
'-fconstant-cfstrings',
3360
'-fexceptions',
3461
'-Wno-shorten-64-to-32',
@@ -38,10 +65,46 @@
3865
'-Wno-unused-variable',
3966
'-Wno-int-conversion',
4067
'-Wno-unused-function',
41-
'-I${SYSROOT}/usr/include/libxml2',
4268
'-I./',
4369
])
4470

71+
if Configuration.current.requires_pkg_config:
72+
pkg_config_dependencies = [
73+
'libcurl',
74+
'libxml-2.0',
75+
]
76+
for package_name in pkg_config_dependencies:
77+
try:
78+
package = PkgConfig(package_name)
79+
except PkgConfig.Error as e:
80+
sys.exit("pkg-config error for package {}: {}".format(package_name, e))
81+
cf.CFLAGS += ' {} '.format(' '.join(package.cflags))
82+
cf.LDFLAGS += ' {} '.format(' '.join(package.ldflags))
83+
else:
84+
cf.CFLAGS += ''.join([
85+
'-I${SYSROOT}/usr/include/curl ',
86+
'-I${SYSROOT}/usr/include/libxml2 ',
87+
])
88+
cf.LDFLAGS += ''.join([
89+
'-lcurl ',
90+
'-lxml2 ',
91+
])
92+
93+
triple = Configuration.current.target.triple
94+
if triple == "armv7-none-linux-androideabi":
95+
cf.LDFLAGS += '-llog '
96+
else:
97+
cf.LDFLAGS += '-lpthread '
98+
99+
cf.LDFLAGS += '-ldl -lm '
100+
101+
# Configure use of Dispatch in CoreFoundation and Foundation if libdispatch is being built
102+
cf.CFLAGS += '-DDEPLOYMENT_ENABLE_LIBDISPATCH=1 '
103+
cf.LDFLAGS += '-ldispatch -rpath \$$ORIGIN '
104+
105+
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
106+
cf.LDFLAGS += '-L${XCTEST_BUILD_DIR}'
107+
45108
headers = CopyHeaders(
46109
module = 'Base.subproj/module.modulemap',
47110
public = [
@@ -76,6 +139,7 @@
76139
'Collections.subproj/CFArray.h',
77140
'RunLoop.subproj/CFRunLoop.h',
78141
'URL.subproj/CFURLAccess.h',
142+
'URL.subproj/CFURLSessionInterface.h',
79143
'Locale.subproj/CFDateFormatter.h',
80144
'RunLoop.subproj/CFMachPort.h',
81145
'PlugIn.subproj/CFPlugInCOM.h',
@@ -88,12 +152,13 @@
88152
'NumberDate.subproj/CFNumber.h',
89153
'Collections.subproj/CFData.h',
90154
'String.subproj/CFAttributedString.h',
91-
'AppServices.subproj/CFNotificationCenter.h',
155+
'Base.subproj/CoreFoundation_Prefix.h',
156+
'AppServices.subproj/CFNotificationCenter.h'
92157
],
93158
private = [
94-
'Base.subproj/CFAsmMacros.h',
95159
'Base.subproj/ForSwiftFoundationOnly.h',
96160
'Base.subproj/ForFoundationOnly.h',
161+
'Base.subproj/CFAsmMacros.h',
97162
'String.subproj/CFBurstTrie.h',
98163
'Error.subproj/CFError_Private.h',
99164
'URL.subproj/CFURLPriv.h',
@@ -130,14 +195,18 @@
130195
'StringEncodings.subproj/CFICUConverters.h',
131196
'String.subproj/CFRegularExpression.h',
132197
'String.subproj/CFRunArray.h',
133-
'URL.subproj/CFURLSessionInterface.h',
198+
'Locale.subproj/CFDateFormatter_Private.h',
199+
'Locale.subproj/CFLocale_Private.h',
200+
'Parsing.subproj/CFPropertyList_Private.h',
134201
],
135202
project = [
136203
])
137204

138205
cf.add_phase(headers)
139206

140-
sources = CompileSources([
207+
sources_list = [
208+
'../uuid/uuid.c',
209+
# 'AppServices.subproj/CFUserNotification.c',
141210
'Base.subproj/CFBase.c',
142211
'Base.subproj/CFFileUtilities.c',
143212
'Base.subproj/CFPlatform.c',
@@ -182,12 +251,17 @@
182251
'PlugIn.subproj/CFBundle_Locale.c',
183252
'PlugIn.subproj/CFBundle_Resources.c',
184253
'PlugIn.subproj/CFBundle_Strings.c',
254+
'PlugIn.subproj/CFBundle_Main.c',
255+
'PlugIn.subproj/CFBundle_ResourceFork.c',
256+
'PlugIn.subproj/CFBundle_Executable.c',
257+
'PlugIn.subproj/CFBundle_DebugStrings.c',
185258
'PlugIn.subproj/CFPlugIn.c',
186259
'PlugIn.subproj/CFPlugIn_Factory.c',
187260
'PlugIn.subproj/CFPlugIn_Instance.c',
188261
'PlugIn.subproj/CFPlugIn_PlugIn.c',
189262
'Preferences.subproj/CFApplicationPreferences.c',
190263
'Preferences.subproj/CFPreferences.c',
264+
'Preferences.subproj/CFXMLPreferencesDomain.c',
191265
'RunLoop.subproj/CFRunLoop.c',
192266
'RunLoop.subproj/CFSocket.c',
193267
'Stream.subproj/CFConcreteStreams.c',
@@ -218,11 +292,35 @@
218292
'String.subproj/CFRegularExpression.c',
219293
'String.subproj/CFAttributedString.c',
220294
'String.subproj/CFRunArray.c',
221-
])
295+
]
222296

297+
sources = CompileSources(sources_list)
223298
sources.add_dependency(headers)
224299
cf.add_phase(sources)
300+
225301
script.add_product(cf)
226-
script.generate()
227302

303+
LIBS_DIRS = ""
304+
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
305+
LIBS_DIRS += "${XCTEST_BUILD_DIR}:"
306+
if "PREFIX" in Configuration.current.variables:
307+
LIBS_DIRS += Configuration.current.variables["PREFIX"]+"/lib:"
308+
309+
Configuration.current.variables["LIBS_DIRS"] = LIBS_DIRS
310+
311+
extra_script = """
312+
rule InstallCoreFoundation
313+
command = mkdir -p "${DSTROOT}/${PREFIX}/lib"; $
314+
mkdir -p "${DSTROOT}/${PREFIX}/include"; $
315+
rsync -a "${BUILD_DIR}/CoreFoundation/${PREFIX}/include/CoreFoundation" "${DSTROOT}/${PREFIX}/include/"; $
316+
cp "${BUILD_DIR}/CoreFoundation/${DYLIB_PREFIX}CoreFoundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib"
228317
318+
build ${BUILD_DIR}/.install: InstallCoreFoundation ${BUILD_DIR}/CoreFoundation/${DYLIB_PREFIX}CoreFoundation${DYLIB_SUFFIX}
319+
320+
build install: phony | ${BUILD_DIR}/.install
321+
322+
"""
323+
324+
script.add_text(extra_script)
325+
326+
script.generate()

lib/product.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ def generate(self, flags, objects = []):
110110

111111

112112
class DynamicLibrary(Library):
113-
def __init__(self, name):
113+
def __init__(self, name, uses_swift_runtime_object = True):
114114
Library.__init__(self, name)
115115
self.name = name
116+
self.uses_swift_runtime_object = uses_swift_runtime_object
116117

117118
def generate(self, objects = []):
118119
self.rule = "Link"
119120
self.product_name = Configuration.current.target.dynamic_library_prefix + self.name + Configuration.current.target.dynamic_library_suffix
120-
if Configuration.current.target.sdk == OSType.Linux or Configuration.current.target.sdk == OSType.FreeBSD:
121+
if (Configuration.current.target.sdk == OSType.Linux or Configuration.current.target.sdk == OSType.FreeBSD) and self.uses_swift_runtime_object:
121122
self.runtime_object = '${SDKROOT}/lib/swift/${OS}/${ARCH}/swiftrt.o'
122123
return Library.generate(self, ["-shared", "-Wl,-soname," + self.product_name, "-Wl,--no-undefined"], objects)
123124
else:

0 commit comments

Comments
 (0)