Skip to content

Improve Bazel support: Switch to Bzlmod - #4584

Merged
nlohmann merged 4 commits into
nlohmann:developfrom
Vertexwahn:bazel-support
Jan 7, 2025
Merged

nlohmann merged 4 commits into
nlohmann:developfrom
Vertexwahn:bazel-support

Conversation

@Vertexwahn

@Vertexwahn Vertexwahn commented Jan 6, 2025 •

Copy link
Copy Markdown
Contributor

This PR only affects the Bazel build. Switched from traditional WORKSPACE approach to Bzlmod.

Background: Due to the shortcomings of WORKSPACE, Bzlmod is going to replace the legacy WORKSPACE system. The WORKSPACE file will be disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025). Therefore, this PR.

Signed-off-by: Vertexwahn <julian.amann@tum.de>
@coveralls

coveralls commented Jan 6, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 99.639%. remained the same
when pulling d324192 on Vertexwahn:bazel-support
into 60c4875 on nlohmann:develop.

Comment thread docs/mkdocs/docs/integration/bazel/WORKSPACE
Comment thread WORKSPACE.bazel
Signed-off-by: Vertexwahn <julian.amann@tum.de>
Comment thread docs/mkdocs/docs/integration/package_managers.md Outdated
Comment thread docs/mkdocs/docs/integration/package_managers.md Outdated
Signed-off-by: Vertexwahn <julian.amann@tum.de>
Signed-off-by: Vertexwahn <julian.amann@tum.de>
@nlohmann

nlohmann commented Jan 7, 2025

Copy link
Copy Markdown
Owner

One question: In #4560, I added an overview for the package managers like this:

image

Most packages have a single string ("package", "formula", "port") to quickly communicate what to do for "their" package manager. Is there something like this for Bazel?

@Vertexwahn

Copy link
Copy Markdown
Contributor Author

Yes three is "nlohmann_json" in the Bazel Central Registry https://registry.bazel.build/modules/nlohmann_json -> so add nlohmann_json

@nlohmann nlohmann added this to the Release 3.11.4 milestone Jan 7, 2025

@nlohmann nlohmann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann
nlohmann merged commit 0cb1241 into nlohmann:develop Jan 7, 2025
@nlohmann

nlohmann commented Jan 7, 2025

Copy link
Copy Markdown
Owner

Thanks!

nlohmann added a commit that referenced this pull request Jan 7, 2025
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
codenut pushed a commit to codenut/json that referenced this pull request Jan 9, 2025
* Improve Bazel support: Switch to Bzlmod

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Update documentation

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Fix spelling

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Fix snippet filename error

Signed-off-by: Vertexwahn <julian.amann@tum.de>

---------

Signed-off-by: Vertexwahn <julian.amann@tum.de>
slowriot pushed a commit to slowriot/json that referenced this pull request Jan 10, 2025
* Improve Bazel support: Switch to Bzlmod

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Update documentation

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Fix spelling

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Fix snippet filename error

Signed-off-by: Vertexwahn <julian.amann@tum.de>

---------

Signed-off-by: Vertexwahn <julian.amann@tum.de>
nlohmann added a commit that referenced this pull request Sep 24, 2026
* Add missing headers to BUILD.bazel and make its generator reproduce it

The "json" cc_library did not list three headers that the library
includes:

- detail/meta/logic.hpp (added in #5016, included by from_json.hpp)
- detail/input/number_parse.hpp (added in #5283, included by lexer.hpp)
- detail/input/string_scan.hpp (added in #5283, included by lexer.hpp
  and serializer.hpp)

Bazel's sandbox only exposes declared headers, so any target depending
on @nlohmann_json//:json and including <nlohmann/json.hpp> failed with
"'nlohmann/detail/meta/logic.hpp' file not found".

The file could not simply be regenerated, because the generator behind
"make BUILD.bazel" was stale: it wrote only the "json" cc_library and
dropped the load() statements, the license block, and the
"singleheader-json" target that were added by hand in #4584. The
generator now emits the complete file, so its output differs from the
previous BUILD.bazel only by the three headers. It also resolves the
glob against the project root instead of the working directory and
sorts the list explicitly.

"make BUILD.bazel" is now phony: in a fresh checkout, BUILD.bazel is
not older than the headers, so make considered it up to date, and a
removed header would never trigger a rebuild. "make check-amalgamation"
also checks that BUILD.bazel is up to date.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Check in CI that BUILD.bazel is up to date

The "Check amalgamation" workflow now also regenerates BUILD.bazel, so a
pull request that adds, renames, or removes a header without updating
the Bazel header list fails, and the attached amalgamation.patch
contains the fix. The failure comment and the contribution guidelines
mention the new check, and the comment now links to the existing
"Amalgamate the source code" section instead of the "Files to change"
anchor that was removed in #4560.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants