From f345b66f53ca9e7c4adc9f649f3894621357a35e Mon Sep 17 00:00:00 2001 From: Artur Yurii Korchynskyi <42449190+akorchyn@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:49:33 +0200 Subject: [PATCH] Fix NixOS vendoring issue (#409) --- .gitignore | 2 ++ bindings/rust/Cargo.lock => Cargo.lock | 0 bindings/rust/Cargo.toml => Cargo.toml | 8 +++++++- bindings/rust/.gitignore | 1 - bindings/rust/benches/kzg_benches.rs | 2 +- bindings/rust/build.rs | 15 ++++++--------- bindings/rust/src/bindings/mod.rs | 26 +++++++++++++------------- 7 files changed, 29 insertions(+), 25 deletions(-) rename bindings/rust/Cargo.lock => Cargo.lock (100%) rename bindings/rust/Cargo.toml => Cargo.toml (86%) delete mode 100644 bindings/rust/.gitignore diff --git a/.gitignore b/.gitignore index adb79e168..8cd120d52 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ build/ # ccls cache dir .ccls-cache/ + +target diff --git a/bindings/rust/Cargo.lock b/Cargo.lock similarity index 100% rename from bindings/rust/Cargo.lock rename to Cargo.lock diff --git a/bindings/rust/Cargo.toml b/Cargo.toml similarity index 86% rename from bindings/rust/Cargo.toml rename to Cargo.toml index 5a10d419d..ca63df3be 100644 --- a/bindings/rust/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,11 @@ license = "Apache-2.0" links = "ckzg" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +include = ["src", "inc", "bindings/rust/src", "bindings/rust/build.rs", "blst/bindings/*.h"] +build = "bindings/rust/build.rs" + +[lib] +path = "bindings/rust/src/lib.rs" [features] default = ["std", "portable"] @@ -36,8 +41,8 @@ criterion = "0.5.1" glob = "0.3.1" rand = "0.8.5" serde = { version = "1.0", features = ["derive"] } -serde_yaml = "0.9.17" serde_json = "1.0.105" +serde_yaml = "0.9.17" [build-dependencies] bindgen = { version = "0.69", optional = true } @@ -47,5 +52,6 @@ cc = "1.0" glob = "0.3" [[bench]] +path = "bindings/rust/benches/kzg_benches.rs" name = "kzg_benches" harness = false diff --git a/bindings/rust/.gitignore b/bindings/rust/.gitignore deleted file mode 100644 index 2f7896d1d..000000000 --- a/bindings/rust/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/bindings/rust/benches/kzg_benches.rs b/bindings/rust/benches/kzg_benches.rs index ad5656af8..85b14cb9e 100644 --- a/bindings/rust/benches/kzg_benches.rs +++ b/bindings/rust/benches/kzg_benches.rs @@ -25,7 +25,7 @@ fn generate_random_blob(rng: &mut ThreadRng) -> Blob { pub fn criterion_benchmark(c: &mut Criterion) { let max_count: usize = 64; let mut rng = rand::thread_rng(); - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = Arc::new(KzgSettings::load_trusted_setup_file(trusted_setup_file).unwrap()); diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index 970a006ff..1b19f71ac 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -1,13 +1,7 @@ -use std::env; -use std::path::PathBuf; +use std::{env, path::PathBuf}; fn main() { - let cargo_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - let root_dir = cargo_dir - .parent() - .expect("rust dir is nested") - .parent() - .expect("bindings dir is nested"); + let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); // Obtain the header files of blst let blst_base_dir = root_dir.join("blst"); @@ -37,7 +31,10 @@ fn main() { #[cfg(feature = "generate-bindings")] { let header_path = c_src_dir.join("c_kzg_4844.h"); - let bindings_out_path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/bindings/generated.rs"); + let bindings_out_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/bindings/rust/src/bindings/generated.rs" + ); make_bindings( header_path.to_str().expect("valid header path"), blst_headers_dir.to_str().expect("valid blst header path"), diff --git a/bindings/rust/src/bindings/mod.rs b/bindings/rust/src/bindings/mod.rs index dfa021bb6..e9362fcf8 100644 --- a/bindings/rust/src/bindings/mod.rs +++ b/bindings/rust/src/bindings/mod.rs @@ -648,20 +648,20 @@ mod tests { #[test] fn test_end_to_end() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); test_simple(trusted_setup_file); } - const BLOB_TO_KZG_COMMITMENT_TESTS: &str = "../../tests/blob_to_kzg_commitment/*/*/*"; - const COMPUTE_KZG_PROOF_TESTS: &str = "../../tests/compute_kzg_proof/*/*/*"; - const COMPUTE_BLOB_KZG_PROOF_TESTS: &str = "../../tests/compute_blob_kzg_proof/*/*/*"; - const VERIFY_KZG_PROOF_TESTS: &str = "../../tests/verify_kzg_proof/*/*/*"; - const VERIFY_BLOB_KZG_PROOF_TESTS: &str = "../../tests/verify_blob_kzg_proof/*/*/*"; - const VERIFY_BLOB_KZG_PROOF_BATCH_TESTS: &str = "../../tests/verify_blob_kzg_proof_batch/*/*/*"; + const BLOB_TO_KZG_COMMITMENT_TESTS: &str = "tests/blob_to_kzg_commitment/*/*/*"; + const COMPUTE_KZG_PROOF_TESTS: &str = "tests/compute_kzg_proof/*/*/*"; + const COMPUTE_BLOB_KZG_PROOF_TESTS: &str = "tests/compute_blob_kzg_proof/*/*/*"; + const VERIFY_KZG_PROOF_TESTS: &str = "tests/verify_kzg_proof/*/*/*"; + const VERIFY_BLOB_KZG_PROOF_TESTS: &str = "tests/verify_blob_kzg_proof/*/*/*"; + const VERIFY_BLOB_KZG_PROOF_BATCH_TESTS: &str = "tests/verify_blob_kzg_proof_batch/*/*/*"; #[test] fn test_blob_to_kzg_commitment() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(BLOB_TO_KZG_COMMITMENT_TESTS) @@ -687,7 +687,7 @@ mod tests { #[test] fn test_compute_kzg_proof() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(COMPUTE_KZG_PROOF_TESTS) @@ -716,7 +716,7 @@ mod tests { #[test] fn test_compute_blob_kzg_proof() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(COMPUTE_BLOB_KZG_PROOF_TESTS) @@ -743,7 +743,7 @@ mod tests { #[test] fn test_verify_kzg_proof() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(VERIFY_KZG_PROOF_TESTS) @@ -774,7 +774,7 @@ mod tests { #[test] fn test_verify_blob_kzg_proof() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(VERIFY_BLOB_KZG_PROOF_TESTS) @@ -804,7 +804,7 @@ mod tests { #[test] fn test_verify_blob_kzg_proof_batch() { - let trusted_setup_file = Path::new("../../src/trusted_setup.txt"); + let trusted_setup_file = Path::new("src/trusted_setup.txt"); assert!(trusted_setup_file.exists()); let kzg_settings = KZGSettings::load_trusted_setup_file(trusted_setup_file).unwrap(); let test_files: Vec = glob::glob(VERIFY_BLOB_KZG_PROOF_BATCH_TESTS)