Skip to content

Commit

Permalink
Extend Bazel build support to bzlmod (fmtlib#3792)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vertexwahn authored and happymonkey1 committed Apr 6, 2024
1 parent 6e05e76 commit 74f8c78
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
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}.

0 comments on commit 74f8c78

Please sign in to comment.