Skip to content

Commit 0cb1241

Browse files
authored
Improve Bazel support: Switch to Bzlmod (nlohmann#4584)
* Improve Bazel support: Switch to Bzlmod Signed-off-by: Vertexwahn <[email protected]> * Update documentation Signed-off-by: Vertexwahn <[email protected]> * Fix spelling Signed-off-by: Vertexwahn <[email protected]> * Fix snippet filename error Signed-off-by: Vertexwahn <[email protected]> --------- Signed-off-by: Vertexwahn <[email protected]>
1 parent 2e50d5b commit 0cb1241

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@
4444
/.build
4545

4646
/tools/astyle/venv/
47+
48+
# Bazel-related
49+
MODULE.bazel.lock

BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2+
load("@rules_license//rules:license.bzl", "license")
3+
4+
package(
5+
default_applicable_licenses = [":license"],
6+
)
7+
8+
exports_files([
9+
"LICENSE.MIT",
10+
])
11+
12+
license(
13+
name = "license",
14+
license_kinds = ["@rules_license//licenses/spdx:MIT"],
15+
license_text = "LICENSE.MIT",
16+
)
17+
118
cc_library(
219
name = "json",
320
hdrs = [
@@ -40,6 +57,7 @@ cc_library(
4057
"include/nlohmann/detail/output/serializer.hpp",
4158
"include/nlohmann/detail/string_concat.hpp",
4259
"include/nlohmann/detail/string_escape.hpp",
60+
"include/nlohmann/detail/string_utils.hpp",
4361
"include/nlohmann/detail/value_t.hpp",
4462
"include/nlohmann/json.hpp",
4563
"include/nlohmann/json_fwd.hpp",
@@ -50,3 +68,12 @@ cc_library(
5068
includes = ["include"],
5169
visibility = ["//visibility:public"],
5270
)
71+
72+
cc_library(
73+
name = "singleheader-json",
74+
hdrs = [
75+
"single_include/nlohmann/json.hpp",
76+
],
77+
includes = ["single_include"],
78+
visibility = ["//visibility:public"],
79+
)

MODULE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module(
2+
name = "nlohmann_json",
3+
compatibility_level = 1,
4+
)
5+
6+
bazel_dep(name = "rules_cc", version = "0.0.17")
7+
bazel_dep(name = "rules_license", version = "1.0.0")

WORKSPACE.bazel

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1")

docs/mkdocs/docs/integration/bazel/WORKSPACE

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/mkdocs/docs/integration/package_managers.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,14 @@ using the subproject directly.
137137

138138
!!! abstract "Summary"
139139

140-
use `http_archive`, `git_repository`, or `local_repository`
140+
use `bazel_dep`, `git_override`, or `local_path_override`
141141

142-
- :octicons-tag-24: Any version, as version is specified in `WORKSPACE` file
142+
- :octicons-tag-24: Any version, that is available via [Bazel Central Registry](https://registry.bazel.build/modules/nlohmann_json)
143143
- :octicons-file-24: File issues at the [library issue tracker](https://github.com/nlohmann/json/issues)
144144
- :octicons-question-24: [Bazel website](https://bazel.build)
145145

146-
This repository provides a [Bazel](https://bazel.build/) `WORKSPACE.bazel` and a corresponding `BUILD.bazel` file. Therefore, this
147-
repository can be referenced by workspace rules such as `http_archive`, `git_repository`, or `local_repository` from
148-
other Bazel workspaces. To use the library you only need to depend on the target `@nlohmann_json//:json` (e.g., via
149-
`deps` attribute).
146+
This repository provides a [Bazel](https://bazel.build/) `MODULE.bazel` and a corresponding `BUILD.bazel` file. Therefore, this
147+
repository can be referenced within a `MODULE.bazel` by rules such as `archive_override`, `git_override`, or `local_path_override`. To use the library you need to depend on the target `@nlohmann_json//:json` (i.e., via `deps` attribute).
150148

151149
??? example
152150

@@ -157,7 +155,7 @@ other Bazel workspaces. To use the library you only need to depend on the target
157155
```
158156

159157
```ini title="WORKSPACE"
160-
--8<-- "integration/bazel/WORKSPACE"
158+
--8<-- "integration/bazel/MODULE.bazel"
161159
```
162160

163161
```cpp title="example.cpp"

0 commit comments

Comments
 (0)