Skip to content
Merged
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
56 changes: 44 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: init
run: uname -m
run: |
uname -m
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 10
- name: configure
run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14
run: cmake -S . --preset=ninja-gcc -B build
- name: build debug
run: cmake --build build --config=Debug -- -v
- name: build release
Expand All @@ -25,16 +27,18 @@ jobs:
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-gcc -P install_test/script.cmake
x64-linux-clang:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: init
run: |
uname -m
sudo apt update -yqq && sudo apt install -yqq clang-19
sudo apt update -yqq && sudo apt install -yqq clang-20
sudo update-alternatives --remove-all clang++
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 10
- name: configure
run: cmake -S . --preset=ninja-clang -B build
- name: build debug
Expand All @@ -45,12 +49,16 @@ jobs:
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-clang -P install_test/script.cmake
arm64-linux-gcc:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: init
run: uname -m
run: |
uname -m
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 10
- name: configure
run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14
- name: build debug
Expand All @@ -61,16 +69,18 @@ jobs:
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-gcc -P install_test/script.cmake
arm64-linux-clang:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: init
run: |
uname -m
sudo apt update -yqq && sudo apt install -yqq clang-19
sudo apt update -yqq && sudo apt install -yqq clang-20
sudo update-alternatives --remove-all clang++
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 10
- name: configure
run: cmake -S . --preset=ninja-clang -B build
- name: build debug
Expand All @@ -81,6 +91,8 @@ jobs:
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-clang -P install_test/script.cmake
x64-windows-vs22:
runs-on: windows-2025
steps:
Expand All @@ -95,17 +107,37 @@ jobs:
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=vs22 -P install_test/script.cmake
x64-windows-clang:
runs-on: windows-2025
steps:
- uses: actions/checkout@v4
- name: configure
run: cmake -S . --preset=ninja-clang -B clang
run: cmake -S . --preset=ninja-clang -B build
- name: build debug
run: cmake --build build --config=Debug -- -v
- name: build release
run: cmake --build build --config=Release -- -v
- name: test debug
run: cd build && ctest -V -C Debug
- name: test release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-clang -P install_test/script.cmake
x64-mingw-gcc:
runs-on: windows-2025
steps:
- uses: actions/checkout@v4
- name: configure
run: cmake -S . --preset=ninja-gcc -B build
- name: build debug
run: cmake --build clang --config=Debug -- -v
run: cmake --build build --config=Debug -- -v
- name: build release
run: cmake --build clang --config=Release -- -v
run: cmake --build build --config=Release -- -v
- name: test debug
run: cd clang && ctest -V -C Debug
run: cd build && ctest -V -C Debug
- name: test release
run: cd clang && ctest -V -C Release
run: cd build && ctest -V -C Release
- name: test install
run: cmake -DBUILD_DIR=build -DPRESET=ninja-gcc -P install_test/script.cmake
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(version.cmake)

project(djson VERSION ${djson_version})

option(DJ_INSTALL "Setup djson install" ${PROJECT_IS_TOP_LEVEL})
option(DJ_BUILD_TESTS "Build djson tests" ${PROJECT_IS_TOP_LEVEL})

configure_file(Doxyfile.in Doxyfile @ONLY)
Expand Down
3 changes: 3 additions & 0 deletions install_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exe/CMakePresets.json
/build
/packages
15 changes: 15 additions & 0 deletions install_test/exe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.23)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(exe)

add_executable(${PROJECT_NAME})

find_package(djson CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME} PRIVATE djson::djson)

target_sources(${PROJECT_NAME} PRIVATE main.cpp)
4 changes: 4 additions & 0 deletions install_test/exe/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <djson/build_version.hpp>
#include <print>

auto main() -> int { std::println("djson version: {}", dj::build_version_v); }
50 changes: 50 additions & 0 deletions install_test/script.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
if("${PRESET}" STREQUAL "")
message(FATAL_ERROR "Invalid PRESET: ${PRESET}")
endif()

if("${BUILD_DIR}" STREQUAL "")
message(FATAL_ERROR "Invalid BUILD_DIR: ${BUILD_DIR}")
endif()

message(STATUS "djson install test")

execute_process(
COMMAND ${CMAKE_COMMAND} --install ${BUILD_DIR} --config=Debug --prefix=install_test/packages
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND ${CMAKE_COMMAND} --install ${BUILD_DIR} --config=Release --prefix=install_test/packages
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND cp -f CMakePresets.json install_test/exe
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND ${CMAKE_COMMAND} -S install_test/exe --preset=${PRESET} -B=install_test/build -DCMAKE_INSTALL_PREFIX=install_test/packages
COMMAND_ERROR_IS_FATAL ANY
COMMAND_ECHO STDOUT
)

execute_process(
COMMAND ${CMAKE_COMMAND} --build install_test/build --config=Debug
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND ${CMAKE_COMMAND} --build install_test/build --config=Release
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND install_test/build/Debug/exe
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(
COMMAND install_test/build/Release/exe
COMMAND_ERROR_IS_FATAL ANY
)
24 changes: 22 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(djson-lib VERSION ${djson_version})

set(version_file "${CMAKE_CURRENT_BINARY_DIR}/include/djson/build_version.hpp")
configure_file(src/build_version.hpp.in "${version_file}" @ONLY)

Expand Down Expand Up @@ -27,3 +25,25 @@ target_sources(${PROJECT_NAME} PRIVATE
)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)

target_link_libraries(${PROJECT_NAME} PRIVATE
$<$<BOOL:${MINGW}>:stdc++exp>
)

if(DJ_INSTALL)
message(STATUS "[djson] setting up install")
include(GNUInstallDirs)

install(
TARGETS djson
EXPORT djson-targets
FILE_SET HEADERS
)

install(
EXPORT djson-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/djson"
NAMESPACE djson::
FILE djson-config.cmake
)
endif()
1 change: 1 addition & 0 deletions lib/src/djson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ auto Parser::from_operator(token::Operator const op) -> Json {
template <typename T>
auto Parser::make_number(token::Number const in) -> Json {
auto value = T{};
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
auto const* end = in.raw_str.data() + in.raw_str.size();
auto const [ptr, ec] = std::from_chars(in.raw_str.data(), end, value);
if (ec != std::errc{} || ptr != end) { throw make_error(Error::Type::InvalidNumber); }
Expand Down
15 changes: 15 additions & 0 deletions tests/test_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,19 @@ TEST(serialize_object) {
std::println("serialized: {}", str);
EXPECT(str == expected);
}

TEST(serialize_escape) {
std::string_view text = R"(test "quoted" text)";
std::string_view expected = R"("test \"quoted\" text")";
auto json = Json{};
json.set_string(text);
auto str = json.serialize(SerializeOptions{.flags = SerializeFlag::NoSpaces});
std::println("serialized:\n{}\nexpected:\n{}", str, expected);
EXPECT(str == expected);

auto result = Json::parse(str);
ASSERT(result);
json = std::move(*result);
EXPECT(json.as_string() == text);
}
} // namespace
2 changes: 1 addition & 1 deletion version.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set(djson_version "3.1.2")
set(djson_version "3.1.3")