Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,51 @@ jobs:
- name: Build release
run: cargo build --workspace --release --verbose

cmake:
name: CMake Integration
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install aarch64 cross toolchain
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-gnu

# `crates/spacewasm_c_api/README.md` documents consuming the crate through
# `add_subdirectory()`, but nothing in CI configures it. The fixture builds
# the same two C programs `spacewasm_c_example` already drives through
# cargo, so the CMake path gets covered without new test code. Both embed
# their module bytes, so unlike the rest of the suite this needs no WABT.
- name: Build and run the documented integration
run: |
cmake -S crates/spacewasm_c_api/tests/cmake -B target/cmake/native \
-DCMAKE_BUILD_TYPE=Debug
cmake --build target/cmake/native -j"$(nproc)"
./target/cmake/native/ctest
./target/cmake/native/ctest_suite

# A cross build has to forward the Rust target explicitly. Without
# `SPACEWASM_TARGET` cargo still produces a host archive and the link fails
# with "file in wrong format", so assert the emitted ELF is AArch64.
- name: Cross-compile to aarch64
run: |
cmake -S crates/spacewasm_c_api/tests/cmake -B target/cmake/aarch64 \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DSPACEWASM_TARGET=aarch64-unknown-linux-gnu
cmake --build target/cmake/aarch64 -j"$(nproc)"
readelf -h target/cmake/aarch64/ctest | grep -q AArch64

benchmark:
name: Benchmark
runs-on: ubuntu-latest
Expand Down
21 changes: 21 additions & 0 deletions crates/spacewasm_c_api/tests/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
####
# CMake integration fixture.
#
# Consumes `spacewasm_c_api` exactly the way `crates/spacewasm_c_api/README.md`
# tells an integrator to: `add_subdirectory()` plus a link against `spacewasm`.
# The programs built here are the same ones `spacewasm_c_example`'s `c_abi.rs`
# drives through cargo, so this adds coverage of the CMake path without adding
# test code. Both are self-contained (module bytes are embedded, no file I/O),
# so unlike the rest of the suite this needs no WABT.
####
cmake_minimum_required(VERSION 3.12)
project(spacewasm_cmake_integration C)

add_subdirectory(../.. spacewasm_c_api)

set(SPACEWASM_C_EXAMPLES ${CMAKE_CURRENT_SOURCE_DIR}/../../../spacewasm_c_example/examples)

foreach(prog ctest ctest_suite)
add_executable(${prog} ${SPACEWASM_C_EXAMPLES}/${prog}.c)
target_link_libraries(${prog} PRIVATE spacewasm)
endforeach()