Skip to content

Commit befd035

Browse files
refactor: cleaned ffi to remove need for hacks when building unified header for swift library (#139)
* refactor: clean FFI * update headers * updated docs * fix * fixes * fix
1 parent be06e94 commit befd035

File tree

22 files changed

+728
-372
lines changed

22 files changed

+728
-372
lines changed

dash-spv-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ env_logger = "0.10"
3737
dashcore-test-utils = { path = "../test-utils" }
3838

3939
[build-dependencies]
40-
cbindgen = "0.26"
40+
cbindgen = "0.29"

dash-spv-ffi/FFI_API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ Sets whether to relay transactions (currently a no-op) # Safety - `config` must
536536
#### `dash_spv_ffi_config_set_restrict_to_configured_peers`
537537

538538
```c
539-
dash_spv_ffi_config_set_restrict_to_configured_peers(config: *mut FFIClientConfig, restrict: bool,) -> i32
539+
dash_spv_ffi_config_set_restrict_to_configured_peers(config: *mut FFIClientConfig, restrict_peers: bool,) -> i32
540540
```
541541
542542
**Description:**

dash-spv-ffi/build.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ fn main() {
77

88
std::fs::create_dir_all(&output_path).unwrap();
99

10-
let config = cbindgen::Config::default();
10+
// Ensure the build script reruns when header-relevant files change
11+
println!("cargo:rerun-if-changed=cbindgen.toml");
12+
println!("cargo:rerun-if-changed=src");
1113

12-
cbindgen::Builder::new()
13-
.with_crate(crate_dir)
14-
.with_config(config)
15-
.with_language(cbindgen::Language::C)
16-
.generate()
17-
.expect("Unable to generate bindings")
18-
.write_to_file(output_path.join("dash_spv_ffi.h"));
14+
let config = cbindgen::Config::from_file("cbindgen.toml")
15+
.expect("cbindgen config missing or invalid: cbindgen.toml");
16+
17+
match cbindgen::Builder::new().with_crate(&crate_dir).with_config(config).generate() {
18+
Ok(bindings) => {
19+
bindings.write_to_file(output_path.join("dash_spv_ffi.h"));
20+
println!("cargo:warning=Generated C header at {:?}", output_path);
21+
}
22+
Err(e) => {
23+
// Fail the build to avoid shipping stale headers
24+
panic!("Failed to generate C header via cbindgen: {}", e);
25+
}
26+
}
1927
}

dash-spv-ffi/cbindgen.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ cpp_compat = true
1111
[export]
1212
include = ["FFI"]
1313
exclude = ["Option_BlockCallback", "Option_TransactionCallback", "Option_BalanceCallback"]
14-
prefix = "dash_spv_ffi_"
14+
prefix = ""
15+
16+
[export.body]
17+
# Forward-declare FFIClientConfig to avoid aliasing to internal ClientConfig in C headers
18+
"FFIClientConfig" = ""
1519

1620
[export.rename]
1721
"FFIValidationMode" = "DashSpvValidationMode"
@@ -32,4 +36,4 @@ parse_deps = false
3236
include = []
3337

3438
[macro_expansion]
35-
bitflags = false
39+
bitflags = false

0 commit comments

Comments
 (0)