Skip to content

Commit

Permalink
fix: set alwayslink = True (#1385)
Browse files Browse the repository at this point in the history
This matches SPM’s behavior. It’s needed to create dynamic frameworks
from rspm targets.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones authored Dec 16, 2024
1 parent c83c18e commit a3d35c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions swiftpkg/internal/swiftpkg_build_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def _swift_library_from_target(target, attrs):
# library targets. So, we do too.
attrs["always_include_developer_search_paths"] = True

# To mimic SPM behavior we always link the library. This will become the
# default in rules_swift 3.0, and we can remove it then.
attrs["alwayslink"] = True

return build_decls.new(
kind = swift_kinds.library,
name = pkginfo_targets.bazel_label_name(target),
Expand Down Expand Up @@ -329,6 +333,8 @@ def _clang_target_build_file(repository_ctx, pkg_ctx, target):
# Assemble attributes

attrs = {
# To mimic SPM behavior we always link the library.
"alwayslink": True,
"copts": copts,
"srcs": srcs,
"visibility": ["//:__subpackages__"],
Expand Down
10 changes: 10 additions & 0 deletions swiftpkg/tests/swiftpkg_build_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "RegularSwiftTargetAsLibrary.rspm",
always_include_developer_search_paths = True,
alwayslink = True,
copts = ["-DSWIFT_PACKAGE"],
module_name = "RegularSwiftTargetAsLibrary",
package_name = "MyPackage",
Expand All @@ -515,6 +516,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "RegularTargetForExec.rspm",
always_include_developer_search_paths = True,
alwayslink = True,
copts = ["-DSWIFT_PACKAGE"],
deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
module_name = "RegularTargetForExec",
Expand Down Expand Up @@ -589,6 +591,7 @@ cc_library(
cc_library(
name = "ClangLibrary.rspm_cxx",
alwayslink = True,
aspect_hints = ["ClangLibrary.rspm_swift_hint"],
copts = [
"-fblocks",
Expand Down Expand Up @@ -654,6 +657,7 @@ objc_library(
objc_library(
name = "ObjcLibrary.rspm_objc",
alwayslink = True,
aspect_hints = ["ObjcLibrary.rspm_swift_hint"],
copts = [
"-fblocks",
Expand Down Expand Up @@ -712,6 +716,7 @@ objc_library(
objc_library(
name = "ObjcLibraryWithModulemap.rspm_objc",
alwayslink = True,
aspect_hints = ["ObjcLibraryWithModulemap.rspm_swift_hint"],
copts = [
"-fblocks",
Expand Down Expand Up @@ -765,6 +770,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "SwiftLibraryWithConditionalDep.rspm",
always_include_developer_search_paths = True,
alwayslink = True,
copts = ["-DSWIFT_PACKAGE"],
deps = ["@swiftpkg_mypackage//:ClangLibrary.rspm"] + select({
"@rules_swift_package_manager//config_settings/spm/platform:ios": ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
Expand Down Expand Up @@ -797,6 +803,7 @@ cc_library(
cc_library(
name = "ClangLibraryWithConditionalDep.rspm_cxx",
alwayslink = True,
aspect_hints = ["ClangLibraryWithConditionalDep.rspm_swift_hint"],
copts = [
"-fblocks",
Expand Down Expand Up @@ -845,6 +852,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "SwiftForObjcTarget.rspm",
always_include_developer_search_paths = True,
alwayslink = True,
copts = ["-DSWIFT_PACKAGE"],
deps = ["@swiftpkg_mypackage//:ObjcLibraryDep.rspm"],
features = ["swift.propagate_generated_module_map"],
Expand Down Expand Up @@ -886,6 +894,7 @@ resource_bundle_infoplist(
swift_library(
name = "SwiftLibraryWithFilePathResource.rspm",
always_include_developer_search_paths = True,
alwayslink = True,
copts = ["-DSWIFT_PACKAGE"],
data = [":SwiftLibraryWithFilePathResource.rspm_resource_bundle"],
module_name = "SwiftLibraryWithFilePathResource",
Expand Down Expand Up @@ -934,6 +943,7 @@ objc_library(
objc_library(
name = "ObjcLibraryWithResources.rspm_objc",
alwayslink = True,
aspect_hints = ["ObjcLibraryWithResources.rspm_swift_hint"],
copts = [
"-fblocks",
Expand Down

0 comments on commit a3d35c0

Please sign in to comment.