diff options
Diffstat (limited to 'waftools')
-rw-r--r-- | waftools/checks/custom.py | 14 | ||||
-rw-r--r-- | waftools/detections/compiler_swift.py | 71 | ||||
-rw-r--r-- | waftools/generators/sources.py | 11 |
3 files changed, 82 insertions, 14 deletions
diff --git a/waftools/checks/custom.py b/waftools/checks/custom.py index 3af9bdb921..14e59f3f49 100644 --- a/waftools/checks/custom.py +++ b/waftools/checks/custom.py @@ -92,18 +92,6 @@ def check_wl_protocols(ctx, dependency_identifier): return ret return fn(ctx, dependency_identifier) -def _run(cmd): - from waflib import Utils - try: - cmd = Utils.subprocess.Popen(cmd, - stdout=Utils.subprocess.PIPE, - stderr=Utils.subprocess.PIPE, - shell=True) - output = cmd.stdout.read().strip() - return output - except Exception: - return "" - def check_cocoa(ctx, dependency_identifier): fn = check_cc( fragment = load_fragment('cocoa.m'), @@ -117,7 +105,7 @@ def check_cocoa(ctx, dependency_identifier): # linking warnings or errors if res: ctx.env.append_value('LINKFLAGS', [ - '-isysroot', '%s' % _run('xcrun --sdk macosx --show-sdk-path') + '-isysroot', ctx.env.MACOS_SDK ]) return res diff --git a/waftools/detections/compiler_swift.py b/waftools/detections/compiler_swift.py new file mode 100644 index 0000000000..36f4f0b432 --- /dev/null +++ b/waftools/detections/compiler_swift.py @@ -0,0 +1,71 @@ +from waflib import Utils + +def __run(cmd): + try: + cmd = Utils.subprocess.Popen(cmd, + stdout=Utils.subprocess.PIPE, + stderr=Utils.subprocess.PIPE, + shell=True) + output = cmd.stdout.read().strip() + return output + except Exception: + return "" + +def __add_swift_flags(ctx): + ctx.env.SWIFT_FLAGS = ('-frontend -c -sdk %s -enable-objc-interop -emit-objc-header' + ' -emit-module -parse-as-library') % (ctx.env.MACOS_SDK) + swift_version = __run(ctx.env.SWIFT + ' -version').split(' ')[3].split('.') + major, minor, sub = [int(n) for n in swift_version] + + # the -swift-version parameter is only supported on swift 3.1 and newer + if major >= 3 and minor >= 1 or major >= 4: + ctx.env.SWIFT_FLAGS += ' -swift-version 3' + + if ctx.is_optimization(): + ctx.env.SWIFT_FLAGS += ' -O' + +def __add_swift_library_linking_flags(ctx, swift_library): + ctx.env.append_value('LINKFLAGS', [ + '-L%s' % swift_library, + '-Xlinker', '-force_load_swift_libs', '-lc++', + ]) + +def __find_swift_library(ctx): + swift_library_paths = [ + 'Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx', + 'usr/lib/swift_static/macosx' + ] + dev_path = __run('xcode-select -p')[1:] + + ctx.start_msg('Checking for Swift Library') + for path in swift_library_paths: + swift_library = ctx.root.find_dir([dev_path, path]) + if swift_library is not None: + ctx.end_msg(swift_library) + __add_swift_library_linking_flags(ctx, swift_library) + return + ctx.end_msg(None, "RED") + +def __find_macos_sdk(ctx): + ctx.start_msg('Checking for macOS SDK') + sdk = __run('xcrun --sdk macosx --show-sdk-path') + if sdk != "": + ctx.end_msg(sdk) + ctx.env.MACOS_SDK = sdk + else: + ctx.end_msg(None, "RED") + +def __find_swift_compiler(ctx): + ctx.start_msg('Checking for swift (Swift compiler)') + swift = __run('xcrun -find swift') + if swift != "": + ctx.end_msg(swift) + ctx.env.SWIFT = swift + __add_swift_flags(ctx) + __find_swift_library(ctx) + else: + ctx.end_msg(None, "RED") + +def configure(ctx): + __find_macos_sdk(ctx) + __find_swift_compiler(ctx) diff --git a/waftools/generators/sources.py b/waftools/generators/sources.py index b0b423edda..b7766cc1b6 100644 --- a/waftools/generators/sources.py +++ b/waftools/generators/sources.py @@ -1,5 +1,5 @@ from waflib.Build import BuildContext -from waflib import TaskGen +from waflib import TaskGen, Utils from io import StringIO from TOOLS.matroska import generate_C_header, generate_C_definitions from TOOLS.file2string import file2string @@ -71,6 +71,15 @@ def __wayland_protocol_header__(ctx, **kwargs): **kwargs ) +@TaskGen.feature('cprogram') +@TaskGen.feature('apply_link') +def handle_add_object(tgen): + if getattr(tgen, 'add_object', None): + for input in Utils.to_list(tgen.add_object): + input_node = tgen.path.find_resource(input) + if input_node is not None: + tgen.link_task.inputs.append(input_node) + BuildContext.file2string = __file2string__ BuildContext.wayland_protocol_code = __wayland_protocol_code__ BuildContext.wayland_protocol_header = __wayland_protocol_header__ |