Skip to content

Commit

Permalink
Update load statements in rules_swift to use the build-definition…
Browse files Browse the repository at this point in the history
…-specific files instead of the umbrella `swift.bzl`

PiperOrigin-RevId: 449278388
(cherry picked from commit 828d106)
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
allevato authored and brentleyjones committed Jun 20, 2024
1 parent d9c8fc9 commit 574d92d
Show file tree
Hide file tree
Showing 48 changed files with 117 additions and 129 deletions.
7 changes: 2 additions & 5 deletions examples/apple/objc_interop/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# vice versa when it is linked into the existing native linking rules for Apple
# platforms.

load(
"//swift:swift.bzl",
"swift_binary",
"swift_library",
)
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_library.bzl", "swift_library")

licenses(["notice"])

Expand Down
7 changes: 2 additions & 5 deletions examples/apple/objc_interop_modulemap/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# vice versa when it is linked into the existing native linking rules for Apple
# platforms.

load(
"//swift:swift.bzl",
"swift_binary",
"swift_library",
)
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_library.bzl", "swift_library")

licenses(["notice"])

Expand Down
7 changes: 2 additions & 5 deletions examples/apple/test_filter/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
load(
"//swift:swift.bzl",
"swift_library",
"swift_test",
)
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_test.bzl", "swift_test")

swift_library(
name = "test_filter_lib",
Expand Down
9 changes: 3 additions & 6 deletions examples/xplatform/c_from_swift/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
load(
"//swift:swift.bzl",
"swift_binary",
"swift_interop_hint",
"swift_library",
)
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_interop_hint.bzl", "swift_interop_hint")
load("//swift:swift_library.bzl", "swift_library")

licenses(["notice"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ load(
"SwiftProtoCompilerInfo",
"swift_proto_common",
)
load(
"//swift:swift.bzl",
"SwiftInfo",
)
load("//swift:providers.bzl", "SwiftInfo")

def _custom_swift_proto_compile(label, actions, swift_proto_compiler_info, additional_compiler_info, proto_infos, module_mappings):
"""Compiles Swift source files from `ProtoInfo` providers.
Expand Down
2 changes: 1 addition & 1 deletion examples/xplatform/dispatch/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//swift:swift.bzl", "swift_binary")
load("//swift:swift_binary.bzl", "swift_binary")

licenses(["notice"])

Expand Down
7 changes: 2 additions & 5 deletions examples/xplatform/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
# 3. Run the `echo_client` binary in the same terminal. It will send a request
# to this service and then print the response that it received.

load(
"//swift:swift.bzl",
"swift_binary",
"swift_test",
)
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_test.bzl", "swift_test")

licenses(["notice"])

Expand Down
2 changes: 1 addition & 1 deletion examples/xplatform/hello_world/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//swift:swift.bzl", "swift_binary")
load("//swift:swift_binary.bzl", "swift_binary")

licenses(["notice"])

Expand Down
4 changes: 3 additions & 1 deletion examples/xplatform/include_dev_srch_paths/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("//swift:swift.bzl", "swift_library", "swift_library_group", "swift_test")
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_library_group.bzl", "swift_library_group")
load("//swift:swift_test.bzl", "swift_test")

swift_library(
name = "TestHelpers",
Expand Down
4 changes: 3 additions & 1 deletion examples/xplatform/macros/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("//swift:swift.bzl", "swift_binary", "swift_library", "swift_test")
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_compiler_plugin.bzl", "swift_compiler_plugin", "universal_swift_compiler_plugin")
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_test.bzl", "swift_test")

licenses(["notice"])

Expand Down
4 changes: 3 additions & 1 deletion examples/xplatform/module_alias/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("//swift:swift.bzl", "swift_binary", "swift_library", "swift_module_alias")
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_module_alias.bzl", "swift_module_alias")

swift_binary(
name = "hello_world",
Expand Down
5 changes: 1 addition & 4 deletions examples/xplatform/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ load(
"//proto:proto.bzl",
"swift_proto_library",
)
load(
"//swift:swift.bzl",
"swift_binary",
)
load("//swift:swift_binary.bzl", "swift_binary")

licenses(["notice"])

Expand Down
5 changes: 1 addition & 4 deletions examples/xplatform/proto_files/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ load(
"//proto:proto.bzl",
"swift_proto_library",
)
load(
"//swift:swift.bzl",
"swift_binary",
)
load("//swift:swift_binary.bzl", "swift_binary")

proto_library(
name = "message_1_proto",
Expand Down
5 changes: 1 addition & 4 deletions examples/xplatform/proto_glob/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ load(
"//proto:proto.bzl",
"swift_proto_library",
)
load(
"//swift:swift.bzl",
"swift_binary",
)
load("//swift:swift_binary.bzl", "swift_binary")

proto_library(
name = "proto_glob",
Expand Down
7 changes: 2 additions & 5 deletions examples/xplatform/proto_library_group/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
load(
"//swift:swift.bzl",
"swift_binary",
"swift_test",
)
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_test.bzl", "swift_test")

swift_binary(
name = "echo_server",
Expand Down
5 changes: 1 addition & 4 deletions examples/xplatform/proto_path/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
load(
"//swift:swift.bzl",
"swift_binary",
)
load("//swift:swift_binary.bzl", "swift_binary")

swift_binary(
name = "proto_path_example",
Expand Down
4 changes: 3 additions & 1 deletion examples/xplatform/swift_import/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//swift:swift.bzl", "swift_binary", "swift_import", "swift_library")
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_import.bzl", "swift_import")
load("//swift:swift_library.bzl", "swift_library")
load(":get_swiftmodule.bzl", "get_swiftmodule")

swift_binary(
Expand Down
2 changes: 1 addition & 1 deletion examples/xplatform/swift_import/get_swiftmodule.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Return the .swiftmodule file from a swift_library for testing"""

load("//swift:swift.bzl", "SwiftInfo")
load("//swift:providers.bzl", "SwiftInfo")

def _impl(ctx):
modules = ctx.attr.lib[SwiftInfo].direct_modules
Expand Down
2 changes: 1 addition & 1 deletion examples/xplatform/xctest/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//swift:swift.bzl", "swift_test")
load("//swift:swift_test.bzl", "swift_test")

licenses(["notice"])

Expand Down
2 changes: 1 addition & 1 deletion proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load(
_swift_proto_library_group = "swift_proto_library_group",
)
load(
"//swift:swift.bzl",
"//swift:providers.bzl",
_SwiftProtoCompilerInfo = "SwiftProtoCompilerInfo",
_SwiftProtoInfo = "SwiftProtoInfo",
)
Expand Down
8 changes: 2 additions & 6 deletions proto/swift_proto_compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ load(
"//proto:swift_proto_utils.bzl",
"register_module_mapping_write_action",
)
load(
"//swift:swift.bzl",
"SwiftInfo",
"SwiftProtoCompilerInfo",
)
load("//swift:providers.bzl", "SwiftInfo", "SwiftProtoCompilerInfo")

def _swift_proto_compile(label, actions, swift_proto_compiler_info, additional_compiler_info, proto_infos, module_mappings):
"""Compiles Swift source files from `ProtoInfo` providers.
Expand Down Expand Up @@ -315,7 +311,7 @@ For example:
),
"plugin_name": attr.string(
doc = """\
Name of the proto compiler plugin passed to protoc.
Name of the proto compiler plugin passed to protoc.
For example:
Expand Down
12 changes: 3 additions & 9 deletions proto/swift_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ load(
"//proto:swift_proto_utils.bzl",
"compile_swift_protos_for_target",
)
load(
"//swift:swift.bzl",
"SwiftProtoCompilerInfo",
"swift_common",
)
load(
"//swift:swift_clang_module_aspect.bzl",
"swift_clang_module_aspect",
)
load("//swift:providers.bzl", "SwiftProtoCompilerInfo")
load("//swift:swift_clang_module_aspect.bzl", "swift_clang_module_aspect")
load("//swift:swift_common.bzl", "swift_common")

# buildifier: disable=bzl-visibility
load(
Expand Down
12 changes: 6 additions & 6 deletions proto/swift_proto_library_group.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ load(
"compile_swift_protos_for_target",
)
load(
"//swift:swift.bzl",
"//swift:providers.bzl",
"SwiftInfo",
"SwiftProtoCompilerInfo",
"SwiftProtoInfo",
"swift_common",
)
load("//swift:swift_common.bzl", "swift_common")

# buildifier: disable=bzl-visibility
load(
Expand Down Expand Up @@ -160,19 +160,19 @@ from which the Swift source files should be generated.
Generates a collection of Swift static library from a target producing `ProtoInfo` and its dependencies.
This rule is intended to facilitate migration from the deprecated swift proto library rules to the new ones.
Unlike `swift_proto_library` which is a drop-in-replacement for `swift_library`,
Unlike `swift_proto_library` which is a drop-in-replacement for `swift_library`,
this rule uses an aspect over the direct proto library dependency and its transitive dependencies,
compiling each into a swift static library.
For example, in the following targets, the `proto_library_group_swift_proto` target only depends on
`package_2_proto` target, and this transitively depends on `package_1_proto`.
When used as a dependency from a `swift_library` or `swift_binary` target,
two modules generated from these proto library targets are visible.
When used as a dependency from a `swift_library` or `swift_binary` target,
two modules generated from these proto library targets are visible.
Because these are derived from the proto library targets via an aspect, though,
you cannot customize many of the attributes including the swift proto compiler targets or
the module names. The module names are derived from the proto library names.
the module names. The module names are derived from the proto library names.
In this case, the module names are:
```
Expand Down
4 changes: 2 additions & 2 deletions proto/swift_proto_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ load(
"paths",
)
load(
"//swift:swift.bzl",
"//swift:providers.bzl",
"SwiftInfo",
"SwiftProtoCompilerInfo",
"SwiftProtoInfo",
"swift_common",
)
load("//swift:swift_common.bzl", "swift_common")

# buildifier: disable=bzl-visibility
load(
Expand Down
6 changes: 5 additions & 1 deletion swift/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ bzl_library(
bzl_library(
name = "providers",
srcs = ["providers.bzl"],
visibility = ["//swift:__subpackages__"],
visibility = [
"//swift:__subpackages__",
"//test:__subpackages__",
],
deps = [
"@bazel_skylib//lib:sets",
"@bazel_skylib//lib:types",
Expand Down Expand Up @@ -96,6 +99,7 @@ bzl_library(
visibility = [
"//proto:__subpackages__",
"//swift:__subpackages__",
"//test:__subpackages__",
],
deps = [
":providers",
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ package(default_visibility = ["//test:__subpackages__"])
bzl_library(
name = "starlark_tests_bzls",
srcs = glob(["*.bzl"]),
deps = ["//swift"],
deps = [
"//swift:providers",
"//swift:swift_clang_module_aspect",
],
)

bzl_library(
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/basic/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//swift:swift.bzl", "swift_library", "swift_library_group")
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_library_group.bzl", "swift_library_group")
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/cc_library/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
load(
"//swift:swift.bzl",
"//swift:swift_interop_hint.bzl",
"swift_interop_hint",
)
load(
"//swift:swift_library.bzl",
"swift_library",
)
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Common build definitions used by test fixtures."""

load("@build_bazel_rules_swift//swift:providers.bzl", "SwiftInfo")
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"SwiftInfo",
"@build_bazel_rules_swift//swift:swift_clang_module_aspect.bzl",
"swift_clang_module_aspect",
)

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/compiler_arguments/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("//swift:swift.bzl", "swift_binary", "swift_library", "swift_test")
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_test.bzl", "swift_test")
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/debug_settings/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
load("//swift:swift.bzl", "swift_library")
load(
"//swift:swift_library.bzl",
"swift_library",
)
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/generated_header/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
load("//swift:swift.bzl", "swift_library")
load(
"//swift:swift_library.bzl",
"swift_library",
)
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/global_index_store/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//swift:swift.bzl", "swift_library")
load("//swift:swift_library.bzl", "swift_library")
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down
Loading

0 comments on commit 574d92d

Please sign in to comment.