Skip to content
Open
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: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ 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
47 changes: 26 additions & 21 deletions dash-spv-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
use std::env;
use std::path::PathBuf;
use std::path::Path;
use std::{env, fs};

fn main() {
let crate_name = env::var("CARGO_PKG_NAME").unwrap();
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let output_path = PathBuf::from(&crate_dir).join("include");
let out_dir = env::var("OUT_DIR").unwrap();

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

// Ensure the build script reruns when header-relevant files change
println!("cargo:rerun-if-changed=cbindgen.toml");
println!("cargo:rerun-if-changed=src");

let config = cbindgen::Config::from_file("cbindgen.toml")
.expect("cbindgen config missing or invalid: cbindgen.toml");

match cbindgen::Builder::new().with_crate(&crate_dir).with_config(config).generate() {
Ok(bindings) => {
bindings.write_to_file(output_path.join("dash_spv_ffi.h"));
println!("cargo:warning=Generated C header at {:?}", output_path);
}
Err(e) => {
// Fail the build to avoid shipping stale headers
panic!("Failed to generate C header via cbindgen: {}", e);
}
}
println!("cargo:rerun-if-changed=src/");

let target_dir = Path::new(&out_dir)
.ancestors()
.nth(3) // This line moves up to the target/<PROFILE> directory
.expect("Failed to find target dir");

let include_dir = target_dir.join("include").join(&crate_name);

fs::create_dir_all(&include_dir).unwrap();

let output_path = include_dir.join(format!("{}.h", &crate_name));

let config_path = Path::new(&crate_dir).join("cbindgen.toml");
let config = cbindgen::Config::from_file(&config_path).expect("Failed to read cbindgen.toml");

cbindgen::Builder::new()
.with_crate(&crate_dir)
.with_config(config)
.generate()
.expect("Unable to generate bindings")
.write_to_file(&output_path);
}
3 changes: 0 additions & 3 deletions dash-spv-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# cbindgen configuration for dash-spv-ffi

language = "C"
header = "/* dash-spv-ffi C bindings - Auto-generated by cbindgen */"
include_guard = "DASH_SPV_FFI_H"
autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */"
include_version = true
namespace = "dash_spv_ffi"
cpp_compat = true

[export]
Expand Down
2 changes: 1 addition & 1 deletion key-wallet-ffi/IMPORT_WALLET_FFI.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The function may set the following error codes:
## Usage Example

```c
#include "key_wallet_ffi.h"
#include "key-wallet-ffi.h"

// Load wallet bytes from file or network
uint8_t *wallet_bytes = load_wallet_bytes();
Expand Down
57 changes: 24 additions & 33 deletions key-wallet-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
// Build script for key-wallet-ffi
// Generates C header file using cbindgen

use std::env;
use std::path::PathBuf;
use std::path::Path;
use std::{env, fs};

fn main() {
// Add platform-specific linking flags
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();

match target_os.as_str() {
"ios" => {
println!("cargo:rustc-link-lib=framework=Security");
}
"macos" => {
println!("cargo:rustc-link-lib=framework=Security");
}
_ => {}
}

// Generate C header file using cbindgen
let crate_name = env::var("CARGO_PKG_NAME").unwrap();
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let output_path = PathBuf::from(&crate_dir).join("include/key_wallet_ffi.h");
let out_dir = env::var("OUT_DIR").unwrap();

println!("cargo:rerun-if-changed=cbindgen.toml");
println!("cargo:rerun-if-changed=src/");

let target_dir = Path::new(&out_dir)
.ancestors()
.nth(3) // This line moves up to the target/<PROFILE> directory
.expect("Failed to find target dir");

let include_dir = target_dir.join("include").join(&crate_name);

fs::create_dir_all(&include_dir).unwrap();

let output_path = include_dir.join(format!("{}.h", &crate_name));

// Create include directory if it doesn't exist
std::fs::create_dir_all(output_path.parent().unwrap()).ok();
let config_path = Path::new(&crate_dir).join("cbindgen.toml");
let config = cbindgen::Config::from_file(&config_path).expect("Failed to read cbindgen.toml");

match cbindgen::Builder::new()
cbindgen::Builder::new()
.with_crate(&crate_dir)
.with_config(cbindgen::Config::from_file("cbindgen.toml").unwrap_or_default())
.with_config(config)
.generate()
{
Ok(bindings) => {
bindings.write_to_file(&output_path);
println!("cargo:warning=Generated C header at {:?}", output_path);
}
Err(e) => {
panic!("Failed to generate C header via cbindgen: {}", e);
}
}
.expect("Unable to generate bindings")
.write_to_file(&output_path);
}
4 changes: 0 additions & 4 deletions key-wallet-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# cbindgen configuration for key-wallet-ffi
# This file configures how cbindgen generates the C header from Rust code

language = "C"
header = """/**
* Key Wallet FFI - C Header File
Expand All @@ -15,7 +12,6 @@ header = """/**
include_guard = "KEY_WALLET_FFI_H"
autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */"
include_version = true
cpp_compat = true
usize_is_size_t = true
no_includes = false
sys_includes = ["stdint.h", "stddef.h", "stdbool.h"]
Expand Down
67 changes: 0 additions & 67 deletions key-wallet-ffi/generate_header.sh

This file was deleted.

Loading