Skip to content

Commit a3d35c0

Browse files
fix: set alwayslink = True (#1385)
This matches SPM’s behavior. It’s needed to create dynamic frameworks from rspm targets. Signed-off-by: Brentley Jones <[email protected]>
1 parent c83c18e commit a3d35c0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

swiftpkg/internal/swiftpkg_build_files.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def _swift_library_from_target(target, attrs):
184184
# library targets. So, we do too.
185185
attrs["always_include_developer_search_paths"] = True
186186

187+
# To mimic SPM behavior we always link the library. This will become the
188+
# default in rules_swift 3.0, and we can remove it then.
189+
attrs["alwayslink"] = True
190+
187191
return build_decls.new(
188192
kind = swift_kinds.library,
189193
name = pkginfo_targets.bazel_label_name(target),
@@ -329,6 +333,8 @@ def _clang_target_build_file(repository_ctx, pkg_ctx, target):
329333
# Assemble attributes
330334

331335
attrs = {
336+
# To mimic SPM behavior we always link the library.
337+
"alwayslink": True,
332338
"copts": copts,
333339
"srcs": srcs,
334340
"visibility": ["//:__subpackages__"],

swiftpkg/tests/swiftpkg_build_files_tests.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
494494
swift_library(
495495
name = "RegularSwiftTargetAsLibrary.rspm",
496496
always_include_developer_search_paths = True,
497+
alwayslink = True,
497498
copts = ["-DSWIFT_PACKAGE"],
498499
module_name = "RegularSwiftTargetAsLibrary",
499500
package_name = "MyPackage",
@@ -515,6 +516,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
515516
swift_library(
516517
name = "RegularTargetForExec.rspm",
517518
always_include_developer_search_paths = True,
519+
alwayslink = True,
518520
copts = ["-DSWIFT_PACKAGE"],
519521
deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
520522
module_name = "RegularTargetForExec",
@@ -589,6 +591,7 @@ cc_library(
589591
590592
cc_library(
591593
name = "ClangLibrary.rspm_cxx",
594+
alwayslink = True,
592595
aspect_hints = ["ClangLibrary.rspm_swift_hint"],
593596
copts = [
594597
"-fblocks",
@@ -654,6 +657,7 @@ objc_library(
654657
655658
objc_library(
656659
name = "ObjcLibrary.rspm_objc",
660+
alwayslink = True,
657661
aspect_hints = ["ObjcLibrary.rspm_swift_hint"],
658662
copts = [
659663
"-fblocks",
@@ -712,6 +716,7 @@ objc_library(
712716
713717
objc_library(
714718
name = "ObjcLibraryWithModulemap.rspm_objc",
719+
alwayslink = True,
715720
aspect_hints = ["ObjcLibraryWithModulemap.rspm_swift_hint"],
716721
copts = [
717722
"-fblocks",
@@ -765,6 +770,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
765770
swift_library(
766771
name = "SwiftLibraryWithConditionalDep.rspm",
767772
always_include_developer_search_paths = True,
773+
alwayslink = True,
768774
copts = ["-DSWIFT_PACKAGE"],
769775
deps = ["@swiftpkg_mypackage//:ClangLibrary.rspm"] + select({
770776
"@rules_swift_package_manager//config_settings/spm/platform:ios": ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
@@ -797,6 +803,7 @@ cc_library(
797803
798804
cc_library(
799805
name = "ClangLibraryWithConditionalDep.rspm_cxx",
806+
alwayslink = True,
800807
aspect_hints = ["ClangLibraryWithConditionalDep.rspm_swift_hint"],
801808
copts = [
802809
"-fblocks",
@@ -845,6 +852,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
845852
swift_library(
846853
name = "SwiftForObjcTarget.rspm",
847854
always_include_developer_search_paths = True,
855+
alwayslink = True,
848856
copts = ["-DSWIFT_PACKAGE"],
849857
deps = ["@swiftpkg_mypackage//:ObjcLibraryDep.rspm"],
850858
features = ["swift.propagate_generated_module_map"],
@@ -886,6 +894,7 @@ resource_bundle_infoplist(
886894
swift_library(
887895
name = "SwiftLibraryWithFilePathResource.rspm",
888896
always_include_developer_search_paths = True,
897+
alwayslink = True,
889898
copts = ["-DSWIFT_PACKAGE"],
890899
data = [":SwiftLibraryWithFilePathResource.rspm_resource_bundle"],
891900
module_name = "SwiftLibraryWithFilePathResource",
@@ -934,6 +943,7 @@ objc_library(
934943
935944
objc_library(
936945
name = "ObjcLibraryWithResources.rspm_objc",
946+
alwayslink = True,
937947
aspect_hints = ["ObjcLibraryWithResources.rspm_swift_hint"],
938948
copts = [
939949
"-fblocks",

0 commit comments

Comments
 (0)