mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
770fc52215
commit
3f6d79ddb6
|
@ -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'])
|
||||
|
|
Loading…
Reference in New Issue