This commit is contained in:
BLUELOVETH 2023-07-07 17:41:48 +08:00
parent 549ed0c5f1
commit cf2fe7236d
3 changed files with 34 additions and 22 deletions

View File

@ -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:

24
c_bindings/CMakeLists.txt Normal file
View File

@ -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
)

View File

@ -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