Hi,
Well i do not know where t start looking for the issue and therefore I need some pointers. Situation is the following. I wrote this program that depends on some c++ function. This function receives a reference to a vector that it fills out. so when i cargo build
or cargo run
i see the content of that vector but if i do cargo build --release
or i cargo run --release
i get an empty vector. Why and how to fix this ?
My toml:
[package]
name = "tool"
version = "0.1.0"
edition = "2021"
[dependencies]
libc = "*"
fxhash = "*"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rustop = "*"
regex = "*"
itertools = "*"
md5 = "*"
flate2 = "*"
[build-dependencies]
cc = { version = "*", features = ["parallel"] }
My build.sh:
const FILES: &[&str] = &[
"src/k/c/candidates.cpp",
"src/k/c/rescue.cpp",
"src/k/c/tools.cpp",
"src/k/c/abi.cpp",
];
const HEADERS: &[&str] = &[
"src/k/c/structure.h",
"src/k/c/kstring.h",
"src/k/c/keq.h",
];
fn main() {
for file in FILES {
println!("cargo:rerun-if-changed={}", file);
}
for file in HEADERS {
println!("cargo:rerun-if-changed={}", file);
}
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=m");
println!("cargo:rustc-link-lib=stdc++");
cc::Build::new()
.define("COMPILATION_TIME_PLACE", "\"build.rs\"")
.warnings(false)
.extra_warnings(false)
.files(FILES)
.flag("-fPIC")
.compile("k.a");
}
function in my tool.rs:
use crate::{Error, ErrorKind, Result};
use libc::{c_int, c_char};
extern {
pub fn k (batch:*const c_char, result:*const c_char, sep: c_char, len: c_int, con: c_int) -> c_int;
}
pub(crate) fn k (&self, batch: &[u8]) ->Result<Vec<u8>>{
let cval = 12;
let mut blen = batch.len() * cval;
let mut result = vec![0i8; blen];
let len = unsafe {
k( batch.as_ptr() as *const i8, result.as_ptr() as *const i8, '|' as i8, batch.len() as i32, cval as i32) as usize
};
result.resize(len as usize,0);
println!("{:?}",result);
// stuff ...
Ok(result)
}
What am i not understanding / missing here ?
Thank you !
PS:
Sorry for that semi example but i do not where to start ...