mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-29 03:32:42 +00:00
Bazel support: Add utf-8 to Windows build (#3962)
This commit is contained in:
parent
8e728044f6
commit
a4715c48b4
@ -1 +1 @@
|
|||||||
7.0.0
|
7.1.2
|
||||||
|
@ -8,6 +8,10 @@ cc_library(
|
|||||||
hdrs = glob([
|
hdrs = glob([
|
||||||
"include/fmt/*.h",
|
"include/fmt/*.h",
|
||||||
]),
|
]),
|
||||||
|
copts = select({
|
||||||
|
"@platforms//os:windows": ["-utf-8"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
includes = [
|
includes = [
|
||||||
"include",
|
"include",
|
||||||
],
|
],
|
||||||
|
@ -16,6 +16,8 @@ For instance, to use {fmt} add to your `MODULE.bazel` file:
|
|||||||
bazel_dep(name = "fmt", version = "10.2.1")
|
bazel_dep(name = "fmt", version = "10.2.1")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Live at head
|
||||||
|
|
||||||
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.:
|
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.:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -24,72 +26,3 @@ local_path_override(
|
|||||||
path = "../third_party/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:
|
|
||||||
|
|
||||||
```
|
|
||||||
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/.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/.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`, 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`.
|
|
||||||
|
@ -1 +1,2 @@
|
|||||||
workspace(name = "fmt")
|
# WORKSPACE marker file needed by Bazel
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user