Skip to content

Commit ab5afff

Browse files
committed
Update fastjson module
1 parent 1601689 commit ab5afff

File tree

10 files changed

+201
-3
lines changed

10 files changed

+201
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Module: fastjson
3+
Purpose: Provides the fastjson library compileable as a Bazel target. Includes unit testing through Bazel
4+
Notes: boost.property_tree is used for the speed test unit test. saru is used as the unit testing framework
5+
"""
6+
7+
module(
8+
name = "fastjson",
9+
version = "0.0.0-20120701063936-485f994a61a6.bcr.1",
10+
bazel_compatibility = [">=7.2.1"], # need support for "overlay" directory
11+
compatibility_level = 1,
12+
)
13+
14+
bazel_dep(name = "rules_cc", version = "0.2.4")
15+
bazel_dep(name = "platforms", version = "1.0.0")
16+
17+
bazel_dep(name = "boost.property_tree", version = "1.89.0.bcr.1", dev_dependency = True)
18+
bazel_dep(name = "saru", version = "0.0.0-20130617092049-c11c375fefd7", dev_dependency = True)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "fastjson",
5+
srcs = glob(["src/*.cpp"]),
6+
hdrs = glob(["include/**/*.h"]),
7+
copts = select({
8+
"@platforms//os:windows": [],
9+
"//conditions:default": [
10+
"-Wno-unused-variable", # Ignore unused element - Don't pollute downstream users
11+
],
12+
}),
13+
includes = ["include"], # Expose for import without include prefix
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
# This must be defined in top level BUILD as we can't access files above the target(s) file
18+
cc_library(
19+
name = "fastjson-test-srcs",
20+
hdrs = glob(["src/*.cpp"]),
21+
includes = ["include/fastjson"], # Tests need access to includes without fastjson folder prefix
22+
visibility = ["//tests:__pkg__"],
23+
)

modules/fastjson/0.0.0-20120701063936-485f994a61a6.bcr.1/overlay/examples/BUILD.bazel

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2+
3+
cc_binary(
4+
name = "address_book",
5+
srcs = ["address_book.cpp"],
6+
copts = [
7+
"-g", # Debug symbols
8+
"-Wall", # All warnings
9+
],
10+
data = ["book.json"], # Include the JSON file as a runtime dependency
11+
deps = ["//:fastjson"],
12+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
2+
load(":tools.bzl", "test_set")
3+
4+
TEST_COPTS = select({
5+
"@platforms//os:windows": [],
6+
"//conditions:default": [
7+
"-g", # Debug symbols
8+
"-Wall", # All warnings
9+
],
10+
})
11+
12+
DEPS = [
13+
"//:fastjson",
14+
"//:fastjson-test-srcs",
15+
"@saru",
16+
]
17+
18+
test_suite(
19+
name = "all_tests",
20+
tests = test_set(
21+
copts = TEST_COPTS,
22+
test_files = glob(
23+
["**/*.cpp"],
24+
exclude = ["misc/speed_test_boost.cpp"],
25+
),
26+
deps = DEPS,
27+
) + [":speed_test"],
28+
)
29+
30+
cc_test(
31+
name = "speed_test",
32+
size = "medium",
33+
srcs = ["misc/speed_test_boost.cpp"],
34+
copts = TEST_COPTS,
35+
deps = DEPS + [
36+
"@boost.property_tree",
37+
],
38+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Tool for generating C++ test targets efficiently using Bazel rules.
2+
"""
3+
4+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
5+
6+
def test_set(
7+
test_files = None,
8+
size = "small",
9+
srcs = [],
10+
file_extensions = ".cpp",
11+
**kwargs):
12+
"""Creates C++ test targets from a list of test files.
13+
14+
Args:
15+
test_files: List of test file paths to process. Defaults to None.
16+
size: Test size parameter for cc_test rule. Defaults to "small".
17+
srcs: Additional source files to include in all tests. Defaults to empty list.
18+
file_extensions: Expected extension of test files. Defaults to ".cpp".
19+
**kwargs: Additional arguments to pass to cc_test rule.
20+
21+
Returns:
22+
List of test target names (e.g., [":test1", ":test2"]).
23+
24+
Note:
25+
Only files ending with the specified file_extensions are processed.
26+
Each test target is created with the filename (without extension) as its name.
27+
"""
28+
test_targets = []
29+
30+
# Process positive tests
31+
for file in test_files:
32+
if not file.endswith(file_extensions):
33+
continue
34+
name = file[:-len(file_extensions)]
35+
target = ":" + name
36+
cc_test(
37+
name = name,
38+
size = size,
39+
srcs = srcs + [file],
40+
**kwargs
41+
)
42+
test_targets.append(target)
43+
44+
return test_targets
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git a/tests/misc/speed_test_boost.cpp b/tests/misc/speed_test_boost.cpp
2+
index 490cab5..11df3e2 100644
3+
--- a/tests/misc/speed_test_boost.cpp
4+
+++ b/tests/misc/speed_test_boost.cpp
5+
@@ -111 +111 @@ int main()
6+
- boost::property_tree::write_json_compact( ssout, n );
7+
+ boost::property_tree::write_json( ssout, n );
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
matrix:
2+
platform:
3+
- debian10
4+
- ubuntu2004
5+
- macos
6+
- macos_arm64
7+
- windows
8+
bazel:
9+
- 8.x
10+
- 7.x
11+
- 6.x
12+
tasks:
13+
verify_targets:
14+
name: Verify build targets
15+
platform: ${{ platform }}
16+
bazel: ${{ bazel }}
17+
build_targets:
18+
- "@fastjson//:fastjson"
19+
20+
bcr_test_module:
21+
module_path: "tests"
22+
matrix:
23+
platform:
24+
- debian10
25+
- ubuntu2004
26+
- macos
27+
- macos_arm64
28+
- windows
29+
bazel:
30+
- 8.x
31+
- 7.x
32+
tasks:
33+
run_test_module:
34+
name: "Run test module"
35+
platform: ${{ platform }}
36+
bazel: ${{ bazel }}
37+
test_targets:
38+
- "//tests:all_tests"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"url": "https://github.com/mikeando/fastjson/archive/485f994.tar.gz",
3+
"integrity": "sha256-phIJMsU4I0+lq+i1hIY+efTSKt5ik9fFVr1NvvJlUgM=",
4+
"patch_strip": 1,
5+
"strip_prefix": "fastjson-485f994a61a64ac73fa6a40d4d639b99b463563b",
6+
"patches": {
7+
"boost_property_tree_compact.patch": "sha256-TXYBKEYstPVgXM9gb8WS+h2ucd6aniFQJC2f1oiDvRo="
8+
},
9+
"overlay": {
10+
"BUILD.bazel": "sha256-eH/vpiHShYq5FDEdUGN9kPeM172uCPIPnPNQJRuvNdU=",
11+
"MODULE.bazel": "sha256-Vm2C97cPME/4OD1JvQvQqIkKIBaYDSgEjDJYcJDI/DM=",
12+
"examples/BUILD.bazel": "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
13+
"examples/address_book/BUILD.bazel": "sha256-ATWDMRmpC/TrLxMH+HGaIHrJZt8tzTMgS8AspWaJkfE=",
14+
"tests/BUILD.bazel": "sha256-dRVpZcvHpgEbJfg1zOx4JrgNxI9LnrE/lzbxAoXXhnQ=",
15+
"tests/tools.bzl": "sha256-r6zxytasL71kmJQya2mERYO4q1xPvxwHNtJuhW9Gnio="
16+
}
17+
}

modules/fastjson/metadata.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
{
55
"email": "[email protected]",
66
"github": "Attempt3035",
7-
"name": "Luke Aguilar",
8-
"github_user_id": 118163872
7+
"github_user_id": 118163872,
8+
"name": "Luke Aguilar"
99
}
1010
],
1111
"repository": [
1212
"github:mikeando/fastjson"
1313
],
1414
"versions": [
15-
"0.0.0-20120701063936-485f994a61a6"
15+
"0.0.0-20120701063936-485f994a61a6",
16+
"0.0.0-20120701063936-485f994a61a6.bcr.1"
1617
],
1718
"yanked_versions": {}
1819
}

0 commit comments

Comments
 (0)