Skip to content

Commit

Permalink
[WIP] Revamp JSON BinPack with the new JSON Toolkit
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jan 13, 2024
1 parent 39aea58 commit d10756e
Show file tree
Hide file tree
Showing 368 changed files with 27,983 additions and 48,529 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ insert_final_newline = true
[Makefile]
indent_style = tab

[GNUmakefile]
indent_style = tab

[*.mk]
indent_style = tab
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
CC: ${{ matrix.platform.cc }}
CXX: ${{ matrix.platform.cxx }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install dependencies (macOS)
if: runner.os == 'macos'
run: brew bundle
Expand All @@ -44,7 +44,7 @@ jobs:
if: runner.os == 'linux' && matrix.platform.cc == 'clang'
run: |
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get install --yes --allow-downgrades libc6=2.35-0ubuntu3.4 libc6-dev=2.35-0ubuntu3.4 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
sudo apt-get install --yes --allow-downgrades libc6=2.35-0ubuntu3.5 libc6-dev=2.35-0ubuntu3.5 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
- name: Install dependencies (Windows)
if: runner.os == 'windows'
Expand All @@ -59,5 +59,5 @@ jobs:
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON
- run: cmake --build ./build --config Release --target shellcheck
- run: cmake --build ./build --config Release --target clang_format_test
- run: cmake --build ./build --config Release --parallel 2
- run: cmake --build ./build --config Release --parallel 4
- run: cd ./build && ctest --build-config Release --output-on-failure --parallel
94 changes: 52 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
cmake_minimum_required(VERSION 3.24)
project("JSON BinPack" VERSION 0.0.1 LANGUAGES CXX
project(jsonbinpack VERSION 0.0.1 LANGUAGES C CXX
DESCRIPTION "\
A space-efficient open-source binary JSON serialization \
format based on JSON Schema with \
both schema-driven and schema-less support.")
include(vendor/noa/cmake/noa.cmake)
both schema-driven and schema-less support."
HOMEPAGE_URL "https://www.jsonbinpack.org")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

include(cmake/warnings.cmake)
# Dependencies
find_package(JSONToolkit REQUIRED)

# Options
option(JSONBINPACK_CLI "Build the JSON BinPack CLI" ON)
option(JSONBINPACK_TESTS "Build the JSON BinPack tests" ON)
option(JSONBINPACK_TESTS "Build the JSON BinPack tests" OFF)
option(JSONBINPACK_INSTALL "Install the JSON BinPack library" ON)

# JSON Toolkit
set(JSONTOOLKIT_BACKEND "rapidjson" CACHE STRING "Set JSON backend")
set(JSONTOOLKIT_BACKEND_PATH "${PROJECT_SOURCE_DIR}/vendor/rapidjson" CACHE STRING "Use vendored backend")
add_subdirectory(vendor/jsontoolkit)
# Global includes
include(vendor/noa/cmake/noa.cmake)
include(cmake/CompilerOptions.cmake)

if(PROJECT_IS_TOP_LEVEL)
noa_target_clang_format(SOURCES
src/*.h src/*.cc
test/*.h test/*.cc)
noa_target_clang_tidy(SOURCES
src/*.h src/*.cc)
noa_target_shellcheck(SOURCES
test/*.sh scripts/*.sh)
endif()

# Sources
add_subdirectory(src/alterschema)
add_subdirectory(src/canonicalizer)
add_subdirectory(src/encoding)
add_subdirectory(src/parser)
add_subdirectory(src/numeric)
add_subdirectory(src/encoding)
add_subdirectory(src/encoder)
add_subdirectory(src/decoder)
add_subdirectory(src/schemas)
add_subdirectory(src/mapper)
if(JSONBINPACK_CLI)
add_subdirectory(src/cli)
endif()

# Sources
# add_subdirectory(src/alterschema)
# add_subdirectory(src/canonicalizer)
# add_subdirectory(src/parser)
# add_subdirectory(src/decoder)
# add_subdirectory(src/schemas)
# add_subdirectory(src/mapper)
# if(JSONBINPACK_CLI)
# add_subdirectory(src/cli)
# endif()

# Testing
if(JSONBINPACK_TESTS)
find_package(GoogleTest REQUIRED)
enable_testing()
set(BUILD_GMOCK OFF CACHE BOOL "disable googlemock")
set(INSTALL_GTEST OFF CACHE BOOL "disable installation")
include(GoogleTest)
add_subdirectory(vendor/googletest)
add_subdirectory(test/alterschema)
add_subdirectory(test/canonicalizer)
add_subdirectory(test/encoding)
add_subdirectory(test/parser)

add_subdirectory(test/numeric)
add_subdirectory(test/encoding)
add_subdirectory(test/encoder)
add_subdirectory(test/decoder)
add_subdirectory(test/schemas)
add_subdirectory(test/mapper)
if(JSONBINPACK_CLI)
add_subdirectory(test/cli)
endif()
add_subdirectory(test/e2e)
endif()

# Only for top-level builds
if(PROJECT_IS_TOP_LEVEL)
file(GLOB_RECURSE JSONBINPACK_CXX_SOURCE_FILES src/*.cc src/*.h test/*.cc test/*.h)
noa_target_clang_format(SOURCES ${JSONBINPACK_CXX_SOURCE_FILES})
noa_target_clang_tidy(SOURCES ${JSONBINPACK_CXX_SOURCE_FILES})
noa_target_shellcheck(SOURCES test/*.sh scripts/*.sh)
# # Testing
# if(JSONBINPACK_TESTS)
# add_subdirectory(vendor/googletest)
# add_subdirectory(test/alterschema)
# add_subdirectory(test/canonicalizer)
# add_subdirectory(test/parser)
# add_subdirectory(test/decoder)
# add_subdirectory(test/schemas)
# add_subdirectory(test/mapper)
# if(JSONBINPACK_CLI)
# add_subdirectory(test/cli)
# endif()
# add_subdirectory(test/e2e)
# endif()

# Website
if(PROJECT_IS_TOP_LEVEL)
string(TOLOWER ${CMAKE_BUILD_TYPE} JSONBINPACK_BUILD_TYPE)
set(JSONBINPACK_WEBSITE_OUT ${PROJECT_SOURCE_DIR}/build/${JSONBINPACK_BUILD_TYPE}/www)
set(JSONBINPACK_WEBSITE_SRC ${PROJECT_SOURCE_DIR}/www)
include(${PROJECT_SOURCE_DIR}/cmake/bundler.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/jekyll.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/doxygen.cmake)
endif()
7 changes: 3 additions & 4 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull 6c398482e30bd85d7e8138c606e01f28270c29ae
rapidjson https://github.com/Tencent/rapidjson 06d58b9e848c650114556a23294d0b6440078c61
jsontoolkit https://github.com/sourcemeta/jsontoolkit e0efe63940e8c27b3a78ce27ac0c1be70922b741
googletest https://github.com/google/googletest e2239ee6043f73722e7aa812a459f54a28552929
jsontoolkit https://github.com/sourcemeta/jsontoolkit 6a81d733421e23813391be3fec4f97d7fd5e082f
googletest https://github.com/google/googletest 987e225614755fec7253aa95bf959c09e0d380d7
bootstrap https://github.com/twbs/bootstrap 1a6fdfae6be09b09eaced8f0e442ca6f7680a61e
noa https://github.com/sourcemeta/noa f7dc92ef5bf95ade5f585494e3a6de3692efdf4f
noa https://github.com/sourcemeta/noa 0862a96772362a6997ce2f5fda877b182a7b6f71
62 changes: 0 additions & 62 deletions GNUmakefile

This file was deleted.

20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Programs
CMAKE = cmake
CTEST = ctest

PRESET = debug
# Options
PRESET = Debug

all: configure compile test

configure: .always
$(CMAKE) -S . -B ./build \
Expand All @@ -13,20 +17,22 @@ configure: .always
compile: .always
$(CMAKE) --build ./build --config $(PRESET) --target clang_format
$(CMAKE) --build ./build --config $(PRESET) --parallel
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
--component sourcemeta_jsonbinpack
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
--component sourcemeta_jsonbinpack_dev

all: configure compile
$(CTEST) --test-dir ./build --build-config $(PRESET) --parallel

test: configure compile
$(CTEST) --test-dir ./build --build-config $(PRESET) --verbose --parallel
test: .always
$(CTEST) --test-dir ./build --build-config $(PRESET) \
--output-on-failure --progress --parallel

lint: .always
$(CMAKE) --build ./build --config $(PRESET) --target clang_tidy

clean: .always
$(CMAKE) -E rm -R -f build

doxygen: configure
doxygen:
$(CMAKE) --build ./build --config $(PRESET) --target doxygen

# For NMake, which doesn't support .PHONY
Expand Down
72 changes: 72 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
function(sourcemeta_jsonbinpack_add_compile_options visibility target)
if(NOA_COMPILER_MSVC)
# See https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category
target_compile_options("${target}" ${visibility}
/options:strict
/W4
/WL
/sdl)
else()
target_compile_options("${target}" ${visibility}
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wdouble-promotion
-Wconversion
-Wunused-parameter
-Wtrigraphs
-Wunreachable-code
-Wmissing-braces
-Wparentheses
-Wswitch
-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-variable
-Wunused-value
-Wempty-body
-Wuninitialized
-Wshadow
-Wconversion
-Wenum-conversion
-Wfloat-conversion
-Wimplicit-fallthrough
-Wsign-compare
# TODO: Enable this flag for safety
-Wno-sign-conversion
-Wunknown-pragmas
-Wnon-virtual-dtor
-Woverloaded-virtual
-Winvalid-offsetof

# Assume that signed arithmetic overflow of addition, subtraction and
# multiplication wraps around using twos-complement representation
# See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf
# See https://www.postgresql.org/message-id/[email protected]
-fwrapv)
endif()

if(NOA_COMPILER_LLVM)
target_compile_options("${target}" ${visibility}
-Wbool-conversion
-Wint-conversion
-Wpointer-sign
-Wconditional-uninitialized
-Wconstant-conversion
-Wnon-literal-null-conversion
-Wshorten-64-to-32
-Wdeprecated-implementations
-Winfinite-recursion
-Wnewline-eof
-Wfour-char-constants
-Wselector
-Wundeclared-selector
-Wdocumentation
-Wmove
-Wc++11-extensions
-Wcomma
-Wno-exit-time-destructors
-Wrange-loop-analysis)
endif()
endfunction()
7 changes: 7 additions & 0 deletions cmake/FindGoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(NOT GoogleTest_FOUND)
set(BUILD_GMOCK OFF CACHE BOOL "disable googlemock")
set(INSTALL_GTEST OFF CACHE BOOL "disable installation")
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googletest")
include(GoogleTest)
set(GoogleTest_FOUND ON)
endif()
4 changes: 4 additions & 0 deletions cmake/FindJSONToolkit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if(NOT JSONToolkit_FOUND)
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/jsontoolkit")
set(JSONToolkit_FOUND ON)
endif()
10 changes: 0 additions & 10 deletions cmake/bundler.cmake

This file was deleted.

1 change: 1 addition & 0 deletions cmake/doxygen.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: Use Noa for Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN "${PROJECT_SOURCE_DIR}/doxygen/Doxyfile.in")
Expand Down
13 changes: 13 additions & 0 deletions cmake/jekyll.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# TODO: Move to Makefile?

find_program(BUNDLE_BIN NAMES bundle)
set(JSONBINPACK_BUNDLER_PATH "${PROJECT_SOURCE_DIR}/build/bundler")
if(BUNDLE_BIN)
add_custom_target(bundler
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM
COMMAND "${BUNDLE_BIN}" install --path "${JSONBINPACK_BUNDLER_PATH}")
else()
message(WARNING "Could not find `bundler` in the system")
endif()

find_program(BUNDLE_BIN NAMES bundle)
if(BUNDLE_BIN)
add_custom_target(jekyll
Expand Down
Loading

0 comments on commit d10756e

Please sign in to comment.