summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2019-04-21 16:57:02 +0200
committerJan Ekström <jeebjp@gmail.com>2019-07-21 18:13:07 +0300
commit3f6d79ddb688ad8f3dbc0b1b652142605af85f82 (patch)
tree1fd6bb38cdfc88fefab08708fef275e819d2b33c
parent770fc5221528e18c17e7b3664ad300a96cdace3a (diff)
downloadmpv-3f6d79ddb688ad8f3dbc0b1b652142605af85f82.tar.bz2
mpv-3f6d79ddb688ad8f3dbc0b1b652142605af85f82.tar.xz
build: add Swift dynamic linking support
this is in preparation for the upcoming swift 5 transition, where static linking was replaced by dynamic linking the swift libraries as the preferred way, by Apple. furthermore Apple removed the static swift libs from their dev Tools starting with xcode 10.2/swift 5. because of ABI incompatibility dynamic linking for swift versions prior to 5 doesn't use the system lib path for the dynamic swift libs. for now static linking is still the default, but that will be changed when swift 5 support is added and swift 3 support is dropped. Fixes #6232
-rw-r--r--waftools/detections/compiler_swift.py23
-rw-r--r--wscript5
2 files changed, 26 insertions, 2 deletions
diff --git a/waftools/detections/compiler_swift.py b/waftools/detections/compiler_swift.py
index 3dffcdedd2..4ff6d20119 100644
--- a/waftools/detections/compiler_swift.py
+++ b/waftools/detections/compiler_swift.py
@@ -30,12 +30,25 @@ def __add_swift_flags(ctx):
if ctx.is_optimization():
ctx.env.SWIFT_FLAGS.append("-O")
-def __add_swift_library_linking_flags(ctx, swift_library):
+def __add_static_swift_library_linking_flags(ctx, swift_library):
ctx.env.append_value('LINKFLAGS', [
'-L%s' % swift_library,
'-Xlinker', '-force_load_swift_libs', '-lc++',
])
+def __add_dynamic_swift_library_linking_flags(ctx, swift_library):
+ ctx.env.append_value('LINKFLAGS', [ '-L%s' % swift_library ])
+
+ #ABI compatibility
+ if StrictVersion(ctx.env.SWIFT_VERSION) >= StrictVersion("5.0"):
+ ctx.env.append_value('LINKFLAGS', [
+ '-Xlinker', '-rpath', '-Xlinker', '/usr/lib/swift',
+ ])
+
+ ctx.env.append_value('LINKFLAGS', [
+ '-Xlinker', '-rpath', '-Xlinker', swift_library,
+ ])
+
def __find_swift_library(ctx):
swift_libraries = {}
#look for set lib paths in passed environment variables
@@ -90,10 +103,16 @@ def __find_swift_library(ctx):
ctx.start_msg('Checking for static Swift Library')
if 'SWIFT_LIB_STATIC' in swift_libraries:
ctx.end_msg(swift_libraries['SWIFT_LIB_STATIC'])
- __add_swift_library_linking_flags(ctx, swift_libraries['SWIFT_LIB_STATIC'])
+ ctx.env['SWIFT_LIB_STATIC'] = swift_libraries['SWIFT_LIB_STATIC']
else:
ctx.end_msg(False)
+ enableStatic = getattr(ctx.options, 'enable_swift-static')
+ if (enableStatic or enableStatic == None) and 'SWIFT_LIB_STATIC' in swift_libraries:
+ __add_static_swift_library_linking_flags(ctx, swift_libraries['SWIFT_LIB_STATIC'])
+ else:
+ __add_dynamic_swift_library_linking_flags(ctx, swift_libraries['SWIFT_LIB_DYNAMIC'])
+
def __find_macos_sdk(ctx):
ctx.start_msg('Checking for macOS SDK')
sdk = __run(['xcrun', '--sdk', 'macosx', '--show-sdk-path'])
diff --git a/wscript b/wscript
index 121f3613af..76cfe1ddd3 100644
--- a/wscript
+++ b/wscript
@@ -125,6 +125,11 @@ build_options = [
'desc': 'generate a clang compilation database',
'func': check_true,
'default': 'disable',
+ } , {
+ 'name': '--swift-static',
+ 'desc': 'static Swift linking',
+ 'deps': 'os-darwin',
+ 'func': check_ctx_vars('SWIFT_LIB_STATIC')
}
]