From 6618aebabf0fc1f3a54648384167fb264f6be088 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Wed, 23 Oct 2024 14:23:49 +0200 Subject: [PATCH 1/9] Add a C++ test outline --- .github/workflows/main.yml | 21 +++++++++++++++- ci/cpp/CMakeLists.txt | 49 ++++++++++++++++++++++++++++++++++++++ ci/cpp/test.cpp | 5 ++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 ci/cpp/CMakeLists.txt create mode 100644 ci/cpp/test.cpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e167536..47b6d65 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,6 @@ concurrency: cancel-in-progress: true jobs: - tests: runs-on: ubuntu-latest steps: @@ -18,3 +17,23 @@ jobs: with: python-version: '3.12' - run: pip install kaitaistruct + + test-cpp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install compiler + run: sudo apt install cmake build-essential + + # The version here should match the one in ci/cpp/CMakeLists.txt + - name: Install kaitai-struct-compiler + run: | + curl -LO https://github.com/kaitai-io/kaitai_struct_compiler/releases/download/0.10/kaitai-struct-compiler_0.10_all.deb + sudo apt install kaitai-struct-compiler_0.10_all.deb + + - name: Build C++ test executable + run: | + cd ci/cpp + cmake -S . -B build + cmake --build build diff --git a/ci/cpp/CMakeLists.txt b/ci/cpp/CMakeLists.txt new file mode 100644 index 0000000..822e72f --- /dev/null +++ b/ci/cpp/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.26) +include(FetchContent) +project(test-cpp CXX) + +# Version of the kaitai_struct_cpp_stl_runtime +# Should match that of the kaitai-struct-compiler +set(KSCSR_VERSION "0.10") + +set(kaitai_struct_cpp_stl_runtime_BUILD_TESTS OFF CACHE INTERNAL + "Disable tests in katai_struct_cpp_stl build" FORCE) + +FetchContent_Declare( + kaitai_struct_cpp_stl_runtime + GIT_REPOSITORY https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime.git + GIT_TAG ${KSCSR_VERSION} + GIT_SHALLOW ON + FIND_PACKAGE_ARGS +) + +FetchContent_MakeAvailable(kaitai_struct_cpp_stl_runtime) + +# Check kaitai-struct-compiler version +execute_process( + COMMAND bash -c "kaitai-struct-compiler --version | awk '{ print $2 }'" + OUTPUT_VARIABLE KSC_VERSION +) + +if(NOT ${KSC_VERSION} STREQUAL ${KSCSR_VERSION}) + message(FATAL "kaitai-struct-compiler version ${KSC_VERSION} does not match kaitai_struct_cpp_stl_runtime-struct version ${KSCSR_VERSION}") +endif() + +# Convenient link to the directory containing the ksy files +set(TEMPLATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tablestream/templates) + +# Generate the cpp files from metadata.ksy +add_custom_command(OUTPUT dtype.cpp metadata.cpp VERBATIM + DEPENDS ${TEMPLATE_DIR}/metadata.ksy + COMMAND kaitai-struct-compiler -t cpp_stl --cpp-standard=11 + ${TEMPLATE_DIR}/metadata.ksy +) + +add_executable(test-cpp dtype.cpp metadata.cpp test.cpp) +target_include_directories(test-cpp PRIVATE ${kaitai_struct_cpp_stl_runtime_SOURCE_DIR}) +target_link_libraries(test-cpp PRIVATE kaitai_struct_cpp_stl_runtime) +# Allows compilation to go further, but these should be fixed +target_compile_options(test-cpp PRIVATE + $<$:-fpermissive> + $<$:-fpermissive> +) \ No newline at end of file diff --git a/ci/cpp/test.cpp b/ci/cpp/test.cpp new file mode 100644 index 0000000..8b65d46 --- /dev/null +++ b/ci/cpp/test.cpp @@ -0,0 +1,5 @@ +#include + +int main(int argc, char * argv[]) { + return 0; +} \ No newline at end of file From dbfdd5457e0e34a3024b3f779022a44c3912d2d4 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Wed, 23 Oct 2024 14:28:34 +0200 Subject: [PATCH 2/9] Add a README.rst --- ci/cpp/README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ci/cpp/README.rst diff --git a/ci/cpp/README.rst b/ci/cpp/README.rst new file mode 100644 index 0000000..e0a11d5 --- /dev/null +++ b/ci/cpp/README.rst @@ -0,0 +1,8 @@ +# C++ test case + +Basic test case testing that generated C++ code compiles and links. + +.. code-block:: bash + + $ cmake -S . -B build + $ cmake --build build \ No newline at end of file From 6106f65aea079cc6920b48da96a1538a67134709 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 08:34:12 +0200 Subject: [PATCH 3/9] Fix downloaded .deb install --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 47b6d65..93e476a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: - name: Install kaitai-struct-compiler run: | curl -LO https://github.com/kaitai-io/kaitai_struct_compiler/releases/download/0.10/kaitai-struct-compiler_0.10_all.deb - sudo apt install kaitai-struct-compiler_0.10_all.deb + sudo apt install ./kaitai-struct-compiler_0.10_all.deb - name: Build C++ test executable run: | From a7fdafe1543e72266e57d17176ff4db501c7b2cc Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 08:50:00 +0200 Subject: [PATCH 4/9] Fix type in install --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 93e476a..a5c33cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - name: Install compiler - run: sudo apt install cmake build-essential + run: sudo apt install cmake build-essentials # The version here should match the one in ci/cpp/CMakeLists.txt - name: Install kaitai-struct-compiler From ca940410131628ef1ce57cb31f03087009f4f5f9 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 08:51:39 +0200 Subject: [PATCH 5/9] Update compiler install --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5c33cb..a275791 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,9 @@ jobs: - uses: actions/checkout@v4 - name: Install compiler - run: sudo apt install cmake build-essentials + run: | + sudo apt update -y + sudo apt install -y cmake build-essential # The version here should match the one in ci/cpp/CMakeLists.txt - name: Install kaitai-struct-compiler From 6ef7b868df29b8a17a81fa68e1a6b7a26c5cdeb2 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 09:02:34 +0200 Subject: [PATCH 6/9] Install a recent version of cmake --- .github/workflows/main.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a275791..e2d5da6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,10 +23,16 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install compiler + # Need for a recent version of cmake + - name: Install kitware cmake archive + run: | + curl -LO https://apt.kitware.com/kitware-archive.sh + bash kitware-archive.sh + + - name: Install compiler and cmake run: | sudo apt update -y - sudo apt install -y cmake build-essential + sudo apt install -y build-essential cmake # The version here should match the one in ci/cpp/CMakeLists.txt - name: Install kaitai-struct-compiler From f4c61e58fd7c0b679abb2180ad3d082eb2ca3190 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 09:03:01 +0200 Subject: [PATCH 7/9] sudo apt install -y ./kaitai-struct-compiler_0.10_all.deb --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e2d5da6..6ac5843 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,7 @@ jobs: - name: Install kaitai-struct-compiler run: | curl -LO https://github.com/kaitai-io/kaitai_struct_compiler/releases/download/0.10/kaitai-struct-compiler_0.10_all.deb - sudo apt install ./kaitai-struct-compiler_0.10_all.deb + sudo apt install -y ./kaitai-struct-compiler_0.10_all.deb - name: Build C++ test executable run: | From a5e8410042bdb82318c22cc4cae062123c1432e5 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 09:25:39 +0200 Subject: [PATCH 8/9] Generate more cpp files from the ksy --- ci/cpp/CMakeLists.txt | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/ci/cpp/CMakeLists.txt b/ci/cpp/CMakeLists.txt index 822e72f..1b0aea0 100644 --- a/ci/cpp/CMakeLists.txt +++ b/ci/cpp/CMakeLists.txt @@ -32,16 +32,36 @@ endif() # Convenient link to the directory containing the ksy files set(TEMPLATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tablestream/templates) -# Generate the cpp files from metadata.ksy +# Generate the cpp files from the various ksy files add_custom_command(OUTPUT dtype.cpp metadata.cpp VERBATIM - DEPENDS ${TEMPLATE_DIR}/metadata.ksy - COMMAND kaitai-struct-compiler -t cpp_stl --cpp-standard=11 - ${TEMPLATE_DIR}/metadata.ksy + DEPENDS ${TEMPLATE_DIR}/metadata.ksy + COMMAND kaitai-struct-compiler -t cpp_stl --cpp-standard=11 + ${TEMPLATE_DIR}/metadata.ksy ) -add_executable(test-cpp dtype.cpp metadata.cpp test.cpp) -target_include_directories(test-cpp PRIVATE ${kaitai_struct_cpp_stl_runtime_SOURCE_DIR}) -target_link_libraries(test-cpp PRIVATE kaitai_struct_cpp_stl_runtime) +add_custom_command(OUTPUT lock.cpp VERBATIM + DEPENDS ${TEMPLATE_DIR}/lock.ksy + COMMAND kaitai-struct-compiler -t cpp_stl --cpp-standard=11 + ${TEMPLATE_DIR}/lock.ksy +) + +add_custom_command(OUTPUT standard_storage_manager.cpp VERBATIM + DEPENDS ${TEMPLATE_DIR}/standard_storage_manager.ksy + COMMAND kaitai-struct-compiler -t cpp_stl --cpp-standard=11 + ${TEMPLATE_DIR}/standard_storage_manager.ksy +) + +add_executable(test-cpp + dtype.cpp + lock.cpp + metadata.cpp + standard_storage_manager.cpp + test.cpp) + +target_include_directories(test-cpp + PRIVATE ${kaitai_struct_cpp_stl_runtime_SOURCE_DIR}) +target_link_libraries(test-cpp + PRIVATE kaitai_struct_cpp_stl_runtime) # Allows compilation to go further, but these should be fixed target_compile_options(test-cpp PRIVATE $<$:-fpermissive> From 5c728f1cf87436fd2b0be946e535c035b45a74f2 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Tue, 5 Nov 2024 17:25:35 +0200 Subject: [PATCH 9/9] sudo bash kitware-archive.sh --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ac5843..228f6ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: - name: Install kitware cmake archive run: | curl -LO https://apt.kitware.com/kitware-archive.sh - bash kitware-archive.sh + sudo bash kitware-archive.sh - name: Install compiler and cmake run: |