Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generate_internal_visibility_from_proto_files feature #962

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ SWIFT_FEATURE_GENERATE_FROM_RAW_PROTO_FILES = "swift.generate_from_raw_proto_fil
# generating a Swift file from a proto file.
SWIFT_FEATURE_GENERATE_PATH_TO_UNDERSCORES_FROM_PROTO_FILES = "swift.generate_path_to_underscores_from_proto_files"

# If enabled, the toolchain will use `--swift_opt=Visibility=Internal`
# (instead of `--swift_opt=Visibility=Public`) for the protoc Swift plugin arguments when
# generating a Swift file from a proto file.
SWIFT_FEATURE_GENERATE_INTERNAL_VISIBILITY_FROM_PROTO_FILES = "swift.generate_internal_visibility_from_proto_files"

# If enabled and whole module optimisation is being used, the `*.swiftdoc`,
# `*.swiftmodule` and `*-Swift.h` are generated with a separate action
# rather than as part of the compilation.
Expand Down
15 changes: 14 additions & 1 deletion swift/internal/swift_protoc_gen_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ load(
"SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION",
"SWIFT_FEATURE_ENABLE_TESTING",
"SWIFT_FEATURE_GENERATE_FROM_RAW_PROTO_FILES",
"SWIFT_FEATURE_GENERATE_INTERNAL_VISIBILITY_FROM_PROTO_FILES",
"SWIFT_FEATURE_GENERATE_PATH_TO_UNDERSCORES_FROM_PROTO_FILES",
)
load(":linking.bzl", "new_objc_provider")
Expand Down Expand Up @@ -107,6 +108,7 @@ def _register_pbswift_generate_action(
module_mapping_file,
generate_from_proto_sources,
generate_path_to_underscores_from_proto_files,
generate_internal_visibility_from_proto_files,
mkdir_and_run,
protoc_executable,
protoc_plugin_executable,
Expand All @@ -132,6 +134,8 @@ def _register_pbswift_generate_action(
comments (https://github.com/bazelbuild/bazel/issues/9337).
generate_path_to_underscores_from_proto_files: True/False for if
generation should use `FileNaming=PathToUnderscores` argument.
generate_internal_visibility_from_proto_files: True/False for if
generation should use `Visibility=Internal` argument
mkdir_and_run: The `File` representing the `mkdir_and_run` executable.
protoc_executable: The `File` representing the `protoc` executable.
protoc_plugin_executable: The `File` representing the `protoc` plugin
Expand Down Expand Up @@ -182,7 +186,11 @@ def _register_pbswift_generate_action(
else:
protoc_args.add("--swift_opt=FileNaming=FullPath")

protoc_args.add("--swift_opt=Visibility=Public")
if generate_internal_visibility_from_proto_files:
protoc_args.add("--swift_opt=Visibility=Internal")
else:
protoc_args.add("--swift_opt=Visibility=Public")

if module_mapping_file:
protoc_args.add(
module_mapping_file,
Expand Down Expand Up @@ -392,6 +400,10 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_GENERATE_PATH_TO_UNDERSCORES_FROM_PROTO_FILES,
)
generate_internal_visibility_from_proto_files = swift_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_GENERATE_INTERNAL_VISIBILITY_FROM_PROTO_FILES,
)

# Only the files for direct sources should be generated, but the
# transitive descriptor sets are still need to be able to parse/load
Expand All @@ -418,6 +430,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
transitive_module_mapping_file,
generate_from_proto_sources,
generate_path_to_underscores_from_proto_files,
generate_internal_visibility_from_proto_files,
aspect_ctx.executable._mkdir_and_run,
aspect_ctx.executable._protoc,
aspect_ctx.executable._protoc_gen_swift,
Expand Down
5 changes: 0 additions & 5 deletions third_party/com_github_apple_swift_log/BUILD.overlay
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load(
"@build_bazel_apple_support//rules:universal_binary.bzl",
"universal_binary",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

Expand Down
26 changes: 12 additions & 14 deletions third_party/com_github_apple_swift_nio/BUILD.overlay
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load(
"@build_bazel_apple_support//rules:universal_binary.bzl",
"universal_binary",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

Expand All @@ -13,12 +8,12 @@ swift_library(
srcs = glob([
"Sources/NIOCore/*.swift",
]),
module_name = "NIOCore",
visibility = ["//visibility:public"],
deps = [
":NIOConcurrencyHelpers",
":CNIOLinux",
":NIOConcurrencyHelpers",
],
module_name = "NIOCore",
visibility = ["//visibility:public"],
)

swift_library(
Expand All @@ -29,8 +24,8 @@ swift_library(
module_name = "NIOEmbedded",
visibility = ["//visibility:public"],
deps = [
"NIOCore",
"NIOConcurrencyHelpers",
"NIOCore",
"_NIODataStructures",
],
)
Expand All @@ -43,8 +38,8 @@ swift_library(
module_name = "NIOPosix",
visibility = ["//visibility:public"],
deps = [
"CNIOLinux",
"CNIODarwin",
"CNIOLinux",
"CNIOWindows",
"NIOConcurrencyHelpers",
"NIOCore",
Expand Down Expand Up @@ -73,7 +68,10 @@ swift_library(
]),
module_name = "_NIOConcurrency",
visibility = ["//visibility:public"],
deps = ["NIO", "NIOCore"],
deps = [
"NIO",
"NIOCore",
],
)

swift_library(
Expand Down Expand Up @@ -179,8 +177,8 @@ swift_library(
module_name = "NIOHTTP1",
visibility = ["//visibility:public"],
deps = [
":NIOCore",
":CNIOHTTPParser",
":NIOCore",
],
)

Expand All @@ -202,9 +200,9 @@ swift_library(
module_name = "_NIODataStructures",
visibility = ["//visibility:public"],
deps = [
"NIOCore",
"NIOConcurrencyHelpers",
"CNIOHTTPParser",
"NIOConcurrencyHelpers",
"NIOCore",
],
)

Expand Down
9 changes: 2 additions & 7 deletions third_party/com_github_apple_swift_nio_extras/BUILD.overlay
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load(
"@build_bazel_apple_support//rules:universal_binary.bzl",
"universal_binary",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

Expand All @@ -13,9 +8,9 @@ swift_library(
srcs = glob([
"Sources/NIOExtras/**/*.swift",
]),
module_name = "NIOExtras",
visibility = ["//visibility:public"],
deps = [
"@com_github_apple_swift_nio//:NIOCore",
],
module_name = "NIOExtras",
visibility = ["//visibility:public"],
)
13 changes: 4 additions & 9 deletions third_party/com_github_apple_swift_nio_http2/BUILD.overlay
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load(
"@build_bazel_apple_support//rules:universal_binary.bzl",
"universal_binary",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

Expand All @@ -13,23 +8,23 @@ swift_library(
srcs = glob([
"Sources/NIOHPACK/**/*.swift",
]),
module_name = "NIOHPACK",
visibility = ["//visibility:public"],
deps = [
"@com_github_apple_swift_nio//:NIOCore",
"@com_github_apple_swift_nio//:NIOHTTP1",
"@com_github_apple_swift_nio//:NIOTLS",
],
module_name = "NIOHPACK",
visibility = ["//visibility:public"],
)

swift_library(
name = "NIOHTTP2",
srcs = glob([
"Sources/NIOHTTP2/**/*.swift",
]),
module_name = "NIOHTTP2",
visibility = ["//visibility:public"],
deps = [
":NIOHPACK",
],
module_name = "NIOHTTP2",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load(
"@build_bazel_apple_support//rules:universal_binary.bzl",
"universal_binary",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

Expand All @@ -13,11 +8,11 @@ swift_library(
srcs = glob([
"Sources/NIOTransportServices/**/*.swift",
]),
module_name = "NIOTransportServices",
visibility = ["//visibility:public"],
deps = [
"@com_github_apple_swift_nio//:NIOCore",
"@com_github_apple_swift_nio//:NIOFoundationCompat",
"@com_github_apple_swift_nio//:NIOTLS",
],
module_name = "NIOTransportServices",
visibility = ["//visibility:public"],
)