diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 0b54d21b..8ff9c20c 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -1,6 +1,7 @@ mod initialization; mod log; mod post_impl; +mod version; #[repr(C)] #[derive(Debug, Clone, Copy)] diff --git a/ffi/src/version.rs b/ffi/src/version.rs new file mode 100644 index 00000000..60480eb8 --- /dev/null +++ b/ffi/src/version.rs @@ -0,0 +1,17 @@ +use std::ffi::{c_char, CStr}; + +const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "\0"); + +#[no_mangle] +pub extern "C" fn version() -> *const c_char { + unsafe { CStr::from_bytes_with_nul_unchecked(VERSION.as_bytes()) }.as_ptr() +} + +#[cfg(test)] +mod tests { + #[test] + fn test_version() { + let version = unsafe { std::ffi::CStr::from_ptr(super::version()) }; + assert_eq!(version.to_str().unwrap(), env!("CARGO_PKG_VERSION")); + } +}