Skip to content

Commit 7b92e4d

Browse files
committed
Add example with deps in swift_import
1 parent 61e2c46 commit 7b92e4d

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

Diff for: test/fixtures/module_interface/BUILD

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ swift_binary(
1313
name = "client",
1414
srcs = ["Client.swift"],
1515
tags = FIXTURE_TAGS,
16-
deps = [":toy_module"],
16+
deps = [
17+
":toy_module",
18+
":toy_module_consumer",
19+
],
1720
)
1821

1922
swift_import(
@@ -26,3 +29,15 @@ swift_import(
2629
swiftinterface = "//test/fixtures/module_interface/library:toy_outputs/ToyModule.swiftinterface",
2730
tags = FIXTURE_TAGS,
2831
)
32+
33+
swift_import(
34+
name = "toy_module_consumer",
35+
archives = [
36+
"//test/fixtures/module_interface/library_consumer:toy_consumer_outputs/libToyModuleConsumer.a",
37+
],
38+
module_name = "ToyModuleConsumer",
39+
swiftdoc = "//test/fixtures/module_interface/library_consumer:toy_consumer_outputs/ToyModuleConsumer.swiftdoc",
40+
swiftinterface = "//test/fixtures/module_interface/library_consumer:toy_consumer_outputs/ToyModuleConsumer.swiftinterface",
41+
tags = FIXTURE_TAGS,
42+
deps = [":toy_module"],
43+
)

Diff for: test/fixtures/module_interface/Client.swift

+2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
// limitations under the License.
1414

1515
import ToyModule
16+
import ToyModuleConsumer
1617

1718
@main
1819
struct Main {
1920
static func main() {
2021
let value = ToyValue(number: 10)
2122
print(value.stringValue)
2223
print(value.squared())
24+
printToyValue()
2325
}
2426
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
load("//swift:swift_library.bzl", "swift_library")
2+
load(
3+
"//test/fixtures:common.bzl",
4+
"FIXTURE_TAGS",
5+
)
6+
load(
7+
"//test/rules:swift_library_artifact_collector.bzl",
8+
"swift_library_artifact_collector",
9+
)
10+
11+
package(
12+
default_testonly = True,
13+
default_visibility = ["//test:__subpackages__"],
14+
)
15+
16+
licenses(["notice"])
17+
18+
# Checking in pre-built artifacts like a `.swiftinterface` and static libraries
19+
# would require different artifacts for every platform the test might run on.
20+
# Instead, build it on-demand but forward the outputs using the "artifact
21+
# collector" rule below to make them act as if they were pre-built outputs when
22+
# referenced by the `swift_import` rule.
23+
#
24+
# These must be in a separate package than the `swift_import` target because
25+
# that rule propagates its pre-built inputs in `DefaultInfo`.
26+
27+
swift_library(
28+
name = "toy_module_consumer",
29+
srcs = ["ToyConsumer.swift"],
30+
library_evolution = True,
31+
module_name = "ToyModuleConsumer",
32+
tags = FIXTURE_TAGS,
33+
deps = ["//test/fixtures/module_interface/library:toy_module_library"],
34+
)
35+
36+
swift_library_artifact_collector(
37+
name = "toy_module_consumer_artifact_collector",
38+
static_library = "toy_consumer_outputs/libToyModuleConsumer.a",
39+
swiftdoc = "toy_consumer_outputs/ToyModuleConsumer.swiftdoc",
40+
swiftinterface = "toy_consumer_outputs/ToyModuleConsumer.swiftinterface",
41+
tags = FIXTURE_TAGS,
42+
target = ":toy_module_consumer",
43+
target_compatible_with = ["@platforms//os:macos"],
44+
)
45+
46+
swift_library(
47+
name = "toy_module_consumer_without_library_evolution",
48+
srcs = ["ToyConsumer.swift"],
49+
library_evolution = False,
50+
module_name = "ToyModuleConsumerNoEvolution",
51+
tags = FIXTURE_TAGS,
52+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2024 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import ToyModule
16+
17+
public func printToyValue() {
18+
print(ToyValue(number: 42))
19+
}

0 commit comments

Comments
 (0)