Skip to content

Commit 0a4e36c

Browse files
authored
chore(test): add nix check and ci tests (#6)
1 parent e73ace0 commit 0a4e36c

File tree

7 files changed

+433
-103
lines changed

7 files changed

+433
-103
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
merge_group:
9+
workflow_dispatch:
10+
11+
jobs:
12+
flake-check:
13+
name: ${{ matrix.name }}
14+
runs-on: ${{ matrix.runner }}
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
# Linux
21+
- name: Linux (x86_64-linux)
22+
runner: ubuntu-latest
23+
system: x86_64-linux
24+
qemu: false
25+
26+
- name: Linux (aarch64-linux)
27+
runner: ubuntu-latest
28+
system: aarch64-linux
29+
qemu: true
30+
31+
# macOS
32+
- name: macOS (aarch64-darwin)
33+
runner: macos-latest
34+
system: aarch64-darwin
35+
qemu: false
36+
macos_target: 11.3
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
42+
- name: Install Nix
43+
uses: DeterminateSystems/nix-installer-action@v12
44+
45+
- name: Configure Nix
46+
shell: bash
47+
run: |
48+
mkdir -p ~/.config/nix
49+
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
50+
51+
- name: Setup QEMU
52+
if: matrix.qemu == true
53+
uses: docker/setup-qemu-action@v3
54+
55+
- name: Setup Cachix
56+
if: runner.os != 'Windows'
57+
uses: cachix/cachix-action@v15
58+
with:
59+
name: nix-community
60+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
61+
continue-on-error: true
62+
63+
- name: Run flake checks
64+
shell: bash
65+
run: |
66+
nix flake check --system ${{ matrix.system }}
67+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ dkms.conf
5858
build/
5959
vendor/build/
6060
result
61+
62+
# cmake
63+
CMakeCache.txt
64+
CMakeFiles/
65+

CMakeLists.txt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,50 @@ endif()
1616
# Define the module
1717
logos_module(
1818
NAME libp2p_module
19-
SOURCES
19+
SOURCES
2020
src/libp2p_module_interface.h
2121
src/libp2p_module_plugin.h
2222
src/libp2p_module_plugin.cpp
2323
EXTERNAL_LIBS
2424
libp2p
25+
INCLUDE_DIRS
26+
${CMAKE_CURRENT_SOURCE_DIR}/include
2527
)
28+
29+
enable_testing()
30+
31+
find_package(Qt6 REQUIRED COMPONENTS Core Test)
32+
33+
logos_find_dependencies()
34+
35+
add_executable(test_libp2p_module
36+
tests/test_libp2p_module.cpp
37+
)
38+
39+
target_include_directories(test_libp2p_module PRIVATE
40+
${CMAKE_CURRENT_SOURCE_DIR}/src
41+
${CMAKE_CURRENT_SOURCE_DIR}/include
42+
)
43+
44+
# ---- Logos SDK includes ----
45+
if(LOGOS_CPP_SDK_IS_SOURCE)
46+
target_include_directories(test_libp2p_module PRIVATE
47+
${LOGOS_CPP_SDK_ROOT}/cpp
48+
${LOGOS_CPP_SDK_ROOT}/cpp/generated
49+
)
50+
else()
51+
target_include_directories(test_libp2p_module PRIVATE
52+
${LOGOS_CPP_SDK_ROOT}/include
53+
${LOGOS_CPP_SDK_ROOT}/include/cpp
54+
${LOGOS_CPP_SDK_ROOT}/include/core
55+
)
56+
endif()
57+
58+
target_link_libraries(test_libp2p_module PRIVATE
59+
libp2p_module_module_plugin
60+
Qt6::Core
61+
Qt6::Test
62+
)
63+
64+
add_test(NAME test_libp2p_module COMMAND test_libp2p_module)
65+

flake.nix

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,57 @@
1212
lib = nixpkgs.lib;
1313
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
1414
forAllSystems = f: lib.genAttrs systems (system: f system);
15-
16-
# Get pre-built libp2p cbind package for each system
15+
1716
libp2pCbind = system: libp2p.packages.${system}.cbind;
18-
19-
# Build module using mkLogosModule with library setup
20-
buildModule = system:
17+
18+
buildModule = system:
2119
logos-module-builder.lib.mkLogosModule {
2220
src = ./.;
2321
configFile = ./module.yaml;
24-
25-
# Copy library to lib/ before cmake (for linking)
22+
2623
preConfigure = ''
2724
mkdir -p lib
2825
cp -r "${libp2pCbind system}/lib"/* lib/
29-
cp -r "${libp2pCbind system}/include"/* lib/
26+
mkdir -p include
27+
cp -r "${libp2pCbind system}/include"/* include/
3028
'';
31-
32-
# Copy library to output after install (for runtime)
29+
3330
postInstall = ''
34-
echo "Copying libp2p library to output..."
31+
mkdir -p $out/lib
3532
cp "${libp2pCbind system}/lib"/*.dylib $out/lib/ 2>/dev/null || true
3633
cp "${libp2pCbind system}/lib"/*.so $out/lib/ 2>/dev/null || true
3734
'';
3835
};
36+
3937
in {
40-
packages = forAllSystems (system: (buildModule system).packages.${system});
41-
devShells = forAllSystems (system: (buildModule system).devShells.${system});
38+
39+
packages = forAllSystems (system:
40+
(buildModule system).packages.${system}
41+
);
42+
43+
devShells = forAllSystems (system:
44+
(buildModule system).devShells.${system}
45+
);
46+
47+
checks = forAllSystems (system:
48+
let
49+
pkgs = nixpkgs.legacyPackages.${system};
50+
module = buildModule system;
51+
pkg = module.packages.${system}.lib;
52+
in {
53+
module-tests = pkg.overrideAttrs (old: {
54+
doCheck = true;
55+
checkPhase = ''
56+
echo "Running Qt tests..."
57+
58+
export QT_QPA_PLATFORM=offscreen
59+
export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.qtPluginPrefix}
60+
61+
ctest --output-on-failure
62+
'';
63+
});
64+
}
65+
);
4266
};
4367
}
68+

0 commit comments

Comments
 (0)