Skip to content

Commit

Permalink
Add Meson build job to CI workflow.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amcn committed Apr 20, 2023
1 parent b4bd4ed commit a32fc9f
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 18 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
13 changes: 10 additions & 3 deletions test/benchmark/benchflatc/benchflatc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(i),
10000 + static_cast<int16_t>(i),
'@' + static_cast<int8_t>(i),
1000000 + static_cast<uint32_t>(i)
);
auto const &bar = Bar(foo, 123456 + i,
3.14159f + static_cast<float>(i),
10000 + static_cast<uint16_t>(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<uint8_t>(i));
vec[i] = foobar;
}
auto location = fbb.CreateString("https://www.example.com/myurl/");
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/benchflatc/flatbuffers/flatbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class vector_downward {

uoffset_t size() const {
assert(cur_ != nullptr && buf_ != nullptr);
return static_cast<uoffset_t>(reserved_ - (cur_ - buf_));
return static_cast<uoffset_t>(reserved_ - static_cast<unsigned long>(cur_ - buf_));
}

uint8_t *data() const {
Expand Down
11 changes: 8 additions & 3 deletions test/benchmark/benchflatcc/benchflatcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 8 additions & 3 deletions test/benchmark/benchflatccjson/benchflatccjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions test/benchmark/benchmain/benchmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions test/benchmark/benchraw/benchraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a32fc9f

Please sign in to comment.