This document provides a high-level description for the design of the rules and utilities provided by the Swift Bazel repository.
- Generate Bazel build files for Swift source files in a Bazel workspace.
- Allow a Bazel workspace to download and use external Swift packages in a Bazel workspace.
The implementation in this repository is separated into two parts:
- A Gazelle plugin.
- Bazel repository rules:
swift_package
andlocal_swift_package
.
The Gazelle plugin generates Bazel build and Starlark files for your project. The swift_package
repository rule generates Bazel build files for the external Swift packages.
The Gazelle plugin is implemented in
Go. It has two modes of
operation: update-repos
and update
.
The update-repos
mode
- Resolves the direct and transitive dependencies for the project using a
Package.swift
file. - Writes a
Package.resolved
file. - Writes a
swift_deps_index.json
file. - Writes
swift_package
declarations for the direct and transitive dependencies.
The update
mode
- Reads the
swift_deps_index.json
file. - Inspects the project looking for Swift source files.
- Identifies the Bazel packages that should contain Swift declarations.
- Writes the Swift declarations to Bazel build files.
The swift_package
repository rule downloads a Swift package and generates the Bazel build files
that will build the Swift targets and products.
The local_swift_package
repository rule references a Swift package directory on disk much like
Bazel's local_repository rule. Like
swift_package
, it too generates Bazel build files for the Swift package.
The repository rules are implemented using Bazel Starlark.