This repository template is for new Swift projects that want to use Bazel from the start. It provides the following conveniences to help bootstrap projects:
- Mockolo external dependency, built from source
swift_module
macro for creatingswift_library
targets, along with associated mockgen and test targets
- Select the
Use this template
option and create your new repository based on this template. - Update
WORKSPACE
for your needs - [Optional] Update
.bazelversion
with the version of Bazel you wish to use (if you're using bazelisk) - [Optional] Update
swift_module
definition for your needs
As a convenience, a Makefile
has been provided. It contains a single command that can be invoked to install bazelisk if needed:
make setup
To create new swift_module
targets, add a BUILD
file similar to the following (substituting your own values):
load("//infra/macros:swift_module.bzl", "swift_module")
swift_module(
name = "ExampleLibrary",
srcs = glob([
"source/**/*.swift",
], allow_empty = False),
test_srcs = glob([
"test/**/*.swift",
], allow_empty = False),
visibility = ["//visibility:public"],
)
xcodeproj
targets are created for all swift_module
by default. These projects can be generated via:
bazelisk run //:ExampleLibrary_Project
Note: Automatic project creation can be disabled by adding project_enabled = False
to the swift_module
definition.