From a84e9d803d644becf408945e972b020d82e97317 Mon Sep 17 00:00:00 2001 From: kamilsa Date: Tue, 4 Nov 2025 17:12:05 +0500 Subject: [PATCH 1/3] Adapt c-hash-sig for kagome-crates integration --- Cargo.toml | 5 ++--- build.rs | 26 +------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf9bfd7..7f2a5b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pq-bindings-c-rust" +name = "c_hash_sig_crust" version = "0.1.0" edition = "2021" @@ -12,5 +12,4 @@ rand = "0.9" bincode = { version = "2.0.1", features = ["serde"] } [build-dependencies] -cbindgen = "0.27" - +build-helper = { path = "../build-helper" } diff --git a/build.rs b/build.rs index 2142c4a..36c2f71 100644 --- a/build.rs +++ b/build.rs @@ -1,29 +1,5 @@ -extern crate cbindgen; - -use std::env; -use std::fs; -use std::path::PathBuf; fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let package_name = env::var("CARGO_PKG_NAME").unwrap(); - - // Create include directory in project root - let include_dir = PathBuf::from(&crate_dir).join("include"); - fs::create_dir_all(&include_dir).expect("Unable to create include directory"); - - let output_file = include_dir - .join(format!("{}.h", package_name)) - .display() - .to_string(); - - cbindgen::Builder::new() - .with_crate(crate_dir) - .with_language(cbindgen::Language::C) - .generate() - .expect("Unable to generate bindings") - .write_to_file(&output_file); - - println!("cargo:rerun-if-changed=src/lib.rs"); + build_helper::run_cbindgen(); } From 8f9f5c3eb4408310850f0a4a381e247571bf5208 Mon Sep 17 00:00:00 2001 From: kamilsa Date: Tue, 4 Nov 2025 17:43:04 +0500 Subject: [PATCH 2/3] Adapt c-hash-sig for kagome-crates integration --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 7f2a5b4..5cbc7ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [lib] +name = "c_hash_sig_crust" crate-type = ["cdylib", "staticlib"] [dependencies] From 1e6c8cadf3bfc9b3c62da8732a5b900c21d5b316 Mon Sep 17 00:00:00 2001 From: kamilsa Date: Tue, 4 Nov 2025 18:25:53 +0500 Subject: [PATCH 3/3] Add feature flag for kagome-crates integration and update build script --- Cargo.toml | 7 ++++++- build.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5cbc7ef..c4fe5ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,15 @@ edition = "2021" name = "c_hash_sig_crust" crate-type = ["cdylib", "staticlib"] +[features] +# Feature flag to enable kagome-crates integration +kagome-crates = ["build-helper"] + [dependencies] hashsig = { git = "https://github.com/b-wagn/hash-sig" } rand = "0.9" bincode = { version = "2.0.1", features = ["serde"] } [build-dependencies] -build-helper = { path = "../build-helper" } +cbindgen = "0.27" +build-helper = { path = "../build-helper", optional = true } diff --git a/build.rs b/build.rs index 36c2f71..31e3682 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,32 @@ - +#[cfg(feature = "kagome-crates")] fn main() { build_helper::run_cbindgen(); } +#[cfg(not(feature = "kagome-crates"))] +fn main() { + use std::env; + use std::fs; + use std::path::PathBuf; + + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let package_name = env::var("CARGO_PKG_NAME").unwrap(); + + // Create include directory in project root + let include_dir = PathBuf::from(&crate_dir).join("include"); + fs::create_dir_all(&include_dir).expect("Unable to create include directory"); + + let output_file = include_dir + .join(format!("{}.h", package_name)) + .display() + .to_string(); + + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_language(cbindgen::Language::C) + .generate() + .expect("Unable to generate bindings") + .write_to_file(&output_file); + + println!("cargo:rerun-if-changed=src/lib.rs"); +}