Skip to content

Commit 4e9869a

Browse files
committed
Fixed build script for OSX, builds dynamic library 'SwiftFoundation'
No-oped CF_AVAILABILITY macros when building SwiftFoundation Changed configure environment variable for swift build directory from 'SDKROOT' (confuses xcrun) to 'SWIFT_SDKROOT'. Requires change to swift's build-script-impl.
1 parent 11184f7 commit 4e9869a

File tree

9 files changed

+67
-132
lines changed

9 files changed

+67
-132
lines changed

CoreFoundation/Base.subproj/CFAvailability.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@
8989
#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...)
9090
#endif
9191

92+
#if DEPLOYMENT_RUNTIME_SWIFT
93+
// PortableFoundation is a standalone module and does not depend on system version
94+
#undef CF_AVAILABLE
95+
#undef CF_AVAILABLE_MAC
96+
#undef CF_AVAILABLE_IOS
97+
#undef CF_DEPRECATED
98+
#undef CF_DEPRECATED_MAC
99+
#undef CF_DEPRECATED_IOS
100+
101+
#define CF_AVAILABLE(_mac, _ios)
102+
#define CF_AVAILABLE_MAC(_mac)
103+
#define CF_AVAILABLE_IOS(_ios)
104+
105+
#if __has_attribute(deprecated) // Keep deprecation warnings
106+
#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) __attribute__((deprecated(__VA_ARGS__)))
107+
#else
108+
#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...)
109+
#endif
110+
111+
#define CF_DEPRECATED_MAC(_macIntro, _macDep, ...) CF_DEPRECATED(_macIntro, _macDep, 0, 0, __VA_ARGS__)
112+
#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...) CF_DEPRECATED(0, 0, _iosIntro, _iosDep, __VA_ARGS__)
113+
#endif
114+
92115
// Older versions of these macros; use iOS versions instead
93116
#define CF_AVAILABLE_IPHONE(_ios) CF_AVAILABLE_IOS(_ios)
94117
#define CF_DEPRECATED_IPHONE(_iosIntro, _iosDep) CF_DEPRECATED_IOS(_iosIntro, _iosDep)

CoreFoundation/Base.subproj/SymbolAliases

Lines changed: 0 additions & 105 deletions
This file was deleted.

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@
273273
D3E8D6D11C367AB600295652 /* NSSpecialValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E8D6D01C367AB600295652 /* NSSpecialValue.swift */; };
274274
D3E8D6D31C36982700295652 /* NSKeyedUnarchiver-EdgeInsetsTest.plist in Resources */ = {isa = PBXBuildFile; fileRef = D3E8D6D21C36982700295652 /* NSKeyedUnarchiver-EdgeInsetsTest.plist */; };
275275
D3E8D6D51C36AC0C00295652 /* NSKeyedUnarchiver-RectTest.plist in Resources */ = {isa = PBXBuildFile; fileRef = D3E8D6D41C36AC0C00295652 /* NSKeyedUnarchiver-RectTest.plist */; };
276-
D5C40F331CDA1D460005690C /* TestNSOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C40F321CDA1D460005690C /* TestNSOperationQueue.swift */; };
277276
D51239DF1CD9DA0800D433EE /* CFSocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B5D88E01BBC9B0300234F36 /* CFSocket.c */; };
278277
D512D17C1CD883F00032E6A5 /* TestNSFileHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D512D17B1CD883F00032E6A5 /* TestNSFileHandle.swift */; };
278+
D5C40F331CDA1D460005690C /* TestNSOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C40F321CDA1D460005690C /* TestNSOperationQueue.swift */; };
279279
E1A03F361C4828650023AF4D /* PropertyList-1.0.dtd in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F351C4828650023AF4D /* PropertyList-1.0.dtd */; };
280280
E1A03F381C482C730023AF4D /* NSXMLDTDTestData.xml in Resources */ = {isa = PBXBuildFile; fileRef = E1A03F371C482C730023AF4D /* NSXMLDTDTestData.xml */; };
281281
E1A3726F1C31EBFB0023AF4D /* NSXMLDocumentTestData.xml in Resources */ = {isa = PBXBuildFile; fileRef = E1A3726E1C31EBFB0023AF4D /* NSXMLDocumentTestData.xml */; };
@@ -649,8 +649,8 @@
649649
D3E8D6D01C367AB600295652 /* NSSpecialValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSSpecialValue.swift; sourceTree = "<group>"; };
650650
D3E8D6D21C36982700295652 /* NSKeyedUnarchiver-EdgeInsetsTest.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NSKeyedUnarchiver-EdgeInsetsTest.plist"; sourceTree = "<group>"; };
651651
D3E8D6D41C36AC0C00295652 /* NSKeyedUnarchiver-RectTest.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NSKeyedUnarchiver-RectTest.plist"; sourceTree = "<group>"; };
652-
D5C40F321CDA1D460005690C /* TestNSOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSOperationQueue.swift; sourceTree = "<group>"; };
653652
D512D17B1CD883F00032E6A5 /* TestNSFileHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSFileHandle.swift; sourceTree = "<group>"; };
653+
D5C40F321CDA1D460005690C /* TestNSOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSOperationQueue.swift; sourceTree = "<group>"; };
654654
D834F9931C31C4060023812A /* TestNSOrderedSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSOrderedSet.swift; sourceTree = "<group>"; };
655655
DCDBB8321C1768AC00313299 /* TestNSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSData.swift; sourceTree = "<group>"; };
656656
E19E17DB1C2225930023AF4D /* TestNSXMLDocument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSXMLDocument.swift; sourceTree = "<group>"; };
@@ -2161,7 +2161,7 @@
21612161
);
21622162
OTHER_LDFLAGS = (
21632163
"-twolevel_namespace",
2164-
"-Wl,-alias_list,CoreFoundation/Base.subproj/SymbolAliases",
2164+
"-Wl,-alias_list,CoreFoundation/Base.subproj/DarwinSymbolAliases",
21652165
"-sectcreate",
21662166
__UNICODE,
21672167
__csbitmaps,
@@ -2230,7 +2230,7 @@
22302230
);
22312231
OTHER_LDFLAGS = (
22322232
"-twolevel_namespace",
2233-
"-Wl,-alias_list,CoreFoundation/Base.subproj/SymbolAliases",
2233+
"-Wl,-alias_list,CoreFoundation/Base.subproj/DarwinSymbolAliases",
22342234
"-sectcreate",
22352235
__UNICODE,
22362236
__csbitmaps,

build.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
script = Script()
1111

12-
foundation = DynamicLibrary("Foundation")
12+
foundation = DynamicLibrary(Configuration.current.module_name)
1313

1414
foundation.GCC_PREFIX_HEADER = 'CoreFoundation/Base.subproj/CoreFoundation_Prefix.h'
1515

@@ -22,6 +22,8 @@
2222
elif Configuration.current.target.sdk == OSType.MacOSX:
2323
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_MACOSX '
2424
foundation.LDFLAGS = '-licucore -twolevel_namespace -Wl,-alias_list,CoreFoundation/Base.subproj/DarwinSymbolAliases -sectcreate __UNICODE __csbitmaps CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap -sectcreate __UNICODE __properties CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data -sectcreate __UNICODE __data CoreFoundation/CharacterSets/CFUnicodeData-L.mapping -segprot __UNICODE r r '
25+
foundation.LDFLAGS += '-mmacosx-version-min=10.11 ' # Required to link symbol ___udivti3 from CFBigNumber
26+
foundation.LDFLAGS += '-init ___CFInitialize -install_name @rpath/lib' + foundation.name + '.dylib -Xlinker -no_deduplicate '
2527

2628
if Configuration.current.build_mode == Configuration.Debug:
2729
foundation.LDFLAGS += ' -lswiftSwiftOnoneSupport '
@@ -48,20 +50,20 @@
4850
'-Wno-unused-variable',
4951
'-Wno-int-conversion',
5052
'-Wno-unused-function',
51-
'-I/usr/include/libxml2',
53+
'-I${SYSROOT}/usr/include/libxml2',
5254
'-I./',
5355
])
5456

5557
swift_cflags = [
56-
'-I${BUILD_DIR}/Foundation/usr/lib/swift',
57-
'-I/usr/include/libxml2'
58+
'-I${BUILD_DIR}/${MODULE_NAME}/usr/lib/swift',
59+
'-I${SYSROOT}/usr/include/libxml2'
5860
]
5961

6062
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
6163
swift_cflags += [
6264
'-I${XCTEST_BUILD_DIR}',
6365
'-L${XCTEST_BUILD_DIR}',
64-
'-I/usr/include/libxml2'
66+
'-I${SYSROOT}/usr/include/libxml2'
6567
]
6668

6769
# Configure use of Dispatch in CoreFoundation and Foundation if libdispatch is being built
@@ -414,22 +416,22 @@
414416
extra_script = """
415417
rule InstallFoundation
416418
command = mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
417-
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
419+
cp "${BUILD_DIR}/${MODULE_NAME}/${DYLIB_PREFIX}${MODULE_NAME}${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
418420
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}"; $
419-
cp "${BUILD_DIR}/Foundation/Foundation.swiftmodule" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
420-
cp "${BUILD_DIR}/Foundation/Foundation.swiftdoc" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
421+
cp "${BUILD_DIR}/${MODULE_NAME}/${MODULE_NAME}.swiftmodule" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
422+
cp "${BUILD_DIR}/${MODULE_NAME}/${MODULE_NAME}.swiftdoc" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
421423
mkdir -p "${DSTROOT}/${PREFIX}/local/include"; $
422-
rsync -r "${BUILD_DIR}/Foundation/${PREFIX}/lib/swift/CoreFoundation" "${DSTROOT}/${PREFIX}/lib/swift/"
424+
rsync -r "${BUILD_DIR}/${MODULE_NAME}/${PREFIX}/lib/swift/CoreFoundation" "${DSTROOT}/${PREFIX}/lib/swift/"
423425
424-
build ${BUILD_DIR}/.install: InstallFoundation ${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}
426+
build ${BUILD_DIR}/.install: InstallFoundation ${BUILD_DIR}/${MODULE_NAME}/${DYLIB_PREFIX}${MODULE_NAME}${DYLIB_SUFFIX}
425427
426428
build install: phony | ${BUILD_DIR}/.install
427429
428430
"""
429431
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
430432
extra_script += """
431433
rule RunTestFoundation
432-
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/:${XCTEST_BUILD_DIR} ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/:${XCTEST_BUILD_DIR} lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
434+
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/${MODULE_NAME}/:${XCTEST_BUILD_DIR} ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/${MODULE_NAME}/:${XCTEST_BUILD_DIR} lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
433435
description = Building Tests
434436
435437
build ${BUILD_DIR}/.test: RunTestFoundation | TestFoundation
@@ -440,7 +442,7 @@
440442
else:
441443
extra_script += """
442444
rule RunTestFoundation
443-
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/ ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/ lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
445+
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/${MODULE_NAME}/ ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/${MODULE_NAME}/ lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
444446
description = Building Tests
445447
446448
build ${BUILD_DIR}/.test: RunTestFoundation | TestFoundation

configure

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def reconfigure(config, path):
5959
config.build_script_path = Path(info['build_script_path'])
6060
if 'source_root' in info and info['source_root'] is not None:
6161
config.source_root = Path(info['source_root'])
62+
if 'module_name' in info and info['module_name'] is not None:
63+
config.module_name = info['module_name']
6264
if 'target' in info and info['target'] is not None:
6365
config.target = Target(info['target'])
6466
if 'system_root' in info and info['system_root'] is not None:
@@ -124,7 +126,7 @@ def main():
124126
config.extra_c_flags = os.getenv("CFLAGS", "")
125127
config.extra_swift_flags = os.getenv("SWIFTCFLAGS", "")
126128
config.extra_ld_flags = os.getenv("LDFLAGS", "")
127-
config.swift_sdk = os.getenv("SDKROOT", None)
129+
config.swift_sdk = os.getenv("SWIFT_SDKROOT", None)
128130
config.script_path = config.source_root.path_by_appending("build.py")
129131
config.build_script_path = config.source_root.path_by_appending("build.ninja")
130132
config.config_path = config.source_root.path_by_appending(".configuration")
@@ -165,8 +167,9 @@ def main():
165167
if config.target.sdk == OSType.MacOSX and config.system_root is None and Target(Target.default()).sdk == OSType.MacOSX:
166168
import subprocess
167169
config.system_root = Path.path(subprocess.Popen(['xcrun', '--show-sdk-path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).communicate()[0])
168-
swift_path = Path.path(subprocess.Popen(['xcrun', '--find', 'swift'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).communicate()[0]).parent().parent()
169-
config.swift_sdk = swift_path.absolute()
170+
if config.swift_sdk is None:
171+
swift_path = Path.path(subprocess.Popen(['xcrun', '--find', 'swift'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).communicate()[0]).parent().parent()
172+
config.swift_sdk = swift_path.absolute()
170173
elif config.swift_sdk is None:
171174
config.swift_sdk = "/usr"
172175
config.toolchain = Path.path(args.toolchain)
@@ -177,6 +180,14 @@ def main():
177180
elif config.ar is None:
178181
config.ar = "ar"
179182

183+
# Set the module name. On OSX this must not conflict with the system 'Foundation'
184+
# or swift's libswiftFoundation.dylib
185+
186+
if config.target.sdk == OSType.MacOSX:
187+
config.module_name = "SwiftFoundation"
188+
else:
189+
config.module_name = "Foundation"
190+
180191
config.write(config.config_path.absolute())
181192
Configuration.current = config
182193

0 commit comments

Comments
 (0)