From bbddd362f0216375929ae9e54e98b86c594721df Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Mon, 30 Dec 2024 22:28:35 -0300 Subject: [PATCH] Add features support --- swiftpkg/internal/pkginfos.bzl | 8 +++++++- swiftpkg/internal/swiftpkg_build_files.bzl | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/swiftpkg/internal/pkginfos.bzl b/swiftpkg/internal/pkginfos.bzl index 08aa9a413..52a184b0d 100644 --- a/swiftpkg/internal/pkginfos.bzl +++ b/swiftpkg/internal/pkginfos.bzl @@ -1437,6 +1437,7 @@ def _new_swift_settings(build_settings): defines = [] unsafe_flags = [] experimental_features = [] + upcoming_features = [] for bs in build_settings: if bs.kind == build_setting_kinds.define: defines.append(bs) @@ -1444,17 +1445,21 @@ def _new_swift_settings(build_settings): unsafe_flags.append(bs) elif bs.kind == build_setting_kinds.experimental_features: experimental_features.append(bs) + elif bs.kind == build_setting_kinds.upcoming_features: + upcoming_features.append(bs) else: # We do not recognize the setting. pass if len(defines) == 0 and \ len(unsafe_flags) == 0 and \ - len(experimental_features) == 0: + len(experimental_features) == 0 and \ + len(upcoming_features) == 0: return None return struct( defines = defines, unsafe_flags = unsafe_flags, experimental_features = experimental_features, + upcoming_features = upcoming_features, ) def _new_linker_settings(build_settings): @@ -1640,6 +1645,7 @@ build_setting_kinds = struct( linked_library = "linkedLibrary", unsafe_flags = "unsafeFlags", experimental_features = "enableExperimentalFeature", + upcoming_features = "enableUpcomingFeature", ) # MARK: - API Definition diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index f16a12560..4a3af3b10 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -114,9 +114,10 @@ def _swift_target_build_file(pkg_ctx, target): # Check if any of the sources indicate that the module will be used by # Objective-C code. If so, generate the bridge header file. + features = [] if target.swift_src_info.has_objc_directive and is_library_target: attrs["generates_header"] = True - attrs["features"] = ["swift.propagate_generated_module_map"] + features.append("swift.propagate_generated_module_map") if target.swift_settings != None: if len(target.swift_settings.defines) > 0: @@ -134,8 +135,15 @@ def _swift_target_build_file(pkg_ctx, target): ])) if len(target.swift_settings.experimental_features) > 0: for bs in target.swift_settings.experimental_features: - copts.append("-enable-experimental-feature") - copts.extend(lists.flatten(bzl_selects.new_from_build_setting(bs))) + for experimental_feature in lists.flatten(bzl_selects.new_from_build_setting(bs)): + features.append("swift.experimental_feature." + experimental_feature) + if len(target.swift_settings.upcoming_features) > 0: + for bs in target.swift_settings.upcoming_features: + for upcoming_feature in lists.flatten(bzl_selects.new_from_build_setting(bs)): + features.append("swift.upcoming_feature." + upcoming_feature) + + if len(features) > 0: + attrs["features"] = features if len(copts) > 0: attrs["copts"] = bzl_selects.to_starlark(copts, mutually_inclusive = True)