move c++ bindings definition and usage to lib file
This commit is contained in:
2
build.rs
2
build.rs
@@ -1,7 +1,7 @@
|
||||
fn main() -> miette::Result<()> {
|
||||
let path = std::path::PathBuf::from("src/cpp"); // include path
|
||||
|
||||
let mut b = autocxx_build::Builder::new("src/main.rs", &[&path]).build()?;
|
||||
let mut b = autocxx_build::Builder::new("src/lib.rs", &[&path]).build()?;
|
||||
// This assumes all your C++ bindings are in main.rs
|
||||
b.flag_if_supported("-std=c++14")
|
||||
.flag("-fopenmp")
|
||||
|
||||
24
src/lib.rs
Normal file
24
src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use autocxx::prelude::*;
|
||||
|
||||
include_cpp! {
|
||||
#include "data.hpp"
|
||||
safety!(unsafe)
|
||||
generate!("Data")
|
||||
}
|
||||
|
||||
use ffi::Data as Data_;
|
||||
|
||||
pub fn generate_data(samples: &[i8]) -> UniquePtr<Data_> {
|
||||
let samples_length = samples.len() as i32;
|
||||
let bits_per_symbol = 8;
|
||||
|
||||
unsafe {
|
||||
ffi::Data::new2(
|
||||
samples.as_ptr(),
|
||||
samples_length.into(),
|
||||
bits_per_symbol.into(),
|
||||
false,
|
||||
)
|
||||
.within_unique_ptr()
|
||||
}
|
||||
}
|
||||
21
src/main.rs
21
src/main.rs
@@ -1,29 +1,16 @@
|
||||
use autocxx::prelude::*;
|
||||
use SP800_90B_rs::generate_data;
|
||||
use rand::Rng;
|
||||
|
||||
include_cpp! {
|
||||
#include "data.hpp"
|
||||
safety!(unsafe)
|
||||
generate!("Data")
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
// println!("Hello, world!");
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let samples: [i8; 1_000_000] = rng.gen();
|
||||
let samples_length = samples.len() as i32;
|
||||
let bits_per_symbol = 8;
|
||||
|
||||
let data = generate_data(&samples);
|
||||
|
||||
let data = unsafe {
|
||||
ffi::Data::new2(
|
||||
samples.as_ptr(),
|
||||
samples_length.into(),
|
||||
bits_per_symbol.into(),
|
||||
false,
|
||||
)
|
||||
.within_unique_ptr()
|
||||
};
|
||||
let a = data.iid_tests();
|
||||
|
||||
println!("{a:?}");
|
||||
|
||||
Reference in New Issue
Block a user