-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,49 @@ | ||
require 'ffi' | ||
require 'json' | ||
require_relative './extism/version' | ||
require_relative './extism/plugin' | ||
require_relative './extism/current_plugin' | ||
require_relative './extism/libextism' | ||
require_relative './extism/wasm' | ||
require_relative './extism/host_environment' | ||
|
||
module Extism | ||
class Error < StandardError | ||
end | ||
|
||
# Return the version of Extism | ||
# | ||
# @return [String] The version string of the Extism runtime | ||
def self.extism_version | ||
LibExtism.extism_version | ||
end | ||
|
||
# Set log file and level, this is a global configuration | ||
# @param name [String] The path to the logfile | ||
# @param level [String] The log level. One of {"debug", "error", "info", "trace" } | ||
def self.set_log_file(name, level = nil) | ||
LibExtism.extism_log_file(name, level) | ||
end | ||
|
||
$PLUGINS = {} | ||
$FREE_PLUGIN = proc { |ptr| | ||
x = $PLUGINS[ptr] | ||
unless x.nil? | ||
LibExtism.extism_plugin_free(x[:plugin]) | ||
$PLUGINS.delete(ptr) | ||
end | ||
} | ||
|
||
# Represents a "block" of memory in Extism. | ||
# This memory is in the communication buffer b/w the | ||
# guest in the host and technically lives in host memory. | ||
class Memory | ||
attr_reader :offset, :len | ||
|
||
def initialize(offset, len) | ||
@offset = offset | ||
@len = len | ||
end | ||
end | ||
end | ||
require 'ffi' | ||
require 'json' | ||
require_relative './extism/manifest' | ||
require_relative './extism/version' | ||
require_relative './extism/plugin' | ||
require_relative './extism/current_plugin' | ||
require_relative './extism/libextism' | ||
require_relative './extism/wasm' | ||
require_relative './extism/host_environment' | ||
|
||
module Extism | ||
class Error < StandardError | ||
end | ||
|
||
# Return the version of Extism | ||
# | ||
# @return [String] The version string of the Extism runtime | ||
def self.extism_version | ||
LibExtism.extism_version | ||
end | ||
|
||
# Set log file and level, this is a global configuration | ||
# @param name [String] The path to the logfile | ||
# @param level [String] The log level. One of {"debug", "error", "info", "trace" } | ||
def self.set_log_file(name, level = nil) | ||
LibExtism.extism_log_file(name, level) | ||
end | ||
|
||
$PLUGINS = {} | ||
$FREE_PLUGIN = proc { |ptr| | ||
x = $PLUGINS[ptr] | ||
unless x.nil? | ||
LibExtism.extism_plugin_free(x[:plugin]) | ||
$PLUGINS.delete(ptr) | ||
end | ||
} | ||
|
||
# Represents a "block" of memory in Extism. | ||
# This memory is in the communication buffer b/w the | ||
# guest in the host and technically lives in host memory. | ||
class Memory | ||
attr_reader :offset, :len | ||
|
||
def initialize(offset, len) | ||
@offset = offset | ||
@len = len | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Extism | ||
class Manifest | ||
attr_reader :manifest_data | ||
|
||
# Create a manifest of a single wasm from url. | ||
# Look at {Manifest#new} for an interface with more control | ||
# | ||
# @see Manifest::new | ||
# @param [String] url The url to the wasm module | ||
# @param [String | nil] url An optional sha256 integrity hash. Defaults to nil | ||
# @param [String | nil] An optional name. Defaults to nil | ||
# @returns [Extism::Manifest] | ||
def self.from_url(url, hash: nil, name: nil) | ||
wasm = { url: url } | ||
wasm[:hash] = hash unless hash.nil? | ||
wasm[:name] = name unless hash.nil? | ||
|
||
Manifest.new({ wasm: [wasm] }) | ||
end | ||
|
||
# Create a manifest of a single wasm from file path. | ||
# Look at {Manifest#new} for an interface with more control | ||
# | ||
# @see Manifest::new | ||
# @param [String] path The path to the wasm module on disk | ||
# @param [String | nil] url An optional sha256 integrity hash. Defaults to nil | ||
# @param [String | nil] An optional name. Defaults to nil | ||
# @returns [Extism::Manifest] | ||
def self.from_path(path, hash: nil, name: nil) | ||
wasm = { path: path } | ||
wasm[:hash] = hash unless hash.nil? | ||
wasm[:name] = name unless hash.nil? | ||
|
||
Manifest.new({ wasm: [wasm] }) | ||
end | ||
|
||
# Create a manifest of a single wasm module with raw binary data. | ||
# Look at {Manifest#new} for an interface with more control | ||
# Consider using a file path instead of the raw wasm binary in memory. | ||
# The performance is often better letting the runtime load the binary itself. | ||
# | ||
# @see Manifest::new | ||
# @param [String] The binary data of the wasm module | ||
# @param [String | nil] hash An optional sha256 integrity hash. Defaults to nil | ||
# @param [String | nil] name An optional name. Defaults to nil | ||
# @returns [Extism::Manifest] | ||
def self.from_bytes(data, hash: nil, name: nil) | ||
wasm = { data: data } | ||
wasm[:hash] = hash unless hash.nil? | ||
wasm[:name] = name unless hash.nil? | ||
|
||
Manifest.new({ wasm: [wasm] }) | ||
end | ||
|
||
# Initialize a manifest | ||
# See https://extism.org/docs/concepts/manifest for schema | ||
# | ||
# @param | ||
def initialize(hash) | ||
@manifest_data = hash | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters