diff --git a/.github/workflows/ci-reusable.yml b/.github/workflows/ci-reusable.yml index 7dd08a44..7121786a 100644 --- a/.github/workflows/ci-reusable.yml +++ b/.github/workflows/ci-reusable.yml @@ -63,6 +63,11 @@ jobs: path: tests/integration/logs/ retention-days: 1 + ## Part 3 Tests ## + - name: Libstorage tests + if: matrix.tests == 'libstorage' || matrix.tests == 'all' + run: make -j${ncpu} testLibstorage + status: if: always() needs: [build] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef35dc0d..e64d05b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,29 +85,3 @@ jobs: name: codecov-umbrella token: ${{ secrets.CODECOV_TOKEN }} verbose: true - - cbinding: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - with: - submodules: recursive - ref: ${{ github.event.pull_request.head.sha }} - - - name: Setup Nimbus Build System - uses: ./.github/actions/nimbus-build-system - with: - os: linux - nim_version: ${{ env.nim_version }} - - - name: C Binding build - run: | - make -j${ncpu} update - make -j${ncpu} libstorage - - - name: C Binding test - run: | - cd examples/c - gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread - LD_LIBRARY_PATH=../../build ./storage diff --git a/.gitignore b/.gitignore index c4aa0d4d..78030176 100644 --- a/.gitignore +++ b/.gitignore @@ -48,5 +48,5 @@ tests/integration/logs data/ -examples/c/data-dir -examples/c/downloaded_hello.txt +tests/cbindings/data-dir +tests/cbindings/downloaded_hello.txt diff --git a/Makefile b/Makefile index b4fe4883..c60c5eb6 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,9 @@ endif deps \ libbacktrace \ test \ + testAll \ + testIntegration \ + testLibstorage \ update ifeq ($(NIM_PARAMS),) @@ -144,10 +147,23 @@ testIntegration: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim testIntegration $(TEST_PARAMS) $(NIM_PARAMS) --define:ws_resubscribe=240 build.nims -# Builds and runs all tests (except for Taiko L2 tests) +# Builds a C example that uses the libstorage C library and runs it +testLibstorage: | build deps + $(MAKE) $(if $(ncpu),-j$(ncpu),) libstorage + cd tests/cbindings && \ + if [ "$(detected_OS)" = "Windows" ]; then \ + gcc -o storage.exe storage.c -L../../build -lstorage -pthread && \ + PATH=../../build:$$PATH ./storage.exe; \ + else \ + gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread && \ + LD_LIBRARY_PATH=../../build ./storage; \ + fi + +# Builds and runs all tests testAll: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim testAll $(NIM_PARAMS) build.nims + $(MAKE) $(if $(ncpu),-j$(ncpu),) testLibstorage # nim-libbacktrace LIBBACKTRACE_MAKE_FLAGS := -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0 diff --git a/README.md b/README.md index 346ddfdf..9575e2eb 100644 --- a/README.md +++ b/README.md @@ -67,23 +67,7 @@ This produces the shared library under `build/`. ### Run the Go example -Build the Go example: - -```bash -go build -o storage-go examples/golang/storage.go -``` - -Export the library path: - -```bash -export LD_LIBRARY_PATH=build -``` - -Run the example: - -```bash -./storage-go -``` +See https://github.com/logos-storage/logos-storage-go-bindings-example. ### Static vs Dynamic build diff --git a/examples/c/hello_world.txt b/tests/cbindings/hello_world.txt similarity index 100% rename from examples/c/hello_world.txt rename to tests/cbindings/hello_world.txt diff --git a/examples/c/storage.c b/tests/cbindings/storage.c similarity index 98% rename from examples/c/storage.c rename to tests/cbindings/storage.c index c7d2d4ad..5f81d2e7 100644 --- a/examples/c/storage.c +++ b/tests/cbindings/storage.c @@ -6,6 +6,19 @@ #include #include "../../library/libstorage.h" +/* Provide realpath on Windows (not available on some MSVC/MinGW setups) */ +#if defined(_WIN32) || defined(_WIN64) +#include +#if defined(_MSC_VER) +#include +#define realpath(N,R) _fullpath((R),(N),_MAX_PATH) +#else +/* MinGW / other Windows gcc: map to _fullpath using PATH_MAX */ +#include +#define realpath(N,R) _fullpath((R),(N),PATH_MAX) +#endif +#endif + // We need 250 as max retries mainly for the start function in CI. // Other functions should be not need that many retries. #define MAX_RETRIES 250 diff --git a/tools/scripts/ci-job-matrix.sh b/tools/scripts/ci-job-matrix.sh index 28734fbc..e55968bf 100755 --- a/tools/scripts/ci-job-matrix.sh +++ b/tools/scripts/ci-job-matrix.sh @@ -109,10 +109,19 @@ integration_test () { fi } + +# outputs a libstorage test job +libstorage_test () { + job_tests="libstorage" + job_includes="" + job +} + # outputs jobs for all test types all_tests () { unit_test integration_test + libstorage_test } # outputs jobs for the specified operating systems and all test types