From a32fc9f59a1dc8914f3dc0cca444229f7d7b2117 Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Thu, 20 Apr 2023 17:43:00 +0200 Subject: [PATCH] Add Meson build job to CI workflow. This commit adds a new job to the CI workflow which builds, runs the tests, and the benchmarks under meson on Linux, Windows and macos. The benchmark code up until now was not compiled with the same flags as the library and runtime and so had avoided some scrutiny from these warnings. Under Meson this is no longer the case, and so this code has been fixed up to clean up some warnings --- .github/workflows/ci.yml | 42 +++++++++++++++++++ test/benchmark/benchflatc/benchflatc.cpp | 13 ++++-- .../benchflatc/flatbuffers/flatbuffers.h | 2 +- test/benchmark/benchflatcc/benchflatcc.c | 11 +++-- .../benchflatccjson/benchflatccjson.c | 11 +++-- test/benchmark/benchmain/benchmain.h | 6 +++ test/benchmark/benchraw/benchraw.c | 16 +++---- 7 files changed, 83 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42e227d67..7de458d8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,3 +58,45 @@ jobs: cmake . msbuild FlatCC.sln /m /property:Configuration=Release ctest -VV + + meson-build: + name: Meson (${{matrix.os}}) + runs-on: ${{matrix.os}} + continue-on-error: true + strategy: + matrix: + os: [ ubuntu-22.04, macos-12, windows-2022 ] + steps: + - uses: actions/checkout@v3 + + - uses: microsoft/setup-msbuild@v1.1 + if: runner.os == 'windows' + - uses: actions/setup-python@v2 + if: runner.os == 'windows' + - name: Prepare MSVC + uses: bus1/cabuild/action/msdevshell@v1 + with: + architecture: x64 + if: runner.os == 'windows' + - name: Install dependencies (windows) + if: runner.os == 'windows' + run: | + pip install meson + + - name: Install dependencies (ubuntu) + if: runner.os == 'linux' + run: | + sudo apt update -y + sudo apt install ninja-build meson + + - name: Install dependencies (macos) + if: runner.os == 'macos' + run: | + brew install meson ninja + + - name: Build and run tests + run: | + meson setup build --buildtype release + meson compile -C build + meson test -C build --verbose + meson test -C build --benchmark --verbose diff --git a/test/benchmark/benchflatc/benchflatc.cpp b/test/benchmark/benchflatc/benchflatc.cpp index d5d329606..d1e7c7a87 100644 --- a/test/benchmark/benchflatc/benchflatc.cpp +++ b/test/benchmark/benchflatc/benchflatc.cpp @@ -23,10 +23,17 @@ int encode(void *bench, void *buffer, size_t *size) for (int i = 0; i < veclen; i++) { // We add + i to not make these identical copies for a more realistic // compression test. - auto const &foo = Foo(0xABADCAFEABADCAFE + i, 10000 + i, '@' + i, 1000000 + i); - auto const &bar = Bar(foo, 123456 + i, 3.14159f + i, 10000 + i); + auto const &foo = Foo(0xABADCAFEABADCAFE + static_cast(i), + 10000 + static_cast(i), + '@' + static_cast(i), + 1000000 + static_cast(i) + ); + auto const &bar = Bar(foo, 123456 + i, + 3.14159f + static_cast(i), + 10000 + static_cast(i) + ); auto name = fbb.CreateString("Hello, World!"); - auto foobar = CreateFooBar(fbb, &bar, name, 3.1415432432445543543 + i, '!' + i); + auto foobar = CreateFooBar(fbb, &bar, name, 3.1415432432445543543 + i, '!' + static_cast(i)); vec[i] = foobar; } auto location = fbb.CreateString("https://www.example.com/myurl/"); diff --git a/test/benchmark/benchflatc/flatbuffers/flatbuffers.h b/test/benchmark/benchflatc/flatbuffers/flatbuffers.h index 3482cbee3..2311d54a9 100644 --- a/test/benchmark/benchflatc/flatbuffers/flatbuffers.h +++ b/test/benchmark/benchflatc/flatbuffers/flatbuffers.h @@ -464,7 +464,7 @@ class vector_downward { uoffset_t size() const { assert(cur_ != nullptr && buf_ != nullptr); - return static_cast(reserved_ - (cur_ - buf_)); + return static_cast(reserved_ - static_cast(cur_ - buf_)); } uint8_t *data() const { diff --git a/test/benchmark/benchflatcc/benchflatcc.c b/test/benchmark/benchflatcc/benchflatcc.c index 1d7208389..a45d7cc4f 100644 --- a/test/benchmark/benchflatcc/benchflatcc.c +++ b/test/benchmark/benchflatcc/benchflatcc.c @@ -37,11 +37,16 @@ int encode(flatcc_builder_t *B, void *buffer, size_t *size) */ C(list_push_start(B)); FooBar(sibling_create(B, - 0xABADCAFEABADCAFE + i, 10000 + i, '@' + i, 1000000 + i, - 123456 + i, 3.14159f + i, 10000 + i)); + 0xABADCAFEABADCAFE + (unsigned long)i, + 10000 + (short)i, + '@' + (char)i, + 1000000 + (unsigned int)i, + 123456 + i, + 3.14159f + (float)i, + 10000 + (unsigned short)i)); FooBar(name_create_str(B, "Hello, World!")); FooBar(rating_add(B, 3.1415432432445543543 + i)); - FooBar(postfix_add(B, '!' + i)); + FooBar(postfix_add(B, '!' + (unsigned char)i)); C(list_push_end(B)); } C(list_end(B)); diff --git a/test/benchmark/benchflatccjson/benchflatccjson.c b/test/benchmark/benchflatccjson/benchflatccjson.c index 26ee2915d..a10b4af38 100644 --- a/test/benchmark/benchflatccjson/benchflatccjson.c +++ b/test/benchmark/benchflatccjson/benchflatccjson.c @@ -63,11 +63,16 @@ int flatcc_jsonbench_init(flatcc_jsonbench_t *bench) */ C(list_push_start(B)); FooBar(sibling_create(B, - 0xABADCAFEABADCAFE + i, 10000 + i, '@' + i, 1000000 + i, - 123456 + i, 3.14159f + i, 10000 + i)); + 0xABADCAFEABADCAFE + (unsigned long)i, + 10000 + (short)i, + '@' + (char)i, + 1000000 + (unsigned int)i, + 123456 + i, + 3.14159f + (float)i, + 10000 + (unsigned short)i)); FooBar(name_create_str(B, "Hello, World!")); FooBar(rating_add(B, 3.1415432432445543543 + i)); - FooBar(postfix_add(B, '!' + i)); + FooBar(postfix_add(B, '!' + (unsigned char)i)); C(list_push_end(B)); } C(list_end(B)); diff --git a/test/benchmark/benchmain/benchmain.h b/test/benchmark/benchmain/benchmain.h index 8241ca483..b6bbefe91 100644 --- a/test/benchmark/benchmain/benchmain.h +++ b/test/benchmark/benchmain/benchmain.h @@ -61,6 +61,12 @@ int main(int argc, char *argv[]) show_benchmark(BENCH_TITLE " decode/traverse " COMPILE_TYPE, t2, t3, size, rep, "1M"); printf("----\n"); ret = 0; + +#ifdef NDEBUG + // Silence warnings in optimised builds. + (void)ret; +#endif + done: if (buf) { free(buf); diff --git a/test/benchmark/benchraw/benchraw.c b/test/benchmark/benchraw/benchraw.c index 7a50c9719..d3cba2973 100644 --- a/test/benchmark/benchraw/benchraw.c +++ b/test/benchmark/benchraw/benchraw.c @@ -55,24 +55,24 @@ int encode(void *bench, void *buffer, size_t *size) (void)bench; strcpy(fbc.location, "https://www.example.com/myurl/"); - fbc.location_len = strlen(fbc.location); + fbc.location_len = (int)strlen(fbc.location); fbc.fruit = Bananas; fbc.initialized = 1; for (i = 0; i < VEC_LEN; ++i) { foobar = &fbc.list[i]; foobar->rating = 3.1415432432445543543 + i; - foobar->postfix = '!' + i; + foobar->postfix = '!' + (unsigned char)i; strcpy(foobar->name, "Hello, World!"); - foobar->name_len = strlen(foobar->name); + foobar->name_len = (int)strlen(foobar->name); bar = &foobar->sibling; - bar->ratio = 3.14159f + i; - bar->size = 10000 + i; + bar->ratio = 3.14159f + (float)i; + bar->size = 10000 + (unsigned short)i; bar->time = 123456 + i; foo = &bar->parent; - foo->id = 0xABADCAFEABADCAFE + i; - foo->count = 10000 + i; + foo->id = (int64_t)0xABADCAFEABADCAFE + i; + foo->count = 10000 + (short)i; foo->length = 1000000 + i; - foo->prefix = '@' + i; + foo->prefix = '@' + (char)i; } if (*size < sizeof(struct FooBarContainer)) { return -1;