Skip to content
Draft
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
11 changes: 8 additions & 3 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ its transitive dependencies be propagated.
<pre>
swift_library(<a href="#swift_library-name">name</a>, <a href="#swift_library-deps">deps</a>, <a href="#swift_library-srcs">srcs</a>, <a href="#swift_library-data">data</a>, <a href="#swift_library-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_library-alwayslink">alwayslink</a>, <a href="#swift_library-copts">copts</a>,
<a href="#swift_library-defines">defines</a>, <a href="#swift_library-generated_header_name">generated_header_name</a>, <a href="#swift_library-generates_header">generates_header</a>, <a href="#swift_library-library_evolution">library_evolution</a>, <a href="#swift_library-linkopts">linkopts</a>,
<a href="#swift_library-linkstatic">linkstatic</a>, <a href="#swift_library-module_name">module_name</a>, <a href="#swift_library-package_name">package_name</a>, <a href="#swift_library-plugins">plugins</a>, <a href="#swift_library-private_deps">private_deps</a>, <a href="#swift_library-swiftc_inputs">swiftc_inputs</a>)
<a href="#swift_library-linkstatic">linkstatic</a>, <a href="#swift_library-module_name">module_name</a>, <a href="#swift_library-package_name">package_name</a>, <a href="#swift_library-plugins">plugins</a>, <a href="#swift_library-private_deps">private_deps</a>, <a href="#swift_library-suppress_warning_groups">suppress_warning_groups</a>,
<a href="#swift_library-swiftc_inputs">swiftc_inputs</a>)
</pre>

Compiles and links Swift code into a static library and Swift module.
Expand All @@ -485,6 +486,7 @@ Compiles and links Swift code into a static library and Swift module.
| <a id="swift_library-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
| <a id="swift_library-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_library-private_deps"></a>private_deps | A list of targets that are implementation-only dependencies of the target being built. Libraries/linker flags from these dependencies will be propagated to dependent for linking, but artifacts/flags required for compilation (such as .swiftmodule files, C headers, and search paths) will not be propagated.<br><br>Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` and `objc_library` (or anything propagating `CcInfo`) | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_library-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
| <a id="swift_library-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


Expand Down Expand Up @@ -618,7 +620,7 @@ remaining modules collected are not present in the `aliases` of the
<pre>
swift_overlay(<a href="#swift_overlay-name">name</a>, <a href="#swift_overlay-deps">deps</a>, <a href="#swift_overlay-srcs">srcs</a>, <a href="#swift_overlay-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_overlay-alwayslink">alwayslink</a>, <a href="#swift_overlay-copts">copts</a>, <a href="#swift_overlay-defines">defines</a>,
<a href="#swift_overlay-library_evolution">library_evolution</a>, <a href="#swift_overlay-linkopts">linkopts</a>, <a href="#swift_overlay-linkstatic">linkstatic</a>, <a href="#swift_overlay-package_name">package_name</a>, <a href="#swift_overlay-plugins">plugins</a>, <a href="#swift_overlay-private_deps">private_deps</a>,
<a href="#swift_overlay-swiftc_inputs">swiftc_inputs</a>)
<a href="#swift_overlay-suppress_warning_groups">suppress_warning_groups</a>, <a href="#swift_overlay-swiftc_inputs">swiftc_inputs</a>)
</pre>

A Swift overlay that sits on top of a C/Objective-C library, allowing an author
Expand Down Expand Up @@ -709,6 +711,7 @@ almost always an anti-pattern.
| <a id="swift_overlay-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
| <a id="swift_overlay-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_overlay-private_deps"></a>private_deps | A list of targets that are implementation-only dependencies of the target being built. Libraries/linker flags from these dependencies will be propagated to dependent for linking, but artifacts/flags required for compilation (such as .swiftmodule files, C headers, and search paths) will not be propagated.<br><br>Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` and `objc_library` (or anything propagating `CcInfo`) | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_overlay-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
| <a id="swift_overlay-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


Expand Down Expand Up @@ -772,7 +775,8 @@ swift_proto_compiler(<a href="#swift_proto_compiler-name">name</a>, <a href="#sw
swift_proto_library(<a href="#swift_proto_library-name">name</a>, <a href="#swift_proto_library-deps">deps</a>, <a href="#swift_proto_library-srcs">srcs</a>, <a href="#swift_proto_library-data">data</a>, <a href="#swift_proto_library-additional_compiler_deps">additional_compiler_deps</a>, <a href="#swift_proto_library-additional_compiler_info">additional_compiler_info</a>,
<a href="#swift_proto_library-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_proto_library-alwayslink">alwayslink</a>, <a href="#swift_proto_library-compilers">compilers</a>, <a href="#swift_proto_library-copts">copts</a>, <a href="#swift_proto_library-defines">defines</a>,
<a href="#swift_proto_library-generated_header_name">generated_header_name</a>, <a href="#swift_proto_library-generates_header">generates_header</a>, <a href="#swift_proto_library-library_evolution">library_evolution</a>, <a href="#swift_proto_library-linkopts">linkopts</a>, <a href="#swift_proto_library-linkstatic">linkstatic</a>,
<a href="#swift_proto_library-module_name">module_name</a>, <a href="#swift_proto_library-package_name">package_name</a>, <a href="#swift_proto_library-plugins">plugins</a>, <a href="#swift_proto_library-protos">protos</a>, <a href="#swift_proto_library-swiftc_inputs">swiftc_inputs</a>)
<a href="#swift_proto_library-module_name">module_name</a>, <a href="#swift_proto_library-package_name">package_name</a>, <a href="#swift_proto_library-plugins">plugins</a>, <a href="#swift_proto_library-protos">protos</a>, <a href="#swift_proto_library-suppress_warning_groups">suppress_warning_groups</a>,
<a href="#swift_proto_library-swiftc_inputs">swiftc_inputs</a>)
</pre>

Generates a Swift static library from one or more targets producing `ProtoInfo`.
Expand Down Expand Up @@ -837,6 +841,7 @@ swift_proto_library(
| <a id="swift_proto_library-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
| <a id="swift_proto_library-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_proto_library-protos"></a>protos | A list of `proto_library` targets (or targets producing `ProtoInfo`), from which the Swift source files should be generated. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="swift_proto_library-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
| <a id="swift_proto_library-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


Expand Down
14 changes: 14 additions & 0 deletions examples/xplatform/suppress_warning_groups/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//swift:swift_library.bzl", "swift_library")

swift_library(
name = "impl_dep",
srcs = ["ImplDep.swift"],
module_name = "ImplDep",
)

swift_library(
name = "impl_only_suppressed",
srcs = ["ImplementationOnlySuppressed.swift"],
private_deps = [":impl_dep"],
suppress_warning_groups = ["ImplementationOnlyDeprecated"],
)
3 changes: 3 additions & 0 deletions examples/xplatform/suppress_warning_groups/ImplDep.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct Dep {
public init() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@_implementationOnly import ImplDep

func useDepSuppressed() {
_ = Dep()
}
8 changes: 8 additions & 0 deletions proto/swift_proto_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ def compile_swift_protos_for_target(
copts = expand_make_variables(ctx, copts, "copts")
linkopts = expand_locations(ctx, getattr(attr, "linkopts", []), swiftc_inputs)
linkopts = expand_make_variables(ctx, linkopts, "linkopts")
suppress_warning_groups = getattr(attr, "suppress_warning_groups", [])
if suppress_warning_groups:
if "-print-diagnostic-groups" not in copts:
copts.append("-print-diagnostic-groups")
for group in suppress_warning_groups:
copts.append(
"-Xwrapped-swift=-suppress-warning-group={}".format(group),
)

# Compile the generated Swift source files as a module:
include_dev_srch_paths = include_developer_search_paths(attr)
Expand Down
9 changes: 9 additions & 0 deletions swift/internal/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ Note that by default, this value will default to True. But if the
swift.enable_embedded feature is on, this value will be automatically overridden
to False, as the swift features that cause -force_load to be required (such as
reflection) are not available in that mode.
""",
),
"suppress_warning_groups": attr.string_list(
doc = """\
A list of Swift diagnostic groups to suppress in build output (for example,
`DeprecatedDeclaration`). These diagnostics are filtered from the compiler's
output by the wrapper and do not change the compiler's behavior. See
https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/
for available diagnostic groups.
""",
),
"generated_header_name": attr.string(
Expand Down
9 changes: 9 additions & 0 deletions swift/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ def _swift_library_impl(ctx):
linkopts = expand_locations(ctx, ctx.attr.linkopts, ctx.attr.swiftc_inputs)
linkopts = expand_make_variables(ctx, linkopts, "linkopts")
srcs = ctx.files.srcs
if ctx.attr.suppress_warning_groups:
if "-print-diagnostic-groups" not in copts:
copts.append("-print-diagnostic-groups")
for group in ctx.attr.suppress_warning_groups:
copts.append(
"-Xwrapped-swift=-suppress-warning-group={}".format(
group,
),
)

module_copts = additional_per_module_swiftcopts(
ctx.label,
Expand Down
13 changes: 12 additions & 1 deletion swift/swift_overlay.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def _swift_overlay_impl(ctx):
deps = ctx.attr.deps
private_deps = ctx.attr.private_deps

copts = list(ctx.attr.copts)
if ctx.attr.suppress_warning_groups:
if "-print-diagnostic-groups" not in copts:
copts.append("-print-diagnostic-groups")
for group in ctx.attr.suppress_warning_groups:
copts.append(
"-Xwrapped-swift=-suppress-warning-group={}".format(
group,
),
)

features = list(ctx.features)
if ctx.attr.library_evolution:
features.append(SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION)
Expand All @@ -59,7 +70,7 @@ def _swift_overlay_impl(ctx):
label = ctx.label,
srcs = ctx.files.srcs,
additional_inputs = ctx.files.swiftc_inputs,
copts = ctx.attr.copts,
copts = copts,
defines = ctx.attr.defines,
disabled_features = ctx.disabled_features,
enabled_features = ctx.features,
Expand Down
3 changes: 3 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ load(":private_deps_tests.bzl", "private_deps_test_suite")
load(":private_swiftinterface_tests.bzl", "private_swiftinterface_test_suite")
load(":runtime_deps_tests.bzl", "runtime_deps_test_suite")
load(":split_derived_files_tests.bzl", "split_derived_files_test_suite")
load(":suppress_warning_groups_tests.bzl", "suppress_warning_groups_test_suite")
load(":swift_binary_linking_tests.bzl", "swift_binary_linking_test_suite")
load(":swift_through_non_swift_tests.bzl", "swift_through_non_swift_test_suite")
load(":symbol_graphs_tests.bzl", "symbol_graphs_test_suite")
Expand Down Expand Up @@ -69,6 +70,8 @@ private_deps_test_suite(name = "private_deps")

split_derived_files_test_suite(name = "split_derived_files")

suppress_warning_groups_test_suite(name = "suppress_warning_groups")

swift_binary_linking_test_suite(name = "swift_binary_rules")

swift_through_non_swift_test_suite(name = "swift_through_non_swift")
Expand Down
31 changes: 31 additions & 0 deletions test/fixtures/suppress_warning_groups/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("//swift:swift_library.bzl", "swift_library")
load("//swift:swift_overlay.bzl", "swift_overlay")
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
default_visibility = ["//test:__subpackages__"],
)

swift_library(
name = "single_category",
srcs = ["Library.swift"],
suppress_warning_groups = ["DeprecatedDeclaration"],
tags = FIXTURE_TAGS,
)

swift_library(
name = "multiple_categories",
srcs = ["Library.swift"],
suppress_warning_groups = [
"DeprecatedDeclaration",
"ImplementationOnlyDeprecated",
],
tags = FIXTURE_TAGS,
)

swift_overlay(
name = "overlay",
srcs = ["Overlay.swift"],
suppress_warning_groups = ["OverlayDeprecated"],
tags = FIXTURE_TAGS,
)
1 change: 1 addition & 0 deletions test/fixtures/suppress_warning_groups/Library.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func libraryFunction() {}
1 change: 1 addition & 0 deletions test/fixtures/suppress_warning_groups/Overlay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func overlayFunction() {}
95 changes: 95 additions & 0 deletions test/suppress_warning_groups_tests.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Tests for suppress_warning_groups."""

load(
"//test/rules:action_command_line_test.bzl",
"action_command_line_test",
)
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "unittest")
load("//swift/internal:providers.bzl", "SwiftOverlayCompileInfo")

def suppress_warning_groups_test_suite(name, tags = []):
"""Test suite for suppress_warning_groups handling.

Args:
name: The base name to be used in targets created by this macro.
tags: Additional tags to apply to each test.
"""
all_tags = [name] + tags

action_command_line_test(
name = "{}_swift_library_single".format(name),
expected_argv = [
"-Xwrapped-swift=-suppress-warning-group=DeprecatedDeclaration",
],
mnemonic = "SwiftCompile",
tags = all_tags,
target_under_test = "//test/fixtures/suppress_warning_groups:single_category",
)

action_command_line_test(
name = "{}_swift_library_multiple".format(name),
expected_argv = [
"-Xwrapped-swift=-suppress-warning-group=DeprecatedDeclaration",
"-Xwrapped-swift=-suppress-warning-group=ImplementationOnlyDeprecated",
],
mnemonic = "SwiftCompile",
tags = all_tags,
target_under_test = "//test/fixtures/suppress_warning_groups:multiple_categories",
)

overlay_copts_test(
name = "{}_swift_overlay_copts".format(name),
expected_copt = "-Xwrapped-swift=-suppress-warning-group=OverlayDeprecated",
tags = all_tags,
target_under_test = "//test/fixtures/suppress_warning_groups:overlay",
)

native.test_suite(
name = name,
tags = all_tags,
)

def _normalize_copt(copt):
if copt.startswith("\"") and copt.endswith("\""):
return copt[1:-1]
return copt

def _overlay_copts_test_impl(ctx):
env = analysistest.begin(ctx)
target_under_test = analysistest.target_under_test(env)

if SwiftOverlayCompileInfo not in target_under_test:
unittest.fail(
env,
"Target '{}' did not provide SwiftOverlayCompileInfo.".format(
target_under_test.label,
),
)
return analysistest.end(env)

actual = [
_normalize_copt(copt)
for copt in target_under_test[SwiftOverlayCompileInfo].copts
]
expected = ctx.attr.expected_copt
if expected not in actual:
unittest.fail(
env,
("Expected '{}' to contain '{}' in SwiftOverlayCompileInfo.copts, " +
"but got {}.").format(
target_under_test.label,
expected,
actual,
),
)
return analysistest.end(env)

overlay_copts_test = analysistest.make(
_overlay_copts_test_impl,
attrs = {
"expected_copt": attr.string(
mandatory = True,
doc = "The compiler option expected in SwiftOverlayCompileInfo.copts.",
),
},
)
Loading