diff options
Diffstat (limited to 'src/fmt/support/bazel')
-rw-r--r-- | src/fmt/support/bazel/.bazelrc | 1 | ||||
-rw-r--r-- | src/fmt/support/bazel/.bazelversion | 1 | ||||
-rw-r--r-- | src/fmt/support/bazel/BUILD.bazel | 28 | ||||
-rw-r--r-- | src/fmt/support/bazel/README.md | 73 | ||||
-rw-r--r-- | src/fmt/support/bazel/WORKSPACE.bazel | 1 |
5 files changed, 104 insertions, 0 deletions
diff --git a/src/fmt/support/bazel/.bazelrc b/src/fmt/support/bazel/.bazelrc new file mode 100644 index 000000000..583cbbd22 --- /dev/null +++ b/src/fmt/support/bazel/.bazelrc @@ -0,0 +1 @@ +build --symlink_prefix=/ # Out of source build diff --git a/src/fmt/support/bazel/.bazelversion b/src/fmt/support/bazel/.bazelversion new file mode 100644 index 000000000..ac14c3dfa --- /dev/null +++ b/src/fmt/support/bazel/.bazelversion @@ -0,0 +1 @@ +5.1.1 diff --git a/src/fmt/support/bazel/BUILD.bazel b/src/fmt/support/bazel/BUILD.bazel new file mode 100644 index 000000000..085765890 --- /dev/null +++ b/src/fmt/support/bazel/BUILD.bazel @@ -0,0 +1,28 @@ +cc_library( + name = "fmt", + srcs = [ + #"src/fmt.cc", # No C++ module support + "src/format.cc", + "src/os.cc", + ], + hdrs = [ + "include/fmt/args.h", + "include/fmt/chrono.h", + "include/fmt/color.h", + "include/fmt/compile.h", + "include/fmt/core.h", + "include/fmt/format-inl.h", + "include/fmt/format.h", + "include/fmt/os.h", + "include/fmt/ostream.h", + "include/fmt/printf.h", + "include/fmt/ranges.h", + "include/fmt/std.h", + "include/fmt/xchar.h", + ], + includes = [ + "include", + ], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) diff --git a/src/fmt/support/bazel/README.md b/src/fmt/support/bazel/README.md new file mode 100644 index 000000000..44af620c1 --- /dev/null +++ b/src/fmt/support/bazel/README.md @@ -0,0 +1,73 @@ +# Bazel support + +To get [Bazel](https://bazel.build/) working with {fmt} you can copy the files `BUILD.bazel`, `WORKSPACE.bazel`, `.bazelrc`, 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. + +The following file structure is assumed: + +``` +example +├── BUILD.bazel +├── main.cpp +└── WORKSPACE.bazel +``` + +*main.cpp*: + +```c++ +#include "fmt/core.h" + +int main() { + fmt::print("The answer is {}\n", 42); +} +``` + +The expected output of this example is `The answer is 42`. + +*WORKSPACE.bazel*: + +```python +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "fmt", + branch = "master", + remote = "https://github.com/fmtlib/fmt", + patch_cmds = [ + "mv support/bazel/.bazelrc .bazelrc", + "mv support/bazel/.bazelversion .bazelversion", + "mv support/bazel/BUILD.bazel BUILD.bazel", + "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel", + ], + # Windows-related patch commands are only needed in the case MSYS2 is not installed. + # More details about the installation process of MSYS2 on Windows systems can be found here: + # https://docs.bazel.build/versions/main/install-windows.html#installing-compilers-and-language-runtimes + # Even if MSYS2 is installed the Windows related patch commands can still be used. + patch_cmds_win = [ + "Move-Item -Path support/bazel/.bazelrc -Destination .bazelrc", + "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion", + "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel", + "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel", + ], +) +``` + +In the *WORKSPACE* file, the {fmt} GitHub repository is fetched. Using the attribute `patch_cmds` the files `BUILD.bazel`, `WORKSPACE.bazel`, `.bazelrc`, and `.bazelversion` are moved to the root of the {fmt} repository. This way the {fmt} repository is recognized as a bazelized workspace. + +*BUILD.bazel*: + +```python +cc_binary( + name = "Demo", + srcs = ["main.cpp"], + deps = ["@fmt"], +) +``` + +The *BUILD* file defines a binary named `Demo` that has a dependency to {fmt}. + +To execute the binary you can run `bazel run //:Demo`. + diff --git a/src/fmt/support/bazel/WORKSPACE.bazel b/src/fmt/support/bazel/WORKSPACE.bazel new file mode 100644 index 000000000..5be77811b --- /dev/null +++ b/src/fmt/support/bazel/WORKSPACE.bazel @@ -0,0 +1 @@ +workspace(name = "fmt") |