Skip to content

Commit 4c20deb

Browse files
committed
chore: add nix check and ci
1 parent e73ace0 commit 4c20deb

File tree

5 files changed

+210
-13
lines changed

5 files changed

+210
-13
lines changed

.github/workflows/ci.yml

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

.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: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,48 @@ 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
2525
)
26+
27+
enable_testing()
28+
29+
find_package(Qt6 REQUIRED COMPONENTS Core Test)
30+
31+
logos_find_dependencies()
32+
33+
add_executable(test_libp2p_module
34+
tests/test_libp2p_module.cpp
35+
)
36+
37+
target_include_directories(test_libp2p_module PRIVATE
38+
${CMAKE_CURRENT_SOURCE_DIR}/src
39+
${CMAKE_CURRENT_SOURCE_DIR}/lib
40+
)
41+
42+
# ---- Logos SDK includes ----
43+
if(LOGOS_CPP_SDK_IS_SOURCE)
44+
target_include_directories(test_libp2p_module PRIVATE
45+
${LOGOS_CPP_SDK_ROOT}/cpp
46+
${LOGOS_CPP_SDK_ROOT}/cpp/generated
47+
)
48+
else()
49+
target_include_directories(test_libp2p_module PRIVATE
50+
${LOGOS_CPP_SDK_ROOT}/include
51+
${LOGOS_CPP_SDK_ROOT}/include/cpp
52+
${LOGOS_CPP_SDK_ROOT}/include/core
53+
)
54+
endif()
55+
56+
target_link_libraries(test_libp2p_module PRIVATE
57+
libp2p_module_module_plugin
58+
Qt6::Core
59+
Qt6::Test
60+
)
61+
62+
add_test(NAME test_libp2p_module COMMAND test_libp2p_module)
63+

flake.nix

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,68 @@
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/
2926
cp -r "${libp2pCbind system}/include"/* lib/
3027
'';
31-
32-
# Copy library to output after install (for runtime)
28+
3329
postInstall = ''
34-
echo "Copying libp2p library to output..."
30+
mkdir -p $out/lib
3531
cp "${libp2pCbind system}/lib"/*.dylib $out/lib/ 2>/dev/null || true
3632
cp "${libp2pCbind system}/lib"/*.so $out/lib/ 2>/dev/null || true
3733
'';
3834
};
35+
3936
in {
40-
packages = forAllSystems (system: (buildModule system).packages.${system});
41-
devShells = forAllSystems (system: (buildModule system).devShells.${system});
37+
packages = forAllSystems (system:
38+
(buildModule system).packages.${system}
39+
);
40+
41+
devShells = forAllSystems (system:
42+
(buildModule system).devShells.${system}
43+
);
44+
45+
checks = forAllSystems (system:
46+
let
47+
pkgs = nixpkgs.legacyPackages.${system};
48+
module = buildModule system;
49+
# pkg = module.packages.${system}.default;
50+
pkg = module.packages.${system}.lib;
51+
in {
52+
module-tests = pkg.overrideAttrs (old: {
53+
doCheck = true;
54+
# nativeBuildInputs =
55+
# (old.nativeBuildInputs or [])
56+
# ++ [ pkgs.qt6.wrapQtAppsHook ];
57+
# nativeCheckInputs =
58+
# (old.nativeCheckInputs or [])
59+
# ++ [
60+
# pkgs.qt6.qtbase
61+
# pkgs.qt6.qttools
62+
# ];
63+
# cmakeFlags = (old.cmakeFlags or []) ++ [
64+
# "-DBUILD_TESTING=ON"
65+
# ];
66+
checkPhase = ''
67+
echo "Running Qt tests..."
68+
69+
export QT_QPA_PLATFORM=offscreen
70+
export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.qtPluginPrefix}
71+
72+
ctest --output-on-failure
73+
'';
74+
});
75+
}
76+
);
4277
};
4378
}
79+

tests/test_libp2p_module.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <QtTest>
2+
#include <libp2p_module_plugin.h>
3+
4+
class TestLibp2pModule : public QObject
5+
{
6+
Q_OBJECT
7+
8+
private slots:
9+
10+
void testConstruction()
11+
{
12+
Libp2pModulePlugin plugin;
13+
QVERIFY(true); // construction should not crash
14+
}
15+
16+
void testFooSignal()
17+
{
18+
Libp2pModulePlugin plugin;
19+
20+
QSignalSpy spy(
21+
&plugin,
22+
SIGNAL(libp2pEvent(QString,int,QString,QVariant))
23+
);
24+
25+
plugin.foo("hello");
26+
27+
QVERIFY(spy.count() >= 0);
28+
}
29+
};
30+
31+
QTEST_MAIN(TestLibp2pModule)
32+
#include "test_libp2p_module.moc"

0 commit comments

Comments
 (0)