Skip to content

Commit

Permalink
Merge pull request #88 from biojppm/update_c4core
Browse files Browse the repository at this point in the history
[chore] update c4core
  • Loading branch information
biojppm committed Oct 26, 2020
2 parents 1ca892a + aa40845 commit cc72d80
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 29 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/create_c4_pack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# this is a work in progress
name: create_c4_pack

on:
- push
- workflow_dispatch

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
createPack:
# https://github.community/t/create-matrix-with-multiple-os-and-env-for-each-one/16895/6
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
- os: ubuntu-latest
- os: windows-latest

steps:

# Get latest CMake and ninja
# https://github.com/marketplace/actions/get-cmake
- name: Get cmake+ninja
uses: lukka/get-cmake@latest

- name: checkout
uses: actions/checkout@v2
with: {submodules: recursive}

- name: show versions
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
run: |
cmake --version
echo "SRC_DIR=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "TEST_DIR=${{runner.workspace}}/build/test" >> $GITHUB_ENV
echo "PACK_DIR=${{runner.workspace}}/build/pack" >> $GITHUB_ENV
cmake -E echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
cmake -E echo "runner.workspace=${{runner.workspace}}"
cmake -E echo "SRC_DIR=$SRC_DIR"
cmake -E echo "TEST_DIR=$TEST_DIR"
cmake -E echo "PACK_DIR=$PACK_DIR"
- name: create build dirs
shell: bash
run: |
cmake -E echo "SRC_DIR=$SRC_DIR"
cmake -E echo "TEST_DIR=$TEST_DIR"
cmake -E echo "PACK_DIR=$PACK_DIR"
cmake -E make_directory $PACK_DIR
cmake -E make_directory $TEST_DIR
# run the tests first
- name: configure_test
shell: bash
run: cmake -S $SRC_DIR -B $TEST_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRYML_BUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=$TEST_DIR/../install_test

- name: build_test
shell: bash
run: cmake --build $TEST_DIR --config $BUILD_TYPE --parallel --target test-build

- name: run_test
shell: bash
run: cmake --build $TEST_DIR --config $BUILD_TYPE --target test


# if the tests succeed, build and create the pack.
# We do not pack the test directory because it brings
# third party projects (eg gtest) into cmake.
- name: configure_pack
shell: bash
run: cmake -S $SRC_DIR -B $PACK_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: build_pack
shell: bash
run: cmake --build $PACK_DIR --config $BUILD_TYPE --parallel

- name: create_pack
shell: bash
run: |
cd $PACK_DIR
cpack -C $BUILD_TYPE --verbose
41 changes: 16 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
cmake_minimum_required(VERSION 3.9)
project(ryml)

cmake_minimum_required(VERSION 3.12)
include(./ext/c4core/cmake/c4Project.cmake)

c4_declare_project(ryml
STANDALONE
DESC "Rapid YAML parsing and emitting"
AUTHOR "Joao Paulo Magalhaes <dev@jpmag.me>"
MAJOR 0 MINOR 1 RELEASE 0)
project(ryml
DESCRIPTION "Rapid YAML parsing and emitting"
HOMEPAGE_URL "https://github.com/biojppm/rapidyaml"
LANGUAGES CXX)
c4_project(VERSION 0.0.1 STANDALONE
AUTHOR "Joao Paulo Magalhaes <dev@jpmag.me>")


#-------------------------------------------------------
Expand Down Expand Up @@ -69,6 +67,7 @@ endif()

c4_install_target(ryml)
c4_install_exports(DEPENDENCIES c4core)
c4_pack_project()


#-------------------------------------------------------
Expand All @@ -77,30 +76,22 @@ c4_install_exports(DEPENDENCIES c4core)
# extern libraries, used only for testing/benchmarking
if(RYML_BUILD_TESTS OR RYML_BUILD_BENCHMARKS)
set(ed ${CMAKE_CURRENT_BINARY_DIR}/subprojects) # casual ryml extern dir (these projects are not part of ryml and are downloaded and compiled on the fly)
#
# these are used both for testing and benchmarking
#
c4_require_subproject(c4fs
REMOTE
c4_require_subproject(c4fs REMOTE
GIT_REPOSITORY https://github.com/biojppm/c4fs
GIT_TAG master)
#
c4_override(BUILD_TESTING OFF)
c4_require_subproject(libyaml REMOTE
GIT_REPOSITORY https://github.com/yaml/libyaml
GIT_TAG master)
c4_set_folder_remote_project_targets(ext yaml)
#
c4_override(YAML_CPP_BUILD_TESTS OFF)
c4_override(YAML_CPP_BUILD_TOOLS OFF)
c4_override(YAML_CPP_BUILD_CONTRIB OFF)
c4_override(YAML_CPP_BUILD_INSTALL OFF)
c4_import_remote_proj(yaml-cpp ${ed}/yaml-cpp
GIT_TAG master
OVERRIDE BUILD_TESTING OFF
SET_FOLDER_TARGETS ext yaml)
c4_import_remote_proj(yaml-cpp ${ed}/yaml-cpp REMOTE
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp
# the master branch regularly screws up on windows builds.
# so use fixed pre-validated commit hashes
GIT_TAG 587b24e2eedea1afa21d79419008ca5f7bda3bf4)
c4_set_folder_remote_project_targets(ext/yaml-cpp yaml-cpp format)
GIT_TAG 587b24e2eedea1afa21d79419008ca5f7bda3bf4
OVERRIDE YAML_CPP_BUILD_TESTS OFF YAML_CPP_BUILD_TOOLS OFF YAML_CPP_BUILD_CONTRIB OFF YAML_CPP_BUILD_INSTALL OFF
SET_FOLDER_TARGETS ext yaml-cpp format)
set(ryml_yaml_cpp_inc ${ed}/yaml-cpp/src/include)
endif()

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ The first benchmarks results are extremely satisfying. On a i7-6800K CPU @
try yet on Windows).
* compared against the other existing YAML libraries for C/C++:
* ryml is in general between 2 and 3 times faster than [libyaml](https://github.com/yaml/libyaml)
* ryml is in general between 20 and 70 times faster than [yaml-cpp](https://github.com/jbeder/yaml-cpp)
* ryml is in general between 20 and 70 times faster than
[yaml-cpp](https://github.com/jbeder/yaml-cpp), and in some cases as
much as 100x and [even
200x](https://github.com/biojppm/c4core/pull/16#issuecomment-700972614) faster.

[Here's the benchmark](./bm/parse.cpp). Using different
approaches within ryml (in-situ/read-only vs. with/without reuse), a YAML /
Expand Down
5 changes: 3 additions & 2 deletions test/parse_emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ struct timed_section

int main(int argc, const char *argv[])
{
TS(TOTAL);

if(argc != 2)
{
printf("usage: %s <path/to/file.yaml>\n", argv[0]);
return 1;
}

TS(TOTAL);

csubstr file = to_csubstr(argv[1]);
C4_CHECK_MSG(fs::path_exists(file.str), "cannot find file: %s (cwd=%s)", file.str, fs::cwd<std::string>().c_str());

Expand Down
44 changes: 44 additions & 0 deletions test/test_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,50 @@ TEST(serialize, std_vector__map_string_int)
});
}


TEST(serialize, bool)
{
Tree t = parse("{a: 0, b: false, c: 1, d: true}");
bool v, w;
t["a"] >> v;
EXPECT_EQ(v, false);
t["b"] >> v;
EXPECT_EQ(v, false);
t["c"] >> v;
EXPECT_EQ(v, true);
t["d"] >> v;
EXPECT_EQ(v, true);

t["e"] << true;
EXPECT_EQ(t["e"].val(), "1");
t["e"] >> w;
EXPECT_EQ(w, true);

t["e"] << false;
EXPECT_EQ(t["e"].val(), "0");
t["e"] >> w;
EXPECT_EQ(w, false);

t["e"] << fmt::boolalpha(true);
EXPECT_EQ(t["e"].val(), "true");
t["e"] >> w;
EXPECT_EQ(w, true);

t["e"] << fmt::boolalpha(false);
EXPECT_EQ(t["e"].val(), "false");
t["e"] >> w;
EXPECT_EQ(w, false);
}

TEST(serialize, std_string)
{
auto t = parse("{foo: bar}");
std::string s;
EXPECT_NE(s, "bar");
t["foo"] >> s;
EXPECT_EQ(s, "bar");
}

} /*namespace yml*/
} /*namespace c4*/

Expand Down

0 comments on commit cc72d80

Please sign in to comment.