Skip to content

Commit

Permalink
Add a private feature for force alwayslink=True. (#1024)
Browse files Browse the repository at this point in the history
This can then be used by a toolchain that needs the behavior to ensure
all Swift code makes it into the final binary.

PiperOrigin-RevId: 516553733
(cherry picked from commit b48dda9)

Co-authored-by: Thomas Van Lenten <thomasvl@google.com>
  • Loading branch information
keith and thomasvl authored Mar 22, 2023
1 parent 9d6d6b1 commit 422c015
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,7 @@ SWIFT_FEATURE_LLD_GC_WORKAROUND = "swift.lld_gc_workaround"
# non-Apple binary top level targets. Disable this to avoid over-linking
# objects if you know that isn't required.
SWIFT_FEATURE_OBJC_LINK_FLAGS = "swift.objc_link_flag"

# A private feature that is set by the toolchain if the given toolchain wants
# all Swift compilations to always be linked.
SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE = "swift._force_alwayslink_true"
7 changes: 7 additions & 0 deletions swift/internal/linking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ load(
":feature_names.bzl",
"SWIFT_FEATURE_LLD_GC_WORKAROUND",
"SWIFT_FEATURE_OBJC_LINK_FLAGS",
"SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE",
)
load(
":developer_dirs.bzl",
Expand Down Expand Up @@ -151,6 +152,12 @@ def create_linking_context_from_compilation_outputs(
),
)

if not alwayslink:
alwayslink = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE,
)

if is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_LLD_GC_WORKAROUND,
Expand Down

0 comments on commit 422c015

Please sign in to comment.