Add version to Host SDK and all clients

This commit is contained in:
Benjamin Eckel
2022-10-17 09:25:22 -05:00
parent 15cd047569
commit 85b3aece6f
11 changed files with 52 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ let _functions = {
extism_plugin_config: ['void', [context, 'int32', 'char*', 'uint64']],
extism_plugin_free: ['void', [context, 'int32']],
extism_context_reset: ['void', [context]],
extism_version: ['char*', []],
};
function locate(paths) {
@@ -50,6 +51,11 @@ export function setLogFile(filename, level = null) {
lib.extism_log_file(filename, level);
}
// Get the version of Extism
export function extismVersion() {
return lib.extism_version().toString();
}
const pluginRegistry = new FinalizationRegistry(({ id, pointer }) => {
lib.extism_plugin_free(pointer, id);
});

View File

@@ -77,6 +77,9 @@ module Bindings = struct
let extism_log_file =
fn "extism_log_file" (string @-> string_opt @-> returning bool)
let extism_version =
fn "extism_version" (void @-> returning string)
let extism_plugin_free =
fn "extism_plugin_free" (context @-> int32_t @-> returning void)
@@ -267,3 +270,5 @@ let function_exists { id; ctx } name =
Bindings.extism_plugin_function_exists ctx.pointer id name
let set_log_file ?level filename = Bindings.extism_log_file filename level
let extism_version = Bindings.extism_version

View File

@@ -51,3 +51,11 @@ function set_log_file($filename, $level)
$lib->extism_log_file($filename, $level);
}
function extism_version()
{
global $lib;
return $lib->extism_version();
}

View File

@@ -32,3 +32,5 @@ ExtismSize extism_output_length(ExtismPlugin plugin);
void extism_output_get(ExtismPlugin plugin, uint8_t *buf, ExtismSize len);
bool extism_log_file(const char *filename, const char *log_level);
const char *extism_version();

View File

@@ -1 +1 @@
from .extism import Error, Plugin, set_log_file, Context
from .extism import Error, Plugin, set_log_file, Context, extism_version

View File

@@ -93,6 +93,9 @@ def set_log_file(file, level=ffi.NULL):
level = level.encode()
lib.extism_log_file(file.encode(), level)
def extism_version():
'''Gets the Extism version string'''
return ffi.string(lib.extism_version()).decode()
def _wasm(plugin):
if isinstance(plugin, str) and os.path.exists(plugin):

View File

@@ -17,12 +17,18 @@ module Extism
attach_function :extism_log_file, [:string, :pointer], :void
attach_function :extism_plugin_free, [:pointer, :int32], :void
attach_function :extism_context_reset, [:pointer], :void
attach_function :extism_version, [], :string
end
class Error < StandardError
end
# Return the version of Extism
def self.extism_version
C.extism_version
end
# Set log file and level, this is a global configuration
def self.set_log_file(name, level=nil)
if level then

View File

@@ -106,3 +106,5 @@ const uint8_t *extism_plugin_output_data(struct ExtismContext *ctx, ExtismPlugin
* Set log file and level
*/
bool extism_log_file(const char *filename, const char *log_level);
const uint8_t *extism_version(void);

View File

@@ -383,5 +383,11 @@ pub unsafe extern "C" fn extism_log_file(
if log4rs::init_config(config).is_err() {
return false;
}
true
}
#[no_mangle]
pub unsafe extern "C" fn extism_version() -> *const u8 {
env!("CARGO_PKG_VERSION").as_ptr()
}

View File

@@ -82,3 +82,9 @@ extern "C" {
log_level: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn extism_version(
) -> *const ::std::os::raw::c_char;
}

View File

@@ -24,6 +24,13 @@ impl From<serde_json::Error> for Error {
}
}
/// Get's the version of Extism
pub fn extism_version() -> String {
let err = unsafe { bindings::extism_version() };
let buf = unsafe { std::ffi::CStr::from_ptr(err) };
return buf.to_str().unwrap().to_string();
}
/// Set the log file and level, this is a global setting
pub fn set_log_file(filename: impl AsRef<std::path::Path>, log_level: Option<log::Level>) {
let log_level = log_level.map(|x| x.as_str());