diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 681e6228..c630b10b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,8 +63,8 @@ jobs: run: python3 scripts/run_tests.py benchmark # - name: GCC Build Test # run: g++ -o pocketpy --std=c++17 src/main.cpp - # - name: C Binding Test - # run: bash run_c_binding_test.sh + - name: C Binding Test + run: bash run_c_binding_test.sh build_macos: runs-on: macos-latest steps: diff --git a/c_bindings/CMakeLists.txt b/c_bindings/CMakeLists.txt new file mode 100644 index 00000000..21c1783b --- /dev/null +++ b/c_bindings/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.17) + +project(test_c_bindings) + +set(CMAKE_C_STANDARD 11) + +option(PK_EXPORT_C_API "Export C API" ON) +option(PK_BUILD_STATIC_LIB "Build static library" ON) + +add_subdirectory( + ${CMAKE_CURRENT_LIST_DIR}/../ + ${CMAKE_CURRENT_LIST_DIR}/build/pocketpy/ +) + +include_directories( + ${CMAKE_CURRENT_LIST_DIR}/../include +) + +add_executable(${PROJECT_NAME} test.c) + +target_link_libraries( + ${PROJECT_NAME} + pocketpy +) \ No newline at end of file diff --git a/run_c_binding_test.sh b/run_c_binding_test.sh index 20f75207..54f5f5b4 100644 --- a/run_c_binding_test.sh +++ b/run_c_binding_test.sh @@ -1,26 +1,14 @@ -python3 preprocess.py +cd c_bindings +mkdir build +cd build +cmake .. +cmake --build . --config Release -echo "compiling c++ lib" -clang++ -c -o pocketpy_c.o c_bindings/pocketpy_c.cpp -Wfatal-errors -O1 --std=c++17 -Wall -Wno-sign-compare -Wno-unused-variable -fno-rtti -stdlib=libc++ -I src/ -g - -echo "compiling c executable" -clang -c -o test.o c_bindings/test.c -Wfatal-errors -Wall -O1 -Wno-sign-compare -Wno-unused-variable -I src/ -g -echo "linking" -clang++ -o c_binding_test test.o pocketpy_c.o -stdlib=libc++ -g -./c_binding_test > binding_test_scratch +./test_c_bindings > binding_test_scratch echo "checking results (they should be identical)" -diff -q -s binding_test_scratch c_bindings/test_answers.txt +diff -q -s binding_test_scratch ../test_answers.txt if [ $? -eq 1 ] then echo "ERROR: c binding test failed" - rm pocketpy_c.o - rm test.o exit 1 -fi - -echo "cleaning up" -rm pocketpy_c.o -rm test.o -rm binding_test_scratch -rm c_binding_test - +fi \ No newline at end of file