Skip to content

Commit

Permalink
Add GetVersion method to public API (#1479)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem V. Navrotskiy <[email protected]>
  • Loading branch information
bozaro authored Jul 8, 2024
1 parent 0c023c8 commit 1a9a729
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions kclvm/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ kclvm-ast-pretty = {path = "../ast_pretty"}
kclvm-runtime = {path = "../runtime"}
kclvm-tools = {path = "../tools" }
kclvm-query = {path = "../query"}
kclvm-version = { path = "../version" }
kcl-language-server = {path = "../tools/src/LSP"}
kclvm-utils = {path = "../utils"}

Expand Down
10 changes: 10 additions & 0 deletions kclvm/api/src/service/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub extern "C" fn kclvm_service_call_with_length(
pub(crate) fn kclvm_get_service_fn_ptr_by_name(name: &str) -> u64 {
match name {
"KclvmService.Ping" => ping as *const () as u64,
"KclvmService.GetVersion" => get_version as *const () as u64,
"KclvmService.ParseFile" => parse_file as *const () as u64,
"KclvmService.ParseProgram" => parse_program as *const () as u64,
"KclvmService.LoadPackage" => load_package as *const () as u64,
Expand Down Expand Up @@ -200,6 +201,15 @@ pub(crate) fn ping(
call!(serv, args, result_len, PingArgs, ping)
}

/// get_version is used to get kclvm service version
pub(crate) fn get_version(
serv: *mut kclvm_service,
args: *const c_char,
result_len: *mut usize,
) -> *const c_char {
call!(serv, args, result_len, GetVersionArgs, get_version)
}

/// parse_file provides users with the ability to parse kcl single file
///
/// # Parameters
Expand Down
9 changes: 9 additions & 0 deletions kclvm/api/src/service/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ fn register_kclvm_service(io: &mut IoHandler) {
};
futures::future::ready(catch!(kclvm_service_impl, args, ping))
});
io.add_method("KclvmService.GetVersion", |params: Params| {
let kclvm_service_impl = KclvmServiceImpl::default();
let args: GetVersionArgs = match params.parse() {
Ok(val) => val,
Err(err) => return futures::future::ready(Err(err)),
};
futures::future::ready(catch!(kclvm_service_impl, args, get_version))
});
io.add_method("KclvmService.ParseFile", |params: Params| {
let kclvm_service_impl = KclvmServiceImpl::default();
let args: ParseFileArgs = match params.parse() {
Expand Down Expand Up @@ -231,6 +239,7 @@ fn register_builtin_service(io: &mut IoHandler) {
let result = ListMethodResult {
method_name_list: vec![
"KclvmService.Ping".to_owned(),
"KclvmService.GetVersion".to_owned(),
"KclvmService.ParseFile".to_owned(),
"KclvmService.ParseProgram".to_owned(),
"KclvmService.ExecProgram".to_owned(),
Expand Down
24 changes: 24 additions & 0 deletions kclvm/api/src/service/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ impl KclvmServiceImpl {
})
}

/// GetVersion KclvmService, return the kclvm service version information
///
/// # Examples
///
/// ```
/// use kclvm_api::service::service_impl::KclvmServiceImpl;
/// use kclvm_api::gpyrpc::*;
/// let serv = KclvmServiceImpl::default();
/// let args = &GetVersionArgs {
/// ..Default::default()
/// };
/// let get_version_result = serv.get_version(args).unwrap();
/// assert!(get_version_result.version_info.to_string().contains("Version"), "{0}", get_version_result.version_info);
/// ```
///
pub fn get_version(&self, _args: &GetVersionArgs) -> anyhow::Result<GetVersionResult> {
Ok(GetVersionResult {
version: kclvm_version::VERSION.to_string(),
checksum: kclvm_version::CHECK_SUM.to_string(),
git_sha: kclvm_version::GIT_SHA.to_string(),
version_info: kclvm_version::get_version_info(),
})
}

/// Parse KCL program with entry files.
///
/// # Examples
Expand Down
11 changes: 11 additions & 0 deletions kclvm/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ service BuiltinService {
// gpyrpc.KclvmService
service KclvmService {
rpc Ping(Ping_Args) returns(Ping_Result);
rpc GetVersion(GetVersion_Args) returns(GetVersion_Result);

rpc ExecProgram(ExecProgram_Args) returns(ExecProgram_Result);
rpc BuildProgram(BuildProgram_Args) returns(BuildProgram_Result);
Expand Down Expand Up @@ -83,6 +84,16 @@ message Ping_Result {
string value = 1;
}

message GetVersion_Args {
// empty
}
message GetVersion_Result {
string version = 1;
string checksum = 2;
string git_sha = 3;
string version_info = 4;
}

message ListMethod_Args {
// empty
}
Expand Down
1 change: 1 addition & 0 deletions kclvm/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub const VERSION: &str = include_str!("./../../../VERSION");
pub const CHECK_SUM: &str = "c020ab3eb4b9179219d6837a57f5d323";
pub const GIT_SHA: &str = env!("VERGEN_GIT_SHA");

/// Get kCL full version string with the format `{version}-{check_sum}`.
#[inline]
Expand Down

0 comments on commit 1a9a729

Please sign in to comment.