diff --git a/support/bazel/.bazelversion b/support/bazel/.bazelversion index 5e3254243a3b..66ce77b7ead5 100644 --- a/support/bazel/.bazelversion +++ b/support/bazel/.bazelversion @@ -1 +1 @@ -6.1.2 +7.0.0 diff --git a/support/bazel/BUILD.bazel b/support/bazel/BUILD.bazel index 29f639becd5e..000b5a1dfa82 100644 --- a/support/bazel/BUILD.bazel +++ b/support/bazel/BUILD.bazel @@ -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", ], diff --git a/support/bazel/MODULE.bazel b/support/bazel/MODULE.bazel new file mode 100644 index 000000000000..b01550f8d9ae --- /dev/null +++ b/support/bazel/MODULE.bazel @@ -0,0 +1,4 @@ +module( + name = "fmt", + compatibility_level = 10, +) diff --git a/support/bazel/README.md b/support/bazel/README.md index 4c29febb1eba..dc4756b90f98 100644 --- a/support/bazel/README.md +++ b/support/bazel/README.md @@ -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: @@ -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}.