Skip to content

Commit

Permalink
Merge pull request swiftlang#1391 from millenomi/pr/fix-cf-buildpy
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci authored Jan 9, 2018
2 parents 7a52fef + f9d84c4 commit 7359ea7
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 21 deletions.
136 changes: 117 additions & 19 deletions CoreFoundation/build.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#

script = Script()

cf = StaticLibrary("CoreFoundation")
cf = DynamicLibrary("CoreFoundation", uses_swift_runtime_object=False)

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

if Configuration.current.target.sdk == OSType.Linux:
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE '
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -DCF_CHARACTERSET_DATA_DIR="CharacterSets" '
cf.LDFLAGS = '-Wl,@./linux.ld -Wl,-Bsymbolic '
Configuration.current.requires_pkg_config = True
elif Configuration.current.target.sdk == OSType.FreeBSD:
cf.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 '
cf.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include/curl '
cf.LDFLAGS = ''
elif Configuration.current.target.sdk == OSType.MacOSX:
cf.CFLAGS = '-DDEPLOYMENT_TARGET_MACOSX '
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 '
elif Configuration.current.target.sdk == OSType.Win32 and Configuration.current.target.environ == EnvironmentType.Cygnus:
cf.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -mcmodel=large '
cf.LDFLAGS = '${SWIFT_USE_LINKER} -lswiftGlibc `icu-config --ldflags` -Wl,--allow-multiple-definition '

cf.ASFLAGS = " ".join([
'-DCF_CHARACTERSET_BITMAP=\\"CharacterSets/CFCharacterSetBitmaps.bitmap\\"',
'-DCF_CHARACTERSET_BITMAP=\\"CharacterSets/CFCharacterSetBitmaps.bitmap\\"',
'-DCF_CHARACTERSET_UNICHAR_DB=\\"CharacterSets/CFUniCharPropertyDatabase.data\\"',
'-DCF_CHARACTERSET_UNICODE_DATA_B=\\"CharacterSets/CFUnicodeData-B.mapping\\"',
'-DCF_CHARACTERSET_UNICODE_DATA_L=\\"CharacterSets/CFUnicodeData-L.mapping\\"',
])

cf.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift"
cf.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
cf.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
cf.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
cf.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
cf.CFLAGS += " ".join([
'-I${DSTROOT}${PREFIX}/include',
'-I${DSTROOT}${PREFIX}/local/include',
]) + " "
cf.LDFLAGS += " ".join([
'-L${DSTROOT}${PREFIX}/lib',
'-L${DSTROOT}${PREFIX}/local/lib',
]) + " "

# For now, we do not distinguish between public and private headers (they are all private to Foundation)
# These are really part of CF, which should ultimately be a separate target
cf.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/include"
cf.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
cf.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"
cf.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"

cf.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/include/CoreFoundation"

cf.CFLAGS += " ".join([
'-DU_SHOW_DRAFT_API',
'-DCF_BUILDING_CF',
'-DDEPLOYMENT_RUNTIME_SWIFT',
'-DU_SHOW_DRAFT_API=1',
'-DCF_BUILDING_CF=1',
'-DDEPLOYMENT_RUNTIME_C=1',
'-fconstant-cfstrings',
'-fexceptions',
'-Wno-shorten-64-to-32',
Expand All @@ -38,10 +65,46 @@
'-Wno-unused-variable',
'-Wno-int-conversion',
'-Wno-unused-function',
'-I${SYSROOT}/usr/include/libxml2',
'-I./',
])

if Configuration.current.requires_pkg_config:
pkg_config_dependencies = [
'libcurl',
'libxml-2.0',
]
for package_name in pkg_config_dependencies:
try:
package = PkgConfig(package_name)
except PkgConfig.Error as e:
sys.exit("pkg-config error for package {}: {}".format(package_name, e))
cf.CFLAGS += ' {} '.format(' '.join(package.cflags))
cf.LDFLAGS += ' {} '.format(' '.join(package.ldflags))
else:
cf.CFLAGS += ''.join([
'-I${SYSROOT}/usr/include/curl ',
'-I${SYSROOT}/usr/include/libxml2 ',
])
cf.LDFLAGS += ''.join([
'-lcurl ',
'-lxml2 ',
])

triple = Configuration.current.target.triple
if triple == "armv7-none-linux-androideabi":
cf.LDFLAGS += '-llog '
else:
cf.LDFLAGS += '-lpthread '

cf.LDFLAGS += '-ldl -lm '

# Configure use of Dispatch in CoreFoundation and Foundation if libdispatch is being built
cf.CFLAGS += '-DDEPLOYMENT_ENABLE_LIBDISPATCH=1 '
cf.LDFLAGS += '-ldispatch -rpath \$$ORIGIN '

if "XCTEST_BUILD_DIR" in Configuration.current.variables:
cf.LDFLAGS += '-L${XCTEST_BUILD_DIR}'

headers = CopyHeaders(
module = 'Base.subproj/module.modulemap',
public = [
Expand Down Expand Up @@ -76,6 +139,7 @@
'Collections.subproj/CFArray.h',
'RunLoop.subproj/CFRunLoop.h',
'URL.subproj/CFURLAccess.h',
'URL.subproj/CFURLSessionInterface.h',
'Locale.subproj/CFDateFormatter.h',
'RunLoop.subproj/CFMachPort.h',
'PlugIn.subproj/CFPlugInCOM.h',
Expand All @@ -88,12 +152,13 @@
'NumberDate.subproj/CFNumber.h',
'Collections.subproj/CFData.h',
'String.subproj/CFAttributedString.h',
'AppServices.subproj/CFNotificationCenter.h',
'Base.subproj/CoreFoundation_Prefix.h',
'AppServices.subproj/CFNotificationCenter.h'
],
private = [
'Base.subproj/CFAsmMacros.h',
'Base.subproj/ForSwiftFoundationOnly.h',
'Base.subproj/ForFoundationOnly.h',
'Base.subproj/CFAsmMacros.h',
'String.subproj/CFBurstTrie.h',
'Error.subproj/CFError_Private.h',
'URL.subproj/CFURLPriv.h',
Expand Down Expand Up @@ -130,14 +195,18 @@
'StringEncodings.subproj/CFICUConverters.h',
'String.subproj/CFRegularExpression.h',
'String.subproj/CFRunArray.h',
'URL.subproj/CFURLSessionInterface.h',
'Locale.subproj/CFDateFormatter_Private.h',
'Locale.subproj/CFLocale_Private.h',
'Parsing.subproj/CFPropertyList_Private.h',
],
project = [
])

cf.add_phase(headers)

sources = CompileSources([
sources_list = [
'../uuid/uuid.c',
# 'AppServices.subproj/CFUserNotification.c',
'Base.subproj/CFBase.c',
'Base.subproj/CFFileUtilities.c',
'Base.subproj/CFPlatform.c',
Expand Down Expand Up @@ -182,12 +251,17 @@
'PlugIn.subproj/CFBundle_Locale.c',
'PlugIn.subproj/CFBundle_Resources.c',
'PlugIn.subproj/CFBundle_Strings.c',
'PlugIn.subproj/CFBundle_Main.c',
'PlugIn.subproj/CFBundle_ResourceFork.c',
'PlugIn.subproj/CFBundle_Executable.c',
'PlugIn.subproj/CFBundle_DebugStrings.c',
'PlugIn.subproj/CFPlugIn.c',
'PlugIn.subproj/CFPlugIn_Factory.c',
'PlugIn.subproj/CFPlugIn_Instance.c',
'PlugIn.subproj/CFPlugIn_PlugIn.c',
'Preferences.subproj/CFApplicationPreferences.c',
'Preferences.subproj/CFPreferences.c',
'Preferences.subproj/CFXMLPreferencesDomain.c',
'RunLoop.subproj/CFRunLoop.c',
'RunLoop.subproj/CFSocket.c',
'Stream.subproj/CFConcreteStreams.c',
Expand Down Expand Up @@ -218,11 +292,35 @@
'String.subproj/CFRegularExpression.c',
'String.subproj/CFAttributedString.c',
'String.subproj/CFRunArray.c',
])
]

sources = CompileSources(sources_list)
sources.add_dependency(headers)
cf.add_phase(sources)

script.add_product(cf)
script.generate()

LIBS_DIRS = ""
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
LIBS_DIRS += "${XCTEST_BUILD_DIR}:"
if "PREFIX" in Configuration.current.variables:
LIBS_DIRS += Configuration.current.variables["PREFIX"]+"/lib:"

Configuration.current.variables["LIBS_DIRS"] = LIBS_DIRS

extra_script = """
rule InstallCoreFoundation
command = mkdir -p "${DSTROOT}/${PREFIX}/lib"; $
mkdir -p "${DSTROOT}/${PREFIX}/include"; $
rsync -a "${BUILD_DIR}/CoreFoundation/${PREFIX}/include/CoreFoundation" "${DSTROOT}/${PREFIX}/include/"; $
cp "${BUILD_DIR}/CoreFoundation/${DYLIB_PREFIX}CoreFoundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib"
build ${BUILD_DIR}/.install: InstallCoreFoundation ${BUILD_DIR}/CoreFoundation/${DYLIB_PREFIX}CoreFoundation${DYLIB_SUFFIX}
build install: phony | ${BUILD_DIR}/.install
"""

script.add_text(extra_script)

script.generate()
5 changes: 3 additions & 2 deletions lib/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ def generate(self, flags, objects = []):


class DynamicLibrary(Library):
def __init__(self, name):
def __init__(self, name, uses_swift_runtime_object = True):
Library.__init__(self, name)
self.name = name
self.uses_swift_runtime_object = uses_swift_runtime_object

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

0 comments on commit 7359ea7

Please sign in to comment.