-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom
module_map
s in swift_interop_hint
.
This allows rules like `cc_library` to associate a custom module map if needed (however, this should be rare and used sparingly). It also eliminates the need for the `swift_c_module`, which will be removed. Added analysis tests around the propagation of the module map artifacts. PiperOrigin-RevId: 387195026
- Loading branch information
1 parent
c42a37a
commit 1356365
Showing
9 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
load( | ||
"//swift:swift.bzl", | ||
"swift_interop_hint", | ||
"swift_library", | ||
) | ||
load("//test/fixtures:common.bzl", "FIXTURE_TAGS") | ||
|
||
package( | ||
default_visibility = ["//test:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) | ||
|
||
swift_library( | ||
name = "import_module_name_swift", | ||
srcs = ["ImportModuleName.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":cc_lib_custom_module_name"], | ||
) | ||
|
||
cc_library( | ||
name = "cc_lib_custom_module_name", | ||
hdrs = [ | ||
"header1.h", | ||
"header2.h", | ||
], | ||
aspect_hints = [":cc_lib_custom_module_name_hint"], | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_interop_hint( | ||
name = "cc_lib_custom_module_name_hint", | ||
module_name = "ModuleName", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_library( | ||
name = "import_submodule_swift", | ||
srcs = ["ImportSubmodule.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":cc_lib_submodule"], | ||
) | ||
|
||
cc_library( | ||
name = "cc_lib_submodule", | ||
hdrs = [ | ||
"header1.h", | ||
"header2.h", | ||
], | ||
aspect_hints = [":cc_lib_submodule_hint"], | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_interop_hint( | ||
name = "cc_lib_submodule_hint", | ||
module_map = "module.modulemap", | ||
module_name = "TopModule", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_library( | ||
name = "invalid_swift", | ||
srcs = ["ImportSubmodule.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":cc_lib_invalid"], | ||
) | ||
|
||
cc_library( | ||
name = "cc_lib_invalid", | ||
hdrs = [ | ||
"header1.h", | ||
"header2.h", | ||
], | ||
aspect_hints = [":cc_lib_invalid_hint"], | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_interop_hint( | ||
name = "cc_lib_invalid_hint", | ||
module_map = "module.modulemap", | ||
tags = FIXTURE_TAGS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import ModuleName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import TopModule.Submodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module TopModule { | ||
header "header1.h" | ||
export * | ||
|
||
module Submodule { | ||
header "header2.h" | ||
export * | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright 2021 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for `swift_interop_hint`.""" | ||
|
||
load( | ||
"@build_bazel_rules_swift//test/rules:analysis_failure_test.bzl", | ||
"analysis_failure_test", | ||
) | ||
load( | ||
"@build_bazel_rules_swift//test/rules:provider_test.bzl", | ||
"provider_test", | ||
) | ||
|
||
def interop_hints_test_suite(): | ||
"""Test suite for `swift_interop_hint`.""" | ||
name = "interop_hints" | ||
|
||
# Verify that a hint with only a custom module name causes the `cc_library` | ||
# to propagate a `SwiftInfo` info with the expected auto-generated module | ||
# map. | ||
provider_test( | ||
name = "{}_hint_with_custom_module_name_builds".format(name), | ||
expected_files = [ | ||
"test/fixtures/interop_hints/cc_lib_custom_module_name.swift.modulemap", | ||
], | ||
field = "transitive_modules.clang.module_map!", | ||
provider = "SwiftInfo", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/interop_hints:import_module_name_swift", | ||
) | ||
|
||
# Verify that a hint with a custom module map file causes the `cc_library` | ||
# to propagate a `SwiftInfo` info with that file. | ||
provider_test( | ||
name = "{}_hint_with_custom_module_map_builds".format(name), | ||
expected_files = [ | ||
"test/fixtures/interop_hints/module.modulemap", | ||
], | ||
field = "transitive_modules.clang.module_map!", | ||
provider = "SwiftInfo", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/interop_hints:import_submodule_swift", | ||
) | ||
|
||
# Verify that the build fails if a hint provides `module_map` without | ||
# `module_name`. | ||
analysis_failure_test( | ||
name = "{}_fails_when_module_map_provided_without_module_name".format(name), | ||
expected_message = "'module_name' must be specified when 'module_map' is specified.", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/interop_hints:invalid_swift", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tags = [name], | ||
) |
1356365
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#691
1356365
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1191