Skip to content

Commit

Permalink
Add features support
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaTheFun committed Dec 31, 2024
1 parent ca7b507 commit bbddd36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion swiftpkg/internal/pkginfos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1437,24 +1437,29 @@ 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)
elif bs.kind == build_setting_kinds.unsafe_flags:
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):
Expand Down Expand Up @@ -1640,6 +1645,7 @@ build_setting_kinds = struct(
linked_library = "linkedLibrary",
unsafe_flags = "unsafeFlags",
experimental_features = "enableExperimentalFeature",
upcoming_features = "enableUpcomingFeature",
)

# MARK: - API Definition
Expand Down
14 changes: 11 additions & 3 deletions swiftpkg/internal/swiftpkg_build_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit bbddd36

Please sign in to comment.