Skip to content

chore(ffi): move header files generation to the target directory#579

Open
ZocoLini wants to merge 1 commit intov0.42-devfrom
chore/header-generation
Open

chore(ffi): move header files generation to the target directory#579
ZocoLini wants to merge 1 commit intov0.42-devfrom
chore/header-generation

Conversation

@ZocoLini
Copy link
Collaborator

@ZocoLini ZocoLini commented Mar 24, 2026

With this PR I make the build.rs scripts ALWAYS generate the headers and, I change the location to the target directory.

Why I made this?? In the swift-sdk, the build script was making a mess to get the headers and merge all the libraries into one, to fix that I need rust-dashcode to generate the headers in the target directory, that way I can grab the headers from there without having to clone this repo.

Also, the dash-spv headers and key_wallet headers used a _ in the file name but now they use - because I just read the crate's name in build.rs script and use that to name the files, let me know if you think we shouldn't do that.

Othe changes I made are:

  • Removed a couple of line in each cbindgen.toml to avoid generating C++ code, that would be an issue in the swift-sdk and would require more complex logic building it
  • Removed the include directories from the .gitignore

Summary by CodeRabbit

  • Chores
    • Updated cbindgen build dependency from 0.29 to 0.29.2 for both FFI crates.
    • Reorganized FFI build system to output generated headers to standard build output directories.
    • Updated version control configuration to track generated FFI header directories.

@ZocoLini ZocoLini marked this pull request as draft March 24, 2026 22:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

The changes refactor FFI build infrastructure for two Rust crates by redirecting generated C header output from local include/ directories to build target directories, removing cbindgen configuration entries, updating the cbindgen dependency version, and unearthing previously-ignored FFI directories from .gitignore.

Changes

Cohort / File(s) Summary
Configuration Cleanup
.gitignore
Removed ignore patterns for dash-spv-ffi/include/ and key-wallet-ffi/include/ directories, allowing generated FFI headers to be tracked.
Build Output Relocation
dash-spv-ffi/build.rs, key-wallet-ffi/build.rs
Both build scripts now derive crate names from CARGO_PKG_NAME, compute output paths as target/<profile>/include/<crate_name>/, and write generated headers there instead of local include/ directories. key-wallet-ffi additionally removes iOS/macOS Security framework linking. Both now use direct expect calls instead of match-based error handling and emit rebuild triggers for cbindgen.toml and src/.
cbindgen Configuration
dash-spv-ffi/cbindgen.toml, key-wallet-ffi/cbindgen.toml
Removed C++ compatibility and namespace options (cpp_compat and namespace in dash-spv-ffi; cpp_compat only in key-wallet-ffi) while preserving all other header generation and export settings.
Dependency Update
dash-spv-ffi/Cargo.toml
Upgraded cbindgen build dependency from "0.29" to "0.29.2".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Hop-skip through build scripts we go,
FFI headers find their rightful home below,
In target's nest, not local ground,
Where generated code is safely found! 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change in the changeset—moving FFI header file generation from local include directories to the target directory.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/header-generation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.85%. Comparing base (19fb152) to head (8cbae41).
⚠️ Report is 5 commits behind head on v0.42-dev.

Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #579      +/-   ##
=============================================
+ Coverage      66.32%   66.85%   +0.52%     
=============================================
  Files            311      314       +3     
  Lines          64976    65111     +135     
=============================================
+ Hits           43097    43529     +432     
+ Misses         21879    21582     -297     
Flag Coverage Δ
core 75.21% <ø> (+0.08%) ⬆️
ffi 38.45% <ø> (+1.65%) ⬆️
rpc 28.28% <ø> (ø)
spv 81.13% <ø> (+0.05%) ⬆️
wallet 66.55% <ø> (+0.27%) ⬆️
see 47 files with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dash-spv-ffi/build.rs`:
- Around line 5-21: The generated header path uses the hyphenated package name
from CARGO_PKG_NAME which breaks C includes; create a library-safe name (e.g.,
let lib_name = crate_name.replace("-", "_")) and use lib_name when building
include_dir and output_path (replace uses of crate_name in include_dir and
output_path with lib_name) so the produced header is named dash_spv_ffi.h and
placed under target/.../include/dash_spv_ffi/.

In `@key-wallet-ffi/build.rs`:
- Around line 5-21: The generated header path uses CARGO_PKG_NAME (crate_name)
which contains hyphens; convert the package name to the library-style name by
replacing '-' with '_' (e.g., lib_name = crate_name.replace('-', '_')) and use
that lib_name when constructing include_dir and output_path (and any other
places that rely on the header filename) so the produced header is
key_wallet_ffi.h and the include directory uses key_wallet_ffi; keep
fs::create_dir_all(&include_dir) and subsequent logic unchanged except for using
lib_name.

In `@key-wallet-ffi/Cargo.toml`:
- Around line 35-36: Update the pull request title to include an allowed
semantic prefix (e.g., "build:") so it conforms to the pr-title.yml workflow;
change the current title "move header files generation to the target directory"
to "build: move header files generation to the target directory" (this PR only
adjusts header-generation/build plumbing related to cbindgen in Cargo.toml) so
the semantic-pull-request check accepts the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d163ca0a-b161-4cde-8934-34b29c1f25ad

📥 Commits

Reviewing files that changed from the base of the PR and between 19fb152 and 40ccaa2.

📒 Files selected for processing (7)
  • .gitignore
  • dash-spv-ffi/Cargo.toml
  • dash-spv-ffi/build.rs
  • dash-spv-ffi/cbindgen.toml
  • key-wallet-ffi/Cargo.toml
  • key-wallet-ffi/build.rs
  • key-wallet-ffi/cbindgen.toml
💤 Files with no reviewable changes (3)
  • .gitignore
  • key-wallet-ffi/cbindgen.toml
  • dash-spv-ffi/cbindgen.toml

@ZocoLini ZocoLini force-pushed the chore/header-generation branch from 40ccaa2 to 65528b2 Compare March 25, 2026 16:10
@ZocoLini ZocoLini marked this pull request as ready for review March 25, 2026 16:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
dash-spv-ffi/build.rs (1)

5-5: ⚠️ Potential issue | 🟠 Major

Use the library-safe header name here, not CARGO_PKG_NAME.

Line 5 pulls the hyphenated package name, and Lines 17-21 reuse it for both the include directory and header filename. That generates dash-spv-ffi.h, while the C-facing name for this crate is dash_spv_ffi, so the moved header path no longer matches current consumers.

Suggested fix
-    let crate_name = env::var("CARGO_PKG_NAME").unwrap();
+    let crate_name = env::var("CARGO_PKG_NAME").expect("Missing CARGO_PKG_NAME");
+    let header_name = crate_name.replace('-', "_");
@@
-    let include_dir = target_dir.join("include").join(&crate_name);
+    let include_dir = target_dir.join("include").join(&header_name);
@@
-    let output_path = include_dir.join(format!("{}.h", &crate_name));
+    let output_path = include_dir.join(format!("{header_name}.h"));

Run this to confirm the package/lib names and the header spellings still referenced by the C surface:

#!/bin/bash
set -euo pipefail

# Expected: package.name is hyphenated, while lib.name and C consumers use the underscored form.
python - <<'PY'
import pathlib, tomllib
cargo = pathlib.Path("dash-spv-ffi/Cargo.toml")
data = tomllib.loads(cargo.read_text())
print("package.name =", data["package"]["name"])
print("lib.name     =", data.get("lib", {}).get("name"))
PY

echo
rg -n -C1 --glob '*.c' --glob 'README*' 'dash[_-]spv[_-]ffi\.h' .

Also applies to: 17-21

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv-ffi/build.rs` at line 5, The build script currently uses the
hyphenated package name (crate_name from env::var("CARGO_PKG_NAME")) for the
generated C header and include directory; change it to a library-safe identifier
by normalizing hyphens to underscores (e.g., let header_name =
crate_name.replace('-', "_")) and use header_name for the header filename and
include dir (the places where crate_name is reused around the header
generation/installation logic, formerly lines ~17-21). Ensure the header
produced is "dash_spv_ffi.h" (underscore form) and any include path uses the
same normalized name so C consumers keep the expected symbol.
🧹 Nitpick comments (1)
dash-spv-ffi/build.rs (1)

12-21: Extract the OUT_DIR path mapping into a testable helper.

The ancestors().nth(3) walk is the new behavior in this PR and it is easy to regress for plain vs target-triple layouts. Pulling that mapping into a small helper with #[cfg(test)] cases would make future path changes much safer. As per coding guidelines, "Write unit tests for new functionality in Rust code" and "Place unit tests alongside code with #[cfg(test)] attribute".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv-ffi/build.rs` around lines 12 - 21, Extract the ancestor-walking
logic that turns OUT_DIR into the target directory into a small helper function
(e.g. fn resolve_target_dir_from_out_dir(out_dir: &str) -> PathBuf) and use that
helper where target_dir is computed instead of calling .ancestors().nth(3)
inline; add unit tests alongside that helper with #[cfg(test)] to cover the
expected layouts (plain target/<PROFILE> and target/<triple>/<PROFILE>) to
assert the returned PathBuf, and update usages in build.rs to call the helper
with the existing out_dir and keep include_dir, fs::create_dir_all and
output_path logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@dash-spv-ffi/build.rs`:
- Line 5: The build script currently uses the hyphenated package name
(crate_name from env::var("CARGO_PKG_NAME")) for the generated C header and
include directory; change it to a library-safe identifier by normalizing hyphens
to underscores (e.g., let header_name = crate_name.replace('-', "_")) and use
header_name for the header filename and include dir (the places where crate_name
is reused around the header generation/installation logic, formerly lines
~17-21). Ensure the header produced is "dash_spv_ffi.h" (underscore form) and
any include path uses the same normalized name so C consumers keep the expected
symbol.

---

Nitpick comments:
In `@dash-spv-ffi/build.rs`:
- Around line 12-21: Extract the ancestor-walking logic that turns OUT_DIR into
the target directory into a small helper function (e.g. fn
resolve_target_dir_from_out_dir(out_dir: &str) -> PathBuf) and use that helper
where target_dir is computed instead of calling .ancestors().nth(3) inline; add
unit tests alongside that helper with #[cfg(test)] to cover the expected layouts
(plain target/<PROFILE> and target/<triple>/<PROFILE>) to assert the returned
PathBuf, and update usages in build.rs to call the helper with the existing
out_dir and keep include_dir, fs::create_dir_all and output_path logic
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 767bc8fb-f1fa-452c-9683-a1c4e57c0abc

📥 Commits

Reviewing files that changed from the base of the PR and between 40ccaa2 and 65528b2.

📒 Files selected for processing (6)
  • .gitignore
  • dash-spv-ffi/Cargo.toml
  • dash-spv-ffi/build.rs
  • dash-spv-ffi/cbindgen.toml
  • key-wallet-ffi/build.rs
  • key-wallet-ffi/cbindgen.toml
💤 Files with no reviewable changes (3)
  • .gitignore
  • key-wallet-ffi/cbindgen.toml
  • dash-spv-ffi/cbindgen.toml
✅ Files skipped from review due to trivial changes (2)
  • dash-spv-ffi/Cargo.toml
  • key-wallet-ffi/build.rs

@ZocoLini ZocoLini changed the title move header files generation to the target directory chore(ffi): move header files generation to the target directory Mar 25, 2026
@ZocoLini ZocoLini force-pushed the chore/header-generation branch from 65528b2 to 8cbae41 Compare March 25, 2026 16:31
@github-actions github-actions bot added the ready-for-review CodeRabbit has approved this PR label Mar 25, 2026
@ktechmidas
Copy link

@dashinfraclaw fulltest

4 similar comments
@ktechmidas
Copy link

@dashinfraclaw fulltest

@ktechmidas
Copy link

@dashinfraclaw fulltest

@ktechmidas
Copy link

@dashinfraclaw fulltest

@ktechmidas
Copy link

@dashinfraclaw fulltest

@dashinfraclaw
Copy link

dashinfraclaw commented Mar 25, 2026

🔧 Infraclaw fulltest results for PR #579

Repo PR Status Details
dashpay/platform #3402 ❌ FAIL Missing key-wallet-manager package (see below)
dashpay/kotlin-platform #33 ❌ FAIL Same root cause
dashpay/ferment #6 ⚠️ No CI No workflows configured
dashpay/quorum-list-server #9 ⚠️ No CI No workflows configured
dashpay/dash-shared-core ⏭️ Skip No direct git dep
dashpay/rs-bip37-bloom-filter ⏭️ Skip No direct git dep

Root cause: pre-existing, not caused by this PR.

Platform references key-wallet-manager from rust-dashcore, but that crate was merged into key-wallet in PR #503 (2026-03-20). Platform is still pinned to rev 42eb1d69 (before the merge) and hasn't been updated yet.

This means no rust-dashcore PR can pass fulltest against platform until platform updates its dependency from key-wallet-manager to key-wallet.

Automated integration test by @dashinfraclaw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants