Skip to content
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

Extend Bazel build support to bzlmod #3792

Merged
merged 1 commit into from
Jan 9, 2024
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
2 changes: 1 addition & 1 deletion support/bazel/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.2
7.0.0
2 changes: 1 addition & 1 deletion support/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cc_library(
name = "fmt",
srcs = [
#"src/fmt.cc", # No C++ module support
#"src/fmt.cc", # No C++ module support, yet in Bazel (https://github.com/bazelbuild/bazel/pull/19940)
"src/format.cc",
"src/os.cc",
],
Expand Down
4 changes: 4 additions & 0 deletions support/bazel/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module(
name = "fmt",
compatibility_level = 10,
)
33 changes: 27 additions & 6 deletions support/bazel/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
# Bazel support

To get [Bazel](https://bazel.build/) working with {fmt} you can copy the files `BUILD.bazel`, `WORKSPACE.bazel`, and `.bazelversion` from this folder (`support/bazel`) to the root folder of this project. This way {fmt} gets bazelized and can be used with Bazel (e.g. doing a `bazel build //...` on {fmt}).
To get [Bazel](https://bazel.build/) working with {fmt} you can copy the files `BUILD.bazel`,
`MODULE.bazel`, `WORKSPACE.bazel`, and `.bazelversion` from this folder (`support/bazel`) to the root folder of this project.
This way {fmt} gets bazelized and can be used with Bazel (e.g. doing a `bazel build //...` on {fmt}).

## Using {fmt} as a dependency

The following minimal example shows how to use {fmt} as a dependency within a Bazel project.
### Using Bzlmod

The [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt) provides support for {fmt}.

For instance, to use {fmt} add to your `MODULE.bazel` file:

```
bazel_dep(name = "fmt", version = "10.2.1")
```

For a live-at-head approach, you can copy the contents of this repository and move the Bazel-related build files to the root folder of this project as described above and make use of `local_path_override`, e.g.:

```
local_path_override(
module_name = "fmt",
path = "../third_party/fmt",
)
```

### WORKSPACE system

The following minimal example shows how to use {fmt} as a dependency within a Bazel project,
that uses the traditional, repository-focused WORKSPACE system.
Note that in the long term Bazel will only support Bzlmod.

The following file structure is assumed:

Expand Down Expand Up @@ -68,7 +93,3 @@ cc_binary(
The *BUILD* file defines a binary named `Demo` that has a dependency to {fmt}.

To execute the binary you can run `bazel run //:Demo`.

# Using Bzlmod

The [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt) also provides support for {fmt}.