Skip to content

Commit ac25aa1

Browse files
committed
[ci] Add Rust CI and coverage build
1 parent 08aa32f commit ac25aa1

5 files changed

Lines changed: 54 additions & 11 deletions

File tree

.github/workflows/linux.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ jobs:
122122
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules origin main
123123
echo "cache-key=$( git merge-base origin/main ${{ github.sha }} )" >> $GITHUB_OUTPUT
124124
125+
- name: Set up Rust
126+
uses: dtolnay/rust-toolchain@stable
127+
128+
- name: Rust Cache
129+
uses: swatinem/rust-cache@v2
130+
with:
131+
# This ensures that if you have a workspace,
132+
# all crates are indexed in the cache.
133+
workspaces: "$GITHUB_WORKSPACE/rxx"
134+
125135
- name: CCache
126136
uses: actions/cache@v5
127137
with:
@@ -138,6 +148,9 @@ jobs:
138148
mkdir --parents ${MULTIPASS_PART}
139149
/snap/bin/lxc profile device add default build disk source=${MULTIPASS_PART} path=/root/parts/multipass
140150
echo "build=${MULTIPASS_PART}/build" >> $GITHUB_OUTPUT
151+
if ! command -v cargo-tarpaulin &> /dev/null; then
152+
cargo install cargo-tarpaulin
153+
fi
141154
142155
- name: Configure
143156
run: |
@@ -182,10 +195,11 @@ jobs:
182195
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c 'mkdir -p /coredump'
183196
# Enable coredumps by setting the core dump size to "unlimited", and run the tests.
184197
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c "\
198+
cd /root/parts/multipass/build && \
185199
ulimit -c unlimited && \
186200
env CTEST_OUTPUT_ON_FAILURE=1 \
187-
LD_LIBRARY_PATH=/root/stage/usr/lib/x86_64-linux-gnu/:/root/stage/lib/:/root/parts/multipass/build/lib/ \
188-
/root/parts/multipass/build/bin/multipass_tests"
201+
LD_LIBRARY_PATH=/root/stage/usr/lib/x86_64-linux-gnu/:/root/stage/lib/:/root/parts/multipass/build/lib/ \
202+
ctest"
189203
190204
- name: Measure coverage
191205
id: measure-coverage
@@ -249,6 +263,10 @@ jobs:
249263
# Pull the coredump folder
250264
/snap/bin/lxc --project snapcraft file pull -p -r "$instance_name/coredump" /tmp/coredump
251265
echo "Pulled the coredumps folder."
266+
mapfile -t BINS < <(cargo test --workspace --no-run --message-format=json | jq -r 'select(.reason == "compiler-artifact" and .executable != null) | .executable')
267+
export TEST_BINARIES="${BINS[*]}"
268+
for bin $TEST_BINARIES; do /snap/bin/lxc --project snapcraft file pull -p -r "$instance_name/$bin" /tmp/coredump/$bin
269+
echo "Pulled the rust executables"
252270
set +o xtrace
253271
254272
- name: Upload test coredump

.github/workflows/windows-macos.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ jobs:
123123
mkdir -p ~/.pip
124124
echo -e "[install]\nbreak-system-packages = true" > ~/.pip/pip.conf
125125
126+
- name: Set up Rust
127+
uses: dtolnay/rust-toolchain@stable
128+
126129
- name: Install dependencies from brew
127130
if: ${{ runner.os == 'macOS' }}
128131
run: |
@@ -278,7 +281,7 @@ jobs:
278281
- name: Test
279282
working-directory: ${{ env.BUILD_DIR }}
280283
run: |
281-
bin/multipass_tests
284+
ctest
282285
283286
- name: Package
284287
id: cmake-package

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ if(cmake_build_type_lower MATCHES "coverage")
394394
endif()
395395

396396
add_custom_target(covreport
397-
DEPENDS multipass_tests
397+
DEPENDS multipass_tests rust_coverage_tarpaulin
398398
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
399399
COMMAND ${LCOV} --directory . --zerocounters
400400
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test
@@ -407,7 +407,9 @@ if(cmake_build_type_lower MATCHES "coverage")
407407
${CMAKE_BINARY_DIR}'/*'
408408
--output-file coverage.cleaned
409409
COMMAND ${CMAKE_COMMAND} -E remove coverage.info
410-
COMMAND ${GENHTML} -o coverage coverage.cleaned
410+
COMMAND ${CMAKE_COMMAND} -E remove coverage.info
411+
COMMAND ${LCOV} -a coverage.cleaned -a lcov.info -o total_coverage.info
412+
COMMAND ${GENHTML} -o coverage total_coverage.info
411413
)
412414
endif()
413415
endif()

rxx/CMakeLists.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ foreach(crate_name ${CRATES})
6767
set(bridge_source "${CMAKE_CURRENT_SOURCE_DIR}/target/cxxbridge/${crate_name}/src")
6868
set(bridge_cc "${bridge_source}/lib.rs.cc")
6969

70+
set(ACTIVE_FEATURES "default")
7071
#Library creation to compile the CXX glue source
7172
add_library(${crate_name} STATIC ${bridge_cc})
7273
#Here we can place the crate-wise dependencies
@@ -78,17 +79,33 @@ foreach(crate_name ${CRATES})
7879

7980
add_custom_command(
8081
OUTPUT ${bridge_cc} ${rust_out}
81-
COMMAND ${CARGO_EXECUTABLE} build -p ${crate_name} ${rust_build_flag} --lib
82+
COMMAND ${CARGO_EXECUTABLE} build -p ${crate_name} ${rust_build_flag} --lib --features "${ACTIVE_FEATURES}"
8283
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
8384
COMMENT "Building Rust crates and generating C++ glue..."
8485
)
8586

86-
add_test(
87-
NAME ${crate_name}_tests
88-
COMMAND cargo test -p ${crate_name} --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml
89-
--no-fail-fast
90-
)
9187
endif()
9288
endforeach()
9389

90+
add_test(
91+
NAME multipass_rust_tests
92+
COMMAND cargo test --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml
93+
--no-fail-fast --workspace --all-features
94+
)
9495
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/target")
96+
97+
if(cmake_build_type_lower MATCHES "coverage")
98+
find_program(CARGO_TARPAULIN cargo-tarpaulin)
99+
100+
if(CARGO_TARPAULIN)
101+
add_custom_target(rust_coverage_tarpaulin
102+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
103+
COMMAND ${CARGO_TARPAULIN}
104+
--out Lcov
105+
--output-dir ${CMAKE_BUILD_DIR}
106+
--exclude-files '../*'
107+
COMMAND
108+
COMMENT "Running Rust coverage with Tarpaulin"
109+
)
110+
endif()
111+
endif()

rxx/petname/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ rust-version.workspace = true
2323
[lib]
2424
crate-type = ["staticlib"]
2525

26+
[features]
27+
default = []
28+
2629
[dependencies]
2730
cxx.workspace = true
2831
macros.workspace = true

0 commit comments

Comments
 (0)