Skip to content

Commit 30618c3

Browse files
authored
build+ci: Use cmake presets (#4)
* build+ci: Use cmake presets * ci: add ccache
1 parent c739c20 commit 30618c3

File tree

8 files changed

+107
-33
lines changed

8 files changed

+107
-33
lines changed

.github/workflows/premerge.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [ "main" ]
66

77
env:
8-
BUILD_TYPE: Release
8+
CMAKE_PRESET: release
99

1010
jobs:
1111
build:
@@ -25,13 +25,21 @@ jobs:
2525
sudo ./llvm.sh 20
2626
sudo apt install libmlir-20-dev mlir-20-tools
2727
28+
- name: ccache
29+
uses: hendrikmuhs/ccache-action@v1.2
30+
with:
31+
create-symlink: true
32+
2833
- name: Configure CMake
29-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_CACHE=OFF
34+
run: cmake --preset ${{env.CMAKE_PRESET}}
3035

3136
- name: Build
32-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
37+
run: cmake --build --preset ${{env.CMAKE_PRESET}}
3338

3439
- name: Test
35-
working-directory: ${{github.workspace}}/build
36-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target test
40+
run: |
41+
ctest --preset ${{env.CMAKE_PRESET}} -E integration-tests
42+
# only run the integration-tests with verbose so we can see the
43+
# whole output which includes which python scripts passed
44+
ctest --preset ${{env.CMAKE_PRESET}} -R integration-tests -V
3745

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__/
22
build/
3+
.cache/

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ repos:
22
- repo: https://github.com/pre-commit/mirrors-clang-format
33
rev: 'v20.1.8'
44
hooks:
5-
- id: clang-format
5+
- id: clang-format
6+
types_or: [c++, c]

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ if(NOT MATH_LIBRARY)
8888
message(FATAL_ERROR "Could not find math library")
8989
endif()
9090

91+
enable_testing()
9192
add_subdirectory(src)
9293
add_subdirectory(integration)
93-
94-
add_custom_target(test)
95-
add_dependencies(test run-unittests integration-tests)

CMakePresets.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "debug",
6+
"displayName": "Debug",
7+
"generator": "Ninja",
8+
"binaryDir": "build/debug",
9+
"cacheVariables": {
10+
"CMAKE_BUILD_TYPE": "Debug",
11+
"CPM_SOURCE_CACHE": ".cache/CPM"
12+
}
13+
},
14+
{
15+
"name": "release",
16+
"displayName": "Release",
17+
"generator": "Ninja",
18+
"binaryDir": "build/release",
19+
"cacheVariables": {
20+
"CMAKE_BUILD_TYPE": "Release",
21+
"CPM_SOURCE_CACHE": ".cache/CPM"
22+
}
23+
}
24+
],
25+
"buildPresets": [
26+
{
27+
"name": "debug",
28+
"displayName": "Debug Build",
29+
"configurePreset": "debug",
30+
"configuration": "Debug"
31+
},
32+
{
33+
"name": "release",
34+
"displayName": "Release Build",
35+
"configurePreset": "release",
36+
"configuration": "Release"
37+
}
38+
],
39+
"testPresets": [
40+
{
41+
"name": "debug",
42+
"displayName": "Test all in Debug mode",
43+
"configurePreset": "debug"
44+
},
45+
{
46+
"name": "release",
47+
"displayName": "Test all in Release mode",
48+
"configurePreset": "release"
49+
}
50+
]
51+
52+
}

integration/CMakeLists.txt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
include(GoogleTest)
2-
31
add_executable(integration-tests_ program.cpp ../src/testing/main.cpp)
42
target_link_libraries(integration-tests_ PRIVATE python-cpp gtest gtest_main cxxopts project_options project_warnings tsl::ordered_map)
5-
# gtest_add_tests(TARGET integration-tests_)
3+
# gtest_discover_tests(integration-tests_)
4+
5+
add_test(
6+
NAME integration-tests
7+
COMMAND ${PROJECT_SOURCE_DIR}/integration/run_integration_tests.sh $<TARGET_FILE:python>
8+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/integration
9+
)
10+
11+
# Ensure the test only runs after the required targets are built
12+
set_tests_properties(integration-tests PROPERTIES
13+
FIXTURES_REQUIRED "python_built"
14+
)
615

7-
# cmake-format: off
8-
add_custom_target(
9-
integration-tests
10-
COMMAND # $<TARGET_FILE:integration-tests_>
11-
echo "------------------------"
12-
&& echo "Running python scripts:"
13-
&& echo "------------------------"
14-
&& echo ""
15-
&& $<TARGET_FILE:python> ${PROJECT_SOURCE_DIR}/integration/fibonacci/main.py --gc-frequency 1
16-
&& $<TARGET_FILE:python> ${PROJECT_SOURCE_DIR}/integration/mandelbrot/mandelbrot.py --gc-frequency 1
17-
&& ${PROJECT_SOURCE_DIR}/integration/run_python_tests.sh $<TARGET_FILE:python>
18-
&& echo ""
19-
&& echo "------------------------"
20-
&& echo "Testing LLVM backend:"
21-
&& echo "------------------------"
22-
&& echo ""
23-
&& ${PROJECT_SOURCE_DIR}/integration/run_llvm_python_tests.sh $<TARGET_FILE:python>
24-
DEPENDS integration-tests_ python)
25-
# cmake-format: on
16+
# Add a setup test that depends on building python
17+
add_test(NAME setup-python COMMAND ${CMAKE_COMMAND} -E echo "Python built")
18+
set_tests_properties(setup-python PROPERTIES
19+
FIXTURES_SETUP "python_built"
20+
DEPENDS python # This may not work in all CMake versions
21+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e # Exit on any error
3+
4+
echo "------------------------"
5+
echo "Running python scripts:"
6+
echo "------------------------"
7+
echo ""
8+
9+
"$1" fibonacci/main.py --gc-frequency 1
10+
"$1" mandelbrot/mandelbrot.py --gc-frequency 1
11+
./run_python_tests.sh "$1"
12+
13+
echo ""
14+
echo "------------------------"
15+
echo "Testing LLVM backend:"
16+
echo "------------------------"
17+
echo ""
18+
19+
./run_llvm_python_tests.sh "$1"

src/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ elseif(ENABLE_LLVM_BACKEND AND LLVM_FOUND)
349349
endif()
350350

351351
target_link_libraries(unittests_ PRIVATE python-cpp gtest gtest_main cxxopts project_options project_warnings tsl::ordered_map)
352-
set_target_properties(unittests_ PROPERTIES OUTPUT_NAME "unittests")
353-
add_custom_target(run-unittests COMMAND $<TARGET_FILE:unittests_> DEPENDS unittests_)
352+
gtest_discover_tests(unittests_)
354353

355354
add_executable(python repl/repl.cpp)
356355
target_link_libraries(python PRIVATE linenoise cxxopts python-cpp project_options project_warnings stdc++)

0 commit comments

Comments
 (0)