Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ cobertura.xml
# Python
__pycache__/

# Generated FFI headers (produced by build.rs via cbindgen)
dash-spv-ffi/include/
key-wallet-ffi/include/

# Build scripts artifacts
*.log
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,20 @@ repos:
types: [rust]
pass_filenames: false

# ============================================================================
# SLOW CHECKS - Run on git push only.
# ============================================================================

- repo: local
hooks:
- id: verify-ffi
name: verify FFI
description: Verify FFI headers and documentation are up to date
description: Verify FFI documentation is up to date
entry: contrib/verify_ffi.py
language: python
pass_filenames: false
files: ^(key-wallet-ffi|dash-spv-ffi)/.*\.(rs|toml|py)$
stages: [pre-push, manual]

# ============================================================================
# SLOW CHECKS - Run on git push only.
# ============================================================================

- repo: local
hooks:
- id: clippy
name: clippy (workspace strict)
description: Strict clippy on entire workspace - deny all warnings
Expand Down
68 changes: 12 additions & 56 deletions contrib/verify_ffi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Verify that FFI headers and documentation are up to date."""
"""Verify that FFI documentation is up to date."""

import subprocess
import sys
Expand All @@ -9,24 +9,6 @@
FFI_CRATES = ["key-wallet-ffi", "dash-spv-ffi"]


def build_ffi_crates(repo_root: Path) -> bool:
"""Build all FFI crates to regenerate headers."""
print(" Building FFI crates...")
result = subprocess.run(
["cargo", "build", "--quiet", "--target-dir", "target/verify-ffi"]
+ [f"-p={crate}" for crate in FFI_CRATES],
cwd=repo_root,
capture_output=True,
text=True
)
if result.returncode != 0:
print("Build failed:", file=sys.stderr)
if result.stderr:
print(result.stderr, file=sys.stderr)
return False
return True


def generate_ffi_docs(crate_dir: Path) -> tuple[str, int, str]:
"""Generate FFI documentation for a crate."""
print(f" Generating {crate_dir.name} docs...")
Expand All @@ -46,11 +28,7 @@ def main():
repo_root = Path(__file__).parent.parent
ffi_crate_dirs = [repo_root / crate for crate in FFI_CRATES]

print("Regenerating FFI headers and documentation")

# Build all FFI crates first
if not build_ffi_crates(repo_root):
sys.exit(1)
print("Regenerating FFI documentation")

# Generate docs in parallel
with ThreadPoolExecutor(max_workers=2) as executor:
Expand All @@ -68,48 +46,26 @@ def main():

print(" Generation complete, checking for changes...")

# Check if headers changed
headers_result = subprocess.run(
["git", "diff", "--exit-code", "--quiet", "--",
"key-wallet-ffi/include/", "dash-spv-ffi/include/"],
cwd=repo_root
)

# Check if docs changed
docs_result = subprocess.run(
["git", "diff", "--exit-code", "--quiet", "--",
"key-wallet-ffi/FFI_API.md", "dash-spv-ffi/FFI_API.md"],
cwd=repo_root
)

headers_changed = headers_result.returncode != 0
docs_changed = docs_result.returncode != 0

if headers_changed or docs_changed:
if docs_result.returncode != 0:
print()
print("FFI documentation is out of date!\n")
print("Documentation changes detected:")
subprocess.run(
["git", "--no-pager", "diff", "--",
"key-wallet-ffi/FFI_API.md", "dash-spv-ffi/FFI_API.md"],
cwd=repo_root
)
print()
if headers_changed:
print("FFI headers are out of date!\n")
print("Header changes detected:")
subprocess.run(
["git", "--no-pager", "diff", "--",
"key-wallet-ffi/include/", "dash-spv-ffi/include/"],
cwd=repo_root
)
print()

if docs_changed:
print("FFI documentation is out of date!\n")
print("Documentation changes detected:")
subprocess.run(
["git", "--no-pager", "diff", "--",
"key-wallet-ffi/FFI_API.md", "dash-spv-ffi/FFI_API.md"],
cwd=repo_root
)
print()

sys.exit(1)

print("FFI headers and documentation are up to date")
print("FFI documentation is up to date")


if __name__ == "__main__":
Expand Down
5 changes: 1 addition & 4 deletions dash-spv-ffi/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ cargo build --release --target aarch64-apple-ios-sim
```

### Header Generation
The C header is auto-generated by the build script. To regenerate manually:
```bash
cbindgen --config cbindgen.toml --crate dash-spv-ffi --output include/dash_spv_ffi.h
```
The C header (`include/dash_spv_ffi.h`) is auto-generated by `build.rs` during `cargo build` and is gitignored.

## Testing

Expand Down
11 changes: 2 additions & 9 deletions dash-spv-ffi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ test:
# Clean build artifacts
clean:
cargo clean
rm -f include/dash_spv_ffi.h

# Generate C header
header:
cargo build --release
@echo "Generated header at include/dash_spv_ffi.h"

# Update FFI documentation
update-docs:
Expand All @@ -32,7 +26,7 @@ check-docs:
@bash scripts/check_ffi_docs.sh

# Generate all documentation
docs: header update-docs
docs: update-docs
@echo "All documentation generated"

# Build for iOS
Expand All @@ -42,7 +36,7 @@ ios:
cargo build --release --target x86_64-apple-ios

# Full build with documentation
full: clean build header update-docs
full: clean build update-docs
@echo "Full build complete with documentation"

# Help
Expand All @@ -51,7 +45,6 @@ help:
@echo " make build - Build the library"
@echo " make test - Run tests"
@echo " make clean - Clean build artifacts"
@echo " make header - Generate C header"
@echo " make update-docs - Update FFI API documentation"
@echo " make check-docs - Check if FFI docs are up to date"
@echo " make docs - Generate all documentation"
Expand Down
Loading
Loading