From 73d17ff9ebff6ddd4806684471062133fbb8c99b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 28 Jan 2023 13:18:58 +0800 Subject: [PATCH] feat: expose version info api --- src/klotski/ffi/klotski.h | 12 ++++++++---- src/klotski/ffi/version.cc | 28 ++++++++++++++++++++++++++++ src/rust_ffi/src/main.rs | 21 ++++++++++++++++++++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h index 1f2ee51..1733b5e 100644 --- a/src/klotski/ffi/klotski.h +++ b/src/klotski/ffi/klotski.h @@ -22,14 +22,18 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif -// extern char* get_author(); -// extern char* get_project_url(); -// extern char* get_compile_time(); - /// version -> major.minor.patch extern int get_version_major(); extern int get_version_minor(); extern int get_version_patch(); + + extern const char* get_author(); + extern const char* get_version(); + extern const char* get_commit_id(); + extern const char* get_build_time(); + extern const char* get_project_url(); + extern const char* get_system_info(); + extern const char* get_compiler_info(); #ifdef __cplusplus } #endif diff --git a/src/klotski/ffi/version.cc b/src/klotski/ffi/version.cc index 7966d53..882999c 100644 --- a/src/klotski/ffi/version.cc +++ b/src/klotski/ffi/version.cc @@ -12,3 +12,31 @@ int get_version_minor() { int get_version_patch() { return VERSION_PATCH; } + +const char* get_author() { + return AUTHOR; +} + +const char* get_version() { + return VERSION_STR; +} + +const char* get_commit_id() { + return GIT_COMMIT_ID; +} + +const char* get_build_time() { + return BUILD_TIME; +} + +const char* get_project_url() { + return PROJECT_URL; +} + +const char* get_system_info() { + return SYSTEM; +} + +const char* get_compiler_info() { + return COMPILER; +} diff --git a/src/rust_ffi/src/main.rs b/src/rust_ffi/src/main.rs index 96ade13..77899e0 100644 --- a/src/rust_ffi/src/main.rs +++ b/src/rust_ffi/src/main.rs @@ -4,6 +4,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); use std::env; +use std::ffi::CStr; fn klotski_tmain() { unsafe { @@ -11,8 +12,26 @@ fn klotski_tmain() { } } +fn klotski_version() -> String { + unsafe { + // let v_major = get_version_major(); + + let v = get_version(); + let csp: &CStr = CStr::from_ptr(v); + let s: &str = csp.to_str().unwrap(); + // println!("klotski version -> {}", s); + + String::from(s) + // String::new() + } +} + fn main() { println!("rust start"); - klotski_tmain(); + + // klotski_tmain(); + + println!("version -> {}", klotski_version()); + println!("rust exit"); }