From 0cb1241d5edce3698517c2b0b996f9a295c2c3c3 Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Tue, 7 Jan 2025 18:47:51 +0100 Subject: [PATCH] Improve Bazel support: Switch to Bzlmod (#4584) * Improve Bazel support: Switch to Bzlmod Signed-off-by: Vertexwahn * Update documentation Signed-off-by: Vertexwahn * Fix spelling Signed-off-by: Vertexwahn * Fix snippet filename error Signed-off-by: Vertexwahn --------- Signed-off-by: Vertexwahn --- .gitignore | 3 +++ BUILD.bazel | 27 +++++++++++++++++++ MODULE.bazel | 7 +++++ WORKSPACE.bazel | 1 - .../docs/integration/bazel/MODULE.bazel | 1 + docs/mkdocs/docs/integration/bazel/WORKSPACE | 7 ----- .../docs/integration/package_managers.md | 12 ++++----- 7 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 MODULE.bazel delete mode 100644 WORKSPACE.bazel create mode 100644 docs/mkdocs/docs/integration/bazel/MODULE.bazel delete mode 100644 docs/mkdocs/docs/integration/bazel/WORKSPACE diff --git a/.gitignore b/.gitignore index e3339eac8..fac47a7b9 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ /.build /tools/astyle/venv/ + +# Bazel-related +MODULE.bazel.lock diff --git a/BUILD.bazel b/BUILD.bazel index 354460d27..afd843958 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,20 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_license//rules:license.bzl", "license") + +package( + default_applicable_licenses = [":license"], +) + +exports_files([ + "LICENSE.MIT", +]) + +license( + name = "license", + license_kinds = ["@rules_license//licenses/spdx:MIT"], + license_text = "LICENSE.MIT", +) + cc_library( name = "json", hdrs = [ @@ -40,6 +57,7 @@ cc_library( "include/nlohmann/detail/output/serializer.hpp", "include/nlohmann/detail/string_concat.hpp", "include/nlohmann/detail/string_escape.hpp", + "include/nlohmann/detail/string_utils.hpp", "include/nlohmann/detail/value_t.hpp", "include/nlohmann/json.hpp", "include/nlohmann/json_fwd.hpp", @@ -50,3 +68,12 @@ cc_library( includes = ["include"], visibility = ["//visibility:public"], ) + +cc_library( + name = "singleheader-json", + hdrs = [ + "single_include/nlohmann/json.hpp", + ], + includes = ["single_include"], + visibility = ["//visibility:public"], +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..51754e7a3 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,7 @@ +module( + name = "nlohmann_json", + compatibility_level = 1, +) + +bazel_dep(name = "rules_cc", version = "0.0.17") +bazel_dep(name = "rules_license", version = "1.0.0") diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel deleted file mode 100644 index 2b2ae9dba..000000000 --- a/WORKSPACE.bazel +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "nlohmann_json") diff --git a/docs/mkdocs/docs/integration/bazel/MODULE.bazel b/docs/mkdocs/docs/integration/bazel/MODULE.bazel new file mode 100644 index 000000000..ba902be27 --- /dev/null +++ b/docs/mkdocs/docs/integration/bazel/MODULE.bazel @@ -0,0 +1 @@ +bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1") diff --git a/docs/mkdocs/docs/integration/bazel/WORKSPACE b/docs/mkdocs/docs/integration/bazel/WORKSPACE deleted file mode 100644 index 57ef2e10c..000000000 --- a/docs/mkdocs/docs/integration/bazel/WORKSPACE +++ /dev/null @@ -1,7 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "nlohmann_json", - urls = ["https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.tar.gz"], - strip_prefix = "json-3.11.3", -) diff --git a/docs/mkdocs/docs/integration/package_managers.md b/docs/mkdocs/docs/integration/package_managers.md index 964e8f8bb..0bc6870fa 100644 --- a/docs/mkdocs/docs/integration/package_managers.md +++ b/docs/mkdocs/docs/integration/package_managers.md @@ -137,16 +137,14 @@ using the subproject directly. !!! abstract "Summary" - use `http_archive`, `git_repository`, or `local_repository` + use `bazel_dep`, `git_override`, or `local_path_override` - - :octicons-tag-24: Any version, as version is specified in `WORKSPACE` file + - :octicons-tag-24: Any version, that is available via [Bazel Central Registry](https://registry.bazel.build/modules/nlohmann_json) - :octicons-file-24: File issues at the [library issue tracker](https://github.com/nlohmann/json/issues) - :octicons-question-24: [Bazel website](https://bazel.build) -This repository provides a [Bazel](https://bazel.build/) `WORKSPACE.bazel` and a corresponding `BUILD.bazel` file. Therefore, this -repository can be referenced by workspace rules such as `http_archive`, `git_repository`, or `local_repository` from -other Bazel workspaces. To use the library you only need to depend on the target `@nlohmann_json//:json` (e.g., via -`deps` attribute). +This repository provides a [Bazel](https://bazel.build/) `MODULE.bazel` and a corresponding `BUILD.bazel` file. Therefore, this +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). ??? example @@ -157,7 +155,7 @@ other Bazel workspaces. To use the library you only need to depend on the target ``` ```ini title="WORKSPACE" - --8<-- "integration/bazel/WORKSPACE" + --8<-- "integration/bazel/MODULE.bazel" ``` ```cpp title="example.cpp"