Skip to content

SR-2100 - Add support for multi-lib systems #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@

# 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
foundation.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift"
foundation.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
foundation.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
foundation.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
foundation.ROOT_HEADERS_FOLDER_PATH = "${PREFIX}/${LIBDIR}/swift"
foundation.PUBLIC_HEADERS_FOLDER_PATH = "${PREFIX}/${LIBDIR}/swift/CoreFoundation"
foundation.PRIVATE_HEADERS_FOLDER_PATH = "${PREFIX}/${LIBDIR}/swift/CoreFoundation"
foundation.PROJECT_HEADERS_FOLDER_PATH = "${PREFIX}/${LIBDIR}/swift/CoreFoundation"

foundation.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/lib/swift/CoreFoundation"
foundation.PUBLIC_MODULE_FOLDER_PATH = "${PREFIX}/${LIBDIR}/swift/CoreFoundation"

foundation.CFLAGS += " ".join([
'-DU_SHOW_DRAFT_API',
Expand All @@ -65,7 +65,7 @@
])

swift_cflags += [
'-I${BUILD_DIR}/Foundation/usr/lib/swift',
'-I${BUILD_DIR}/Foundation/usr/${LIBDIR}/swift',
]

if "XCTEST_BUILD_DIR" in Configuration.current.variables:
Expand Down Expand Up @@ -549,15 +549,15 @@

extra_script = """
rule InstallFoundation
command = mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift_static/${OS}"; $
cp "${BUILD_DIR}/Foundation/${STATICLIB_PREFIX}Foundation${STATICLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift_static/${OS}"; $
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}"; $
cp "${BUILD_DIR}/Foundation/Foundation.swiftmodule" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
cp "${BUILD_DIR}/Foundation/Foundation.swiftdoc" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
command = mkdir -p "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/${OS}"; $
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/${OS}"; $
mkdir -p "${DSTROOT}/${PREFIX}/${LIBDIR}/swift_static/${OS}"; $
cp "${BUILD_DIR}/Foundation/${STATICLIB_PREFIX}Foundation${STATICLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/${LIBDIR}/swift_static/${OS}"; $
mkdir -p "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/${OS}/${ARCH}"; $
cp "${BUILD_DIR}/Foundation/Foundation.swiftmodule" "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/${OS}/${ARCH}/"; $
cp "${BUILD_DIR}/Foundation/Foundation.swiftdoc" "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/${OS}/${ARCH}/"; $
mkdir -p "${DSTROOT}/${PREFIX}/local/include"; $
rsync -a "${BUILD_DIR}/Foundation/${PREFIX}/lib/swift/CoreFoundation" "${DSTROOT}/${PREFIX}/lib/swift/"
rsync -a "${BUILD_DIR}/Foundation/${PREFIX}/${LIBDIR}/swift/CoreFoundation" "${DSTROOT}/${PREFIX}/${LIBDIR}/swift/"

build ${BUILD_DIR}/.install: InstallFoundation ${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}

Expand Down
5 changes: 5 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def main():
config.script_path = config.source_root.path_by_appending("build.py")
config.build_script_path = config.source_root.path_by_appending("build.ninja")
config.config_path = config.source_root.path_by_appending(".configuration")
config.libdir = "lib"

parser = argparse.ArgumentParser(description='Configure and emit ninja build scripts for building.')
parser.add_argument('--target', dest='target', type=str, default=Target.default(), help="specify the deployment target")
Expand All @@ -144,10 +145,14 @@ def main():
parser.add_argument('--linker', dest='linker', type=str, default=None, help="which linker program to use")
parser.add_argument('--pkg-config', dest='pkg_config', type=str, default="pkg-config")
parser.add_argument('--bootstrap', dest='bootstrap', type=str, default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "bootstrap"), help="a directory for bootstrapping commonly used headers and libraries not associated directly with the target operating system")
parser.add_argument('--libdir-suffix', dest='libdir_suffix', type=str, default=None, help="library folder suffix")
parser.add_argument('--reconfigure', dest='reconfigure', action="store_true", help="re-generate the build script given the previous configuration")
parser.add_argument('-v', '--verbose', dest='verbose', action="store_true")
args, extras = parser.parse_known_args()

if args.libdir_suffix is not None:
config.libdir += args.libdir_suffix

if args.reconfigure:
reconfigure(config, config.config_path.absolute())
for arg in extras:
Expand Down
4 changes: 3 additions & 1 deletion lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Configuration:
extra_ld_flags = None
build_mode = None
config_path = None # dont save this; else it would be recursive
libdir = None
variables = {}
def __init__(self):
pass
Expand Down Expand Up @@ -90,7 +91,8 @@ def write(self, path):
'extra_ld_flags' : self.extra_ld_flags,
'build_mode' : self.build_mode,
'variables' : self.variables,
'libdir' : self.libdir,
}
with open(path, 'w+') as outfile:
json.dump(info, outfile)


3 changes: 2 additions & 1 deletion lib/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .phases import BuildAction
from .phases import MergeSwiftModule
from .target import OSType
from .target import ArchType
from .path import Path

import os
Expand Down Expand Up @@ -119,7 +120,7 @@ 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) and self.uses_swift_runtime_object:
self.runtime_object = '${SDKROOT}/lib/swift/${OS}/${ARCH}/swiftrt.o'
self.runtime_object = '${SDKROOT}/${LIBDIR}/swift/${OS}/${ARCH}/swiftrt.o'
return Library.generate(self, ["-shared", "-Wl,-soname," + self.product_name, "-Wl,--no-undefined"], objects)
else:
return Library.generate(self, ["-shared"], objects)
Expand Down
10 changes: 6 additions & 4 deletions lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

from .config import Configuration

import os

class Script:
Expand Down Expand Up @@ -66,6 +67,7 @@ def generate_products(self):
STATICLIB_PREFIX = """ + Configuration.current.target.static_library_prefix + """
STATICLIB_SUFFIX = """ + Configuration.current.target.static_library_suffix + """
PREFIX = """ + Configuration.current.prefix + """
LIBDIR = """ + Configuration.current.libdir + """
"""
if Configuration.current.requires_pkg_config:
base_flags += """
Expand Down Expand Up @@ -103,8 +105,8 @@ def generate_products(self):
c_flags += """ -I${TARGET_BOOTSTRAP_DIR}/usr/include -I${TARGET_BOOTSTRAP_DIR}/usr/local/include """

c_flags += Configuration.current.extra_c_flags

swift_flags = "\nTARGET_SWIFTCFLAGS = -I${SDKROOT}/lib/swift/" + Configuration.current.target.swift_sdk_name + " -Xcc -fblocks -resource-dir ${SDKROOT}/lib/swift "
swift_flags = "\nTARGET_SWIFTCFLAGS = -I${SDKROOT}/${LIBDIR}/swift/" + Configuration.current.target.swift_sdk_name + " -Xcc -fblocks -resource-dir ${SDKROOT}/${LIBDIR}/swift "
if swift_triple is not None:
swift_flags += "-target ${SWIFT_TARGET} "
if Configuration.current.system_root is not None:
Expand All @@ -122,7 +124,7 @@ def generate_products(self):
swift_flags += Configuration.current.extra_swift_flags

swift_flags += """
TARGET_SWIFTEXE_FLAGS = -I${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """ -L${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """ """
TARGET_SWIFTEXE_FLAGS = -I${SDKROOT}/${LIBDIR}/swift/""" + Configuration.current.target.swift_sdk_name + """ -L${SDKROOT}/${LIBDIR}/swift/""" + Configuration.current.target.swift_sdk_name + """ """
if Configuration.current.build_mode == Configuration.Debug:
swift_flags += "-g -Onone -enable-testing "
elif Configuration.current.build_mode == Configuration.Release:
Expand All @@ -135,7 +137,7 @@ def generate_products(self):
EXTRA_LD_FLAGS = """ + Configuration.current.extra_ld_flags

ld_flags += """
TARGET_LDFLAGS = --target=${TARGET} ${EXTRA_LD_FLAGS} -L ${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """/${ARCH} -L${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """ """
TARGET_LDFLAGS = --target=${TARGET} ${EXTRA_LD_FLAGS} -L ${SDKROOT}/${LIBDIR}/swift/""" + Configuration.current.target.swift_sdk_name + """/${ARCH} -L${SDKROOT}/${LIBDIR}/swift/""" + Configuration.current.target.swift_sdk_name + """ """
if Configuration.current.system_root is not None:
ld_flags += "--sysroot=${SYSROOT}"

Expand Down