Skip to content
Merged
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
49 changes: 47 additions & 2 deletions Example/HelloWorld/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_interop_hint")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template_rule")


swift_library(
Expand Down Expand Up @@ -35,11 +36,38 @@ objc_library(
aspect_hints = [":TodoObjCSupport_hint"],
)

genrule(
name = "GenerateDummySwiftFile",
outs = [
"GeneratedDummy.swift",
],
cmd = """
cat > $@ << 'EOF'
// This is a generated Swift file
import Foundation

struct GeneratedDummy {
static let message = "Hello from generated Swift file!"

static func greet() -> String {
return message
}
}
EOF
""",
)

swift_library(
name = "GeneratedDummy",
module_name = "GeneratedDummy",
srcs = [":GenerateDummySwiftFile"],
)

swift_library(
name = "HelloWorldLib",
module_name = "HelloWorldLib",
srcs = glob(["HelloWorldLib/Sources/*.swift"]),
deps = [":TodoModels", ":TodoObjCSupport"],
deps = [":TodoModels", ":TodoObjCSupport", ":GeneratedDummy", ":ExpandedTemplate"],
)

genrule(
Expand All @@ -64,5 +92,22 @@ ios_application(
families = ["iphone", "ipad"],
infoplists = ["Resources/Info.plist"],
minimum_os_version = "17.0",
deps = [":HelloWorldLib"],
deps = [":HelloWorldLib", ":GeneratedDummy"],
)

expand_template_rule(
name = "ExpandTemplateSwiftFile",
template = "template.swift.tpl",
out = "ExpandedTemplate.swift",
substitutions = {
"{{CLASS_NAME}}": "ExpandedTemplate",
"{{MESSAGE}}": "Hello from expanded template!",
},
)

swift_library(
name = "ExpandedTemplate",
module_name = "ExpandedTemplate",
srcs = [":ExpandTemplateSwiftFile"],
)

10 changes: 10 additions & 0 deletions Example/HelloWorld/template.swift.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This is a generated Swift file from template
import Foundation

struct {{CLASS_NAME}} {
static let message = "{{MESSAGE}}"

static func greet() -> String {
return message
}
}
2 changes: 2 additions & 0 deletions Example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ archive_override(


bazel_dep(name = "apple_support", version = "1.22.1", repo_name = "build_bazel_apple_support")

bazel_dep(name = "aspect_bazel_lib", version = "2.9.3")
Loading