This repository contains a Gazelle plugin used to generate rules_swift targets based upon your Swift source code.
The following provides a quick introduction on how to set up and use the features in this repository. These instructions assume that you are using Bazel modules to load your external dependencies. If you are using Bazel's legacy external dependency management, we recommend using Bazel's hybrid mode, then follow the steps in this quickstart guide.
1. Configure your MODULE.bazel to use swift_gazelle_plugin.
Add a dependency on swift_gazelle_plugin.
bazel_dep(name = "swift_gazelle_plugin", version = "0.2.2")Add the following to the BUILD.bazel file at the root of your workspace.
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")
# This declaration builds a Gazelle binary that incorporates all of the Gazelle
# plugins for the languages that you use in your workspace. In this example, we
# are only listing the Gazelle plugin for Swift from swift_gazelle_plugin.
gazelle_binary(
name = "gazelle_bin",
languages = [
"@swift_gazelle_plugin//gazelle",
],
)
# This target updates the Bazel build files for your project. Run this target
# whenever you add or remove source files from your project.
gazelle(
name = "update_build_files",
gazelle = ":gazelle_bin",
)Generate/update the Bazel build files for your project by running the following:
bazel run //:update_build_filesBuild and test your project.
bazel test //...- The
MODULE.bazelcontains the declarations for your external dependencies.
You are ready to start coding.
The following are a few tips to consider as you work with your repository:
- When you add or remove source files, run
bazel run //:update_build_files. This will create/update the Bazel build files in your project. It is designed to be fast and unobtrusive. - If things do not appear to be working properly, run the following:
bazel run //:update_build_files
- Do yourself a favor and create a Bazel target (e.g.,
//:tidy) that runs your repository maintenance targets (e.g.,//:update_build_files, formatting utilities) in the proper order. If you are looking for an easy way to set this up, check out the//:tidydeclaration in this repository and the documentation for the tidy macro.