Skip to content

Commit 56db034

Browse files
committed
CI: Add separate job for CPython Interop tests
1 parent eadd0f9 commit 56db034

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

.github/workflows/CI.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,46 @@ jobs:
290290
cd integration_tests
291291
./run_tests.py -b llvm
292292
./run_tests.py -b c
293+
294+
cpython_interop:
295+
name: Test CPython Interop (@pythoncall)
296+
runs-on: ubuntu-latest
297+
steps:
298+
- uses: actions/checkout@v3
299+
with:
300+
fetch-depth: 0
301+
302+
- uses: mamba-org/setup-micromamba@v1
303+
with:
304+
environment-file: ci/environment.yml
305+
create-args: >-
306+
python=3.10
307+
bison=3.4
308+
309+
- uses: hendrikmuhs/ccache-action@main
310+
with:
311+
variant: sccache
312+
key: ${{ github.job }}-${{ matrix.os }}
313+
314+
- name: Build Linux
315+
shell: bash -l {0}
316+
run: |
317+
./build0.sh
318+
cmake . -GNinja \
319+
-DCMAKE_BUILD_TYPE=Debug \
320+
-DWITH_LLVM=yes \
321+
-DLFORTRAN_BUILD_ALL=yes \
322+
-DWITH_STACKTRACE=no \
323+
-DWITH_RUNTIME_STACKTRACE=yes \
324+
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
325+
-DCMAKE_INSTALL_PREFIX=`pwd`/inst \
326+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
327+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
328+
329+
cmake --build . -j16 --target install
330+
331+
- name: Test Linux
332+
shell: bash -l {0}
333+
run: |
334+
cd integration_tests
335+
./run_tests.py -b cpython_py c_py

integration_tests/CMakeLists.txt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,25 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN
113113
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR})
114114
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
115115
target_link_libraries(${name} lpython_rtlib)
116-
if (run_enable_cpython)
117-
target_include_directories(${name} PRIVATE ${NUMPY_INCLUDE_DIR})
118-
target_link_libraries(${name} Python::Python)
119-
if (extra_files)
120-
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${extra_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
121-
endif()
116+
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
117+
if (labels)
118+
set_tests_properties(${name} PROPERTIES LABELS "${labels}")
119+
endif()
120+
if (${fail})
121+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
122+
endif()
123+
elseif(KIND STREQUAL "c_py")
124+
add_custom_command(
125+
OUTPUT ${name}.c
126+
COMMAND ${LPYTHON} ${extra_args} --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c
127+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py
128+
VERBATIM)
129+
add_executable(${name} ${name}.c ${extra_files})
130+
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR} ${NUMPY_INCLUDE_DIR})
131+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
132+
target_link_libraries(${name} lpython_rtlib Python::Python)
133+
if (extra_files)
134+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${extra_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
122135
endif()
123136
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
124137
if (labels)
@@ -127,7 +140,7 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN
127140
if (${fail})
128141
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
129142
endif()
130-
elseif(KIND STREQUAL "cpython")
143+
elseif((KIND STREQUAL "cpython") OR (KIND STREQUAL "cpython_py"))
131144
# CPython test
132145
if (extra_files)
133146
set(PY_MOD "${name}_mod")
@@ -254,7 +267,7 @@ macro(RUN)
254267
if ((NOT DISABLE_FAST) AND (NOT RUN_NOFAST))
255268
set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} --fast)
256269
set(RUN_NAME "${RUN_NAME}_FAST")
257-
list(REMOVE_ITEM RUN_LABELS cpython) # remove cpython from --fast test
270+
list(REMOVE_ITEM RUN_LABELS cpython cpython_py) # remove cpython, cpython_py from --fast test
258271
RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS)
259272
endif()
260273
endmacro(RUN)
@@ -492,8 +505,8 @@ RUN(NAME bindc_05 LABELS llvm c
492505
EXTRAFILES bindc_05b.c)
493506
RUN(NAME bindc_06 LABELS llvm c
494507
EXTRAFILES bindc_06b.c)
495-
RUN(NAME bindpy_01 LABELS cpython c ENABLE_CPYTHON NOFAST EXTRAFILES bindpy_01_module.py)
496-
RUN(NAME bindpy_02 LABELS cpython c LINK_NUMPY EXTRAFILES bindpy_02_module.py)
508+
RUN(NAME bindpy_01 LABELS cpython_py c_py ENABLE_CPYTHON NOFAST EXTRAFILES bindpy_01_module.py)
509+
RUN(NAME bindpy_02 LABELS cpython_py c_py LINK_NUMPY EXTRAFILES bindpy_02_module.py)
497510
RUN(NAME test_generics_01 LABELS cpython llvm c NOFAST)
498511
RUN(NAME test_cmath LABELS cpython llvm c NOFAST)
499512
RUN(NAME test_complex_01 LABELS cpython llvm c wasm wasm_x64)

integration_tests/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Initialization
88
DEFAULT_THREADS_TO_USE = 8 # default no of threads is 8
9-
SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64']
9+
SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64', 'c_py', 'cpython_py']
1010
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
1111
LPYTHON_PATH = f"{BASE_DIR}/../src/bin"
1212

0 commit comments

Comments
 (0)