Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Module: fastjson
Purpose: Provides the fastjson library compileable as a Bazel target. Includes unit testing through Bazel
Notes: boost.property_tree is used for the speed test unit test. saru is used as the unit testing framework
"""

module(
name = "fastjson",
version = "0.0.0-20120701063936-485f994a61a6.bcr.1",
bazel_compatibility = [">=7.2.1"], # need support for "overlay" directory
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.2.4")
bazel_dep(name = "platforms", version = "1.0.0")

bazel_dep(name = "boost.property_tree", version = "1.89.0.bcr.1", dev_dependency = True)
bazel_dep(name = "saru", version = "0.0.0-20130617092049-c11c375fefd7", dev_dependency = True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")

cc_library(
name = "fastjson",
srcs = glob(["src/*.cpp"]),
hdrs = glob(["include/**/*.h"]),
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-Wno-unused-variable", # Ignore unused element - Don't pollute downstream users
],
}),
includes = ["include"], # Expose for import without include prefix
visibility = ["//visibility:public"],
)

# This must be defined in top level BUILD as we can't access files above the target(s) file
cc_library(
name = "fastjson-test-srcs",
hdrs = glob(["src/*.cpp"]),
includes = ["include/fastjson"], # Tests need access to includes without fastjson folder prefix
visibility = ["//tests:__pkg__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Module: fastjson
Purpose: Provides the fastjson library compileable as a Bazel target. Includes unit testing through Bazel
Notes: boost.property_tree is used for the speed test unit test. saru is used as the unit testing framework
"""

module(
name = "fastjson",
version = "0.0.0-20120701063936-485f994a61a6.bcr.1",
bazel_compatibility = [">=7.2.1"], # need support for "overlay" directory
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.2.4")
bazel_dep(name = "platforms", version = "1.0.0")

bazel_dep(name = "boost.property_tree", version = "1.89.0.bcr.1", dev_dependency = True)
bazel_dep(name = "saru", version = "0.0.0-20130617092049-c11c375fefd7", dev_dependency = True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")

cc_binary(
name = "address_book",
srcs = ["address_book.cpp"],
copts = [
"-g", # Debug symbols
"-Wall", # All warnings
],
data = ["book.json"], # Include the JSON file as a runtime dependency
deps = ["//:fastjson"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load(":tools.bzl", "test_set")

TEST_COPTS = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-g", # Debug symbols
"-Wall", # All warnings
],
})

DEPS = [
"//:fastjson",
"//:fastjson-test-srcs",
"@saru",
]

test_suite(
name = "all_tests",
tests = test_set(
copts = TEST_COPTS,
test_files = glob(
["**/*.cpp"],
exclude = ["misc/speed_test_boost.cpp"],
),
deps = DEPS,
) + [":speed_test"],
)

cc_test(
name = "speed_test",
size = "medium",
srcs = ["misc/speed_test_boost.cpp"],
copts = TEST_COPTS,
deps = DEPS + [
"@boost.property_tree",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tool for generating C++ test targets efficiently using Bazel rules.
"""

load("@rules_cc//cc:cc_test.bzl", "cc_test")

def test_set(
test_files = None,
size = "small",
srcs = [],
file_extensions = ".cpp",
**kwargs):
"""Creates C++ test targets from a list of test files.

Args:
test_files: List of test file paths to process. Defaults to None.
size: Test size parameter for cc_test rule. Defaults to "small".
srcs: Additional source files to include in all tests. Defaults to empty list.
file_extensions: Expected extension of test files. Defaults to ".cpp".
**kwargs: Additional arguments to pass to cc_test rule.

Returns:
List of test target names (e.g., [":test1", ":test2"]).

Note:
Only files ending with the specified file_extensions are processed.
Each test target is created with the filename (without extension) as its name.
"""
test_targets = []

# Process positive tests
for file in test_files:
if not file.endswith(file_extensions):
continue
name = file[:-len(file_extensions)]
target = ":" + name
cc_test(
name = name,
size = size,
srcs = srcs + [file],
**kwargs
)
test_targets.append(target)

return test_targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/tests/misc/speed_test_boost.cpp b/tests/misc/speed_test_boost.cpp
index 490cab5..11df3e2 100644
--- a/tests/misc/speed_test_boost.cpp
+++ b/tests/misc/speed_test_boost.cpp
@@ -111 +111 @@ int main()
- boost::property_tree::write_json_compact( ssout, n );
+ boost::property_tree::write_json( ssout, n );
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
matrix:
platform:
- debian10
- ubuntu2004
- macos
- macos_arm64
- windows
bazel:
- rolling
- 8.x
- 7.x
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "@fastjson//:fastjson"

bcr_test_module:
module_path: "tests"
matrix:
platform:
- debian10
- ubuntu2004
- macos
- macos_arm64
- windows
bazel:
- rolling
- 8.x
- 7.x
tasks:
run_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
test_targets:
- "//tests:all_tests"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"url": "https://github.com/mikeando/fastjson/archive/485f994.tar.gz",
"integrity": "sha256-phIJMsU4I0+lq+i1hIY+efTSKt5ik9fFVr1NvvJlUgM=",
"patch_strip": 1,
"strip_prefix": "fastjson-485f994a61a64ac73fa6a40d4d639b99b463563b",
"patches": {
"boost_property_tree_compact.patch": "sha256-TXYBKEYstPVgXM9gb8WS+h2ucd6aniFQJC2f1oiDvRo="
},
"overlay": {
"BUILD.bazel": "sha256-eH/vpiHShYq5FDEdUGN9kPeM172uCPIPnPNQJRuvNdU=",
"MODULE.bazel": "sha256-Vm2C97cPME/4OD1JvQvQqIkKIBaYDSgEjDJYcJDI/DM=",
"examples/BUILD.bazel": "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
"examples/address_book/BUILD.bazel": "sha256-ATWDMRmpC/TrLxMH+HGaIHrJZt8tzTMgS8AspWaJkfE=",
"tests/BUILD.bazel": "sha256-dRVpZcvHpgEbJfg1zOx4JrgNxI9LnrE/lzbxAoXXhnQ=",
"tests/tools.bzl": "sha256-r6zxytasL71kmJQya2mERYO4q1xPvxwHNtJuhW9Gnio="
}
}
7 changes: 4 additions & 3 deletions modules/fastjson/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
{
"email": "[email protected]",
"github": "Attempt3035",
"name": "Luke Aguilar",
"github_user_id": 118163872
"github_user_id": 118163872,
"name": "Luke Aguilar"
}
],
"repository": [
"github:mikeando/fastjson"
],
"versions": [
"0.0.0-20120701063936-485f994a61a6"
"0.0.0-20120701063936-485f994a61a6",
"0.0.0-20120701063936-485f994a61a6.bcr.1"
],
"yanked_versions": {}
}
Loading