Skip to content

Commit e6113ef

Browse files
committed
fix(taos-ws-sys): fix ws_get_client_info error
1 parent b408a2a commit e6113ef

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

taos-ws-sys/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ anyhow = "1"
1414
bytes = "1.1.0"
1515
pretty_env_logger = "0.5.0"
1616
serde_json = "1"
17-
cargo_metadata = "0.18.1"
1817
taos-error = { path = "../taos-error" }
1918
taos-query = { path = "../taos-query" }
2019
taos-ws = { path = "../taos-ws" }

taos-ws-sys/src/lib.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::thread;
99
use std::time::Duration;
1010

1111
use bytes::Bytes;
12-
use cargo_metadata::MetadataCommand;
1312
use taos_error::Code;
1413
use taos_query::common::{
1514
Field, Precision, RawBlock as Block, SchemalessPrecision, SchemalessProtocol, SmlDataBuilder,
@@ -1162,31 +1161,9 @@ pub unsafe extern "C" fn ws_select_db(taos: *mut WS_TAOS, db: *const c_char) ->
11621161
/// If the query is update query or not
11631162
pub unsafe extern "C" fn ws_get_client_info() -> *const c_char {
11641163
static VERSION_INFO: OnceLock<CString> = OnceLock::new();
1165-
1166-
let metadata = match MetadataCommand::new().no_deps().exec().ok() {
1167-
Some(m) => m,
1168-
_ => {
1169-
set_error_and_get_code(WsError::new(Code::FAILED, "Metadata Command error"));
1170-
return std::ptr::null();
1171-
}
1172-
};
1173-
1174-
let package = match metadata
1175-
.packages
1176-
.into_iter()
1177-
.find(|p| p.name == "taos-ws-sys")
1178-
{
1179-
Some(x) => x,
1180-
_ => {
1181-
set_error_and_get_code(WsError::new(Code::FAILED, "find package error"));
1182-
return std::ptr::null();
1183-
}
1184-
};
1185-
1186-
let version = package.version.to_string();
1187-
let version = CString::new(version).unwrap();
1188-
VERSION_INFO.set(version).unwrap();
1189-
VERSION_INFO.get().unwrap().as_ptr()
1164+
VERSION_INFO
1165+
.get_or_init(|| CString::new(env!("CARGO_PKG_VERSION")).unwrap())
1166+
.as_ptr() as _
11901167
}
11911168

11921169
#[no_mangle]
@@ -1763,6 +1740,10 @@ mod tests {
17631740
unsafe {
17641741
let pclient_info = ws_get_client_info();
17651742
dbg!(CStr::from_ptr(pclient_info));
1743+
assert_eq!(
1744+
CStr::from_ptr(pclient_info).to_str().unwrap(),
1745+
env!("CARGO_PKG_VERSION")
1746+
);
17661747
}
17671748
}
17681749

0 commit comments

Comments
 (0)