Browse Source

feat: expose version info api

master
Dnomd343 1 year ago
parent
commit
73d17ff9eb
  1. 12
      src/klotski/ffi/klotski.h
  2. 28
      src/klotski/ffi/version.cc
  3. 21
      src/rust_ffi/src/main.rs

12
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

28
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;
}

21
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");
}

Loading…
Cancel
Save