Skip to content

Commit c304954

Browse files
authored
ci: add FFI header validation step (#609)
* .c files to validate headers and script to execute them * add ffi-c-tests github workflow with the validation headers job * fix headers generation issues * validate_headers.sh works with any include directory provided as an argument
1 parent 3f65002 commit c304954

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

.github/workflows/build-and-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,8 @@ jobs:
9090
path: ${{ runner.temp }}/dashd-test-logs/
9191
retention-days: 7
9292
if-no-files-found: ignore
93+
- name: Validate headers
94+
if: matrix.group == 'ffi' && inputs.os == 'ubuntu-latest'
95+
run: |
96+
sudo apt update && sudo apt install -y build-essential
97+
bash ffi-c-tests/validate-headers.sh ./target/llvm-cov-target/debug/include

dash-spv-ffi/cbindgen.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include_guard = "DASH_SPV_FFI_H"
44
autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */"
55
include_version = true
66
cpp_compat = true
7+
includes = ["../key-wallet-ffi/key-wallet-ffi.h"]
78

89
[export]
910
include = ["FFI"]
@@ -26,6 +27,7 @@ postfix = ""
2627
rename_fields = "None"
2728

2829
[enum]
30+
prefix_with_name = true
2931
rename_variants = "None"
3032

3133
[parse]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "dash-spv-ffi/dash-spv-ffi.h"
2+
3+
int main() { return 0; }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "key-wallet-ffi/key-wallet-ffi.h"
2+
3+
int main() { return 0; }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "dash-spv-ffi/dash-spv-ffi.h"
2+
#include "key-wallet-ffi/key-wallet-ffi.h"
3+
4+
int main() { return 0; }

ffi-c-tests/validate-headers.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
NC='\033[0m'
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
HEADER_TESTS_DIR="$SCRIPT_DIR/header-tests"
10+
11+
if [ $# -lt 1 ]; then
12+
echo "Usage: $0 <include_dir>"
13+
exit 1
14+
fi
15+
16+
INCLUDE_DIR="$1"
17+
18+
if [ ! -d "$INCLUDE_DIR" ]; then
19+
echo "Error: INCLUDE_DIR '$INCLUDE_DIR' does not exist or is not a directory."
20+
exit 1
21+
fi
22+
23+
EXIT_CODE=0
24+
25+
for file in "$HEADER_TESTS_DIR"/*.c; do
26+
if gcc -c "$file" -I"$INCLUDE_DIR" -o /dev/null; then
27+
echo -e "${GREEN}Passed: $file${NC}"
28+
else
29+
echo -e "${RED}Failed: $file${NC}"
30+
EXIT_CODE=1
31+
fi
32+
done
33+
34+
exit $EXIT_CODE

key-wallet-ffi/cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ item_types = ["functions", "enums", "structs", "typedefs", "opaque", "constants"
5555

5656
[enum]
5757
# Configure enum generation
58+
prefix_with_name = true
5859
rename_variants = "ScreamingSnakeCase"
5960
add_sentinel = false
6061
derive_helper_methods = false

0 commit comments

Comments
 (0)