Skip to content

[bazel] Update Bazel README with Bzlmod & WORKSPACE examples #2918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2024
Merged
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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@ Start contributing to SwiftSyntax see [this guide](CONTRIBUTING.md) for more inf
## Bazel

SwiftSyntax provides an experimental [Bazel](https://bazel.build) build configuration, maintained by Keith Smiley.
To use it you can pull the source archive from the relevant release tag
into your `WORKSPACE` and depend on the libraries you need from the
To use it, you can pull the source archive from the relevant release tag
into your `MODULE.bazel` file (preferred and recommended) with `bazel_dep`. Bzlmod support was added starting release of `509.0.0` and above. All available versions can be found in the [Bazel Central Registry](https://registry.bazel.build/modules/swift-syntax)

```python3
bazel_dep(name = "swift-syntax", version = "600.0.1")
```

You can also pull source archive with `WORKSPACE` but note that it is preferred to use `MODULE.bazel`. To use `WORKSPACE` and swift-syntax, you can use `http_archive` as such

```python3
http_archive(
name = "SwiftSyntax",
sha256 = "f070fd44db9b33f430fd5b5d2700f1e2001c0028711859600e80cc975074fab0",
strip_prefix = "swift-syntax-509.1.0",
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.1.0.tar.gz",
)
```

and depend on the libraries you need from the
[`BUILD.bazel`](BUILD.bazel) file. Each library also has an associated
`Library_opt` target (such as `SwiftSyntax_opt`) which forces
SwiftSyntax to always build with optimizations enabled. This may help
Expand Down