Mercurial > minori
comparison dep/fmt/support/bazel/README.md @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 20 Jun 2024 05:56:06 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 342:adb79bdde329 | 343:1faa72660932 |
|---|---|
| 1 # Bazel support | |
| 2 | |
| 3 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}). | |
| 4 | |
| 5 ## Using {fmt} as a dependency | |
| 6 | |
| 7 The following minimal example shows how to use {fmt} as a dependency within a Bazel project. | |
| 8 | |
| 9 The following file structure is assumed: | |
| 10 | |
| 11 ``` | |
| 12 example | |
| 13 ├── BUILD.bazel | |
| 14 ├── main.cpp | |
| 15 └── WORKSPACE.bazel | |
| 16 ``` | |
| 17 | |
| 18 *main.cpp*: | |
| 19 | |
| 20 ```c++ | |
| 21 #include "fmt/core.h" | |
| 22 | |
| 23 int main() { | |
| 24 fmt::print("The answer is {}\n", 42); | |
| 25 } | |
| 26 ``` | |
| 27 | |
| 28 The expected output of this example is `The answer is 42`. | |
| 29 | |
| 30 *WORKSPACE.bazel*: | |
| 31 | |
| 32 ```python | |
| 33 load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | |
| 34 | |
| 35 git_repository( | |
| 36 name = "fmt", | |
| 37 branch = "master", | |
| 38 remote = "https://github.com/fmtlib/fmt", | |
| 39 patch_cmds = [ | |
| 40 "mv support/bazel/.bazelversion .bazelversion", | |
| 41 "mv support/bazel/BUILD.bazel BUILD.bazel", | |
| 42 "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel", | |
| 43 ], | |
| 44 # Windows-related patch commands are only needed in the case MSYS2 is not installed. | |
| 45 # More details about the installation process of MSYS2 on Windows systems can be found here: | |
| 46 # https://docs.bazel.build/versions/main/install-windows.html#installing-compilers-and-language-runtimes | |
| 47 # Even if MSYS2 is installed the Windows related patch commands can still be used. | |
| 48 patch_cmds_win = [ | |
| 49 "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion", | |
| 50 "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel", | |
| 51 "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel", | |
| 52 ], | |
| 53 ) | |
| 54 ``` | |
| 55 | |
| 56 In the *WORKSPACE* file, the {fmt} GitHub repository is fetched. Using the attribute `patch_cmds` the files `BUILD.bazel`, `WORKSPACE.bazel`, and `.bazelversion` are moved to the root of the {fmt} repository. This way the {fmt} repository is recognized as a bazelized workspace. | |
| 57 | |
| 58 *BUILD.bazel*: | |
| 59 | |
| 60 ```python | |
| 61 cc_binary( | |
| 62 name = "Demo", | |
| 63 srcs = ["main.cpp"], | |
| 64 deps = ["@fmt"], | |
| 65 ) | |
| 66 ``` | |
| 67 | |
| 68 The *BUILD* file defines a binary named `Demo` that has a dependency to {fmt}. | |
| 69 | |
| 70 To execute the binary you can run `bazel run //:Demo`. | |
| 71 | |
| 72 # Using Bzlmod | |
| 73 | |
| 74 The [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt) also provides support for {fmt}. |
