Skip to content

Commit 762f604

Browse files
Add genrules to Example project (#19)
* Add an example GenerateDummySwiftFile genrule This genrule actually breaks indexing! You can see SourceKit LSP tries to index the genrule itself... [11:02:04 AM] 🟨🟫⬛️ Indexing /Users/.../sourcekit-bazel-bsp/Example/HelloWorld/GenerateDummySwiftFile [11:02:04 AM] 🟨🟫⬛️ clang: error: no input files [11:02:04 AM] 🟨🟫⬛️ Finished with exit code 1 in 0.00619425 seconds I'm not sure how to fix this — any help would be appreciated, thanks! * Update HelloWorld to use 'expand_template_rule' Add another example that causing this indexing error to occur [11:16:39 AM] 🟪🟩⬛️ clang: error: no input files [11:16:39 AM] 🟨⬜️🟨 clang: error: no input files [11:16:39 AM] 🟪🟩⬛️ Finished with exit code 1 in 0.009771333 seconds [11:16:39 AM] 🟨⬜️🟨 Finished with exit code 1 in 0.00974475 seconds
1 parent 95915f2 commit 762f604

File tree

4 files changed

+472
-2
lines changed

4 files changed

+472
-2
lines changed

Example/HelloWorld/BUILD

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test")
22
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_interop_hint")
3+
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template_rule")
34

45

56
swift_library(
@@ -35,11 +36,38 @@ objc_library(
3536
aspect_hints = [":TodoObjCSupport_hint"],
3637
)
3738

39+
genrule(
40+
name = "GenerateDummySwiftFile",
41+
outs = [
42+
"GeneratedDummy.swift",
43+
],
44+
cmd = """
45+
cat > $@ << 'EOF'
46+
// This is a generated Swift file
47+
import Foundation
48+
49+
struct GeneratedDummy {
50+
static let message = "Hello from generated Swift file!"
51+
52+
static func greet() -> String {
53+
return message
54+
}
55+
}
56+
EOF
57+
""",
58+
)
59+
60+
swift_library(
61+
name = "GeneratedDummy",
62+
module_name = "GeneratedDummy",
63+
srcs = [":GenerateDummySwiftFile"],
64+
)
65+
3866
swift_library(
3967
name = "HelloWorldLib",
4068
module_name = "HelloWorldLib",
4169
srcs = glob(["HelloWorldLib/Sources/*.swift"]),
42-
deps = [":TodoModels", ":TodoObjCSupport"],
70+
deps = [":TodoModels", ":TodoObjCSupport", ":GeneratedDummy", ":ExpandedTemplate"],
4371
)
4472

4573
genrule(
@@ -64,5 +92,22 @@ ios_application(
6492
families = ["iphone", "ipad"],
6593
infoplists = ["Resources/Info.plist"],
6694
minimum_os_version = "17.0",
67-
deps = [":HelloWorldLib"],
95+
deps = [":HelloWorldLib", ":GeneratedDummy"],
96+
)
97+
98+
expand_template_rule(
99+
name = "ExpandTemplateSwiftFile",
100+
template = "template.swift.tpl",
101+
out = "ExpandedTemplate.swift",
102+
substitutions = {
103+
"{{CLASS_NAME}}": "ExpandedTemplate",
104+
"{{MESSAGE}}": "Hello from expanded template!",
105+
},
68106
)
107+
108+
swift_library(
109+
name = "ExpandedTemplate",
110+
module_name = "ExpandedTemplate",
111+
srcs = [":ExpandTemplateSwiftFile"],
112+
)
113+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This is a generated Swift file from template
2+
import Foundation
3+
4+
struct {{CLASS_NAME}} {
5+
static let message = "{{MESSAGE}}"
6+
7+
static func greet() -> String {
8+
return message
9+
}
10+
}

Example/MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ archive_override(
1818

1919

2020
bazel_dep(name = "apple_support", version = "1.22.1", repo_name = "build_bazel_apple_support")
21+
22+
bazel_dep(name = "aspect_bazel_lib", version = "2.9.3")

0 commit comments

Comments
 (0)