Setup for inclusion in the Bazel Central Registry
By adding a MODULE.bazel file, this library becomes usable with Bazel's new external dependency management system Bzlmod. The new tests are run when a new version is included in the Bazel Central Registry and verify that the basic functionality works with the provided Bazel setup. See: https://bazel.build/build/bzlmod
This commit is contained in:
parent
a3e6e26dc8
commit
cec4630c2d
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@
|
||||
|
||||
# build directories (vscode-cmake-tools, user-defined, ...)
|
||||
/build*/
|
||||
bazel-*
|
||||
|
||||
# fuzzers
|
||||
/tests/corpus_*
|
||||
|
||||
5
MODULE.bazel
Normal file
5
MODULE.bazel
Normal file
@ -0,0 +1,5 @@
|
||||
module(
|
||||
name = "nlohmann_json",
|
||||
compatibility_level = 1,
|
||||
version = "3.11.2",
|
||||
)
|
||||
1
tests/bazel/.bazelrc
Normal file
1
tests/bazel/.bazelrc
Normal file
@ -0,0 +1 @@
|
||||
common --enable_bzlmod
|
||||
1
tests/bazel/.bazelversion
Normal file
1
tests/bazel/.bazelversion
Normal file
@ -0,0 +1 @@
|
||||
6.0.0rc1
|
||||
5
tests/bazel/BUILD.bazel
Normal file
5
tests/bazel/BUILD.bazel
Normal file
@ -0,0 +1,5 @@
|
||||
cc_test(
|
||||
name = "json_example_test",
|
||||
srcs = ["json_example_test.cpp"],
|
||||
deps = ["@json"],
|
||||
)
|
||||
5
tests/bazel/MODULE.bazel
Normal file
5
tests/bazel/MODULE.bazel
Normal file
@ -0,0 +1,5 @@
|
||||
bazel_dep(name = "nlohmann_json", repo_name = "json")
|
||||
local_path_override(
|
||||
module_name = "nlohmann_json",
|
||||
path = "../.."
|
||||
)
|
||||
0
tests/bazel/WORKSPACE.bazel
Normal file
0
tests/bazel/WORKSPACE.bazel
Normal file
2
tests/bazel/WORKSPACE.bzlmod
Normal file
2
tests/bazel/WORKSPACE.bzlmod
Normal file
@ -0,0 +1,2 @@
|
||||
# The presence of this file ensures that Bazel ignores WORKSPACE.bazel and
|
||||
# does not implicitly add any dependency declarations.
|
||||
24
tests/bazel/json_example_test.cpp
Normal file
24
tests/bazel/json_example_test.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
nlohmann::json j;
|
||||
j["pi"] = 3.141;
|
||||
j["happy"] = true;
|
||||
j["name"] = "Niels";
|
||||
j["nothing"] = nullptr;
|
||||
j["answer"]["everything"] = 42;
|
||||
j["list"] = {1, 0, 2};
|
||||
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
|
||||
|
||||
std::string s = j.dump();
|
||||
if (s != R"({"answer":{"everything":42},"happy":true,"list":[1,0,2],"name":"Niels","nothing":null,"object":{"currency":"USD","value":42.99},"pi":3.141})")
|
||||
{
|
||||
std::cerr << "Unexpected JSON serialization: " << s << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user