Skip to content

Commit

Permalink
chore: update to latest extism API, remove ExtismContext (#2)
Browse files Browse the repository at this point in the history
* chore: update to latest extism API, remove ExtismContext

* chore: use new cli
  • Loading branch information
zshipko authored Oct 3, 2023
1 parent 088f045 commit 7a14e22
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
17 changes: 17 additions & 0 deletions .github/actions/libextism/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on: [workflow_call]

name: libextism

runs:
using: composite
steps:
- uses: actions/checkout@v3
with:
repository: extism/cli
path: .extism-cli
- uses: ./.extism-cli/.github/actions/extism-cli
- name: Install
shell: bash
run: sudo extism lib install --version git
env:
GITHUB_TOKEN: ${{ github.token }}
24 changes: 1 addition & 23 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: "3.9"
check-latest: true

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Checkout extism/cli
uses: actions/checkout@v3
with:
repository: extism/cli
path: cli

- name: Install Extism & CLI
run: |
pushd cli
pip3 install cffi
pip3 install .
popd
extism install git
- uses: ./.github/actions/libextism

- name: make
run: make
Expand Down
34 changes: 19 additions & 15 deletions extism-dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) {
return 1;
}

char *errmsg = NULL; // Plugin error message
int ret = 0; // Return value
size_t wasmLength = 0; // Length of WASM data
uint8_t *wasm = read_file(argv[1], &wasmLength); // Alloc wasm
Expand All @@ -40,20 +41,20 @@ int main(int argc, char *argv[]) {
uint8_t *data = NULL; // Input data
size_t dataLength = 0; // Input data length

// Create context
ExtismContext *ctx = extism_context_new(); // Alloc ctx

// Create plugin
setenv("EXTISM_DEBUG", "1", 0);
ExtismPlugin plugin =
extism_plugin_new(ctx, wasm, wasmLength, NULL, 0, true); // Alloc plugin
free(wasm); // Free wasm
if (plugin < 0) {
BAIL("%s", extism_error(ctx, plugin));
ExtismPlugin *plugin = extism_plugin_new(wasm, wasmLength, NULL, 0, true,
&errmsg); // Alloc plugin
free(wasm); // Free wasm
if (errmsg != NULL) {
BAIL("%s", errmsg);
}
if (plugin == NULL) {
BAIL("%s", "unable to create plugin");
}

// Make sure that the specified function exists before reading input
if (!extism_plugin_function_exists(ctx, plugin, argv[2])) {
if (!extism_plugin_function_exists(plugin, argv[2])) {
BAIL("Function does not exist in plugin: %s", argv[2]);
}

Expand All @@ -78,13 +79,13 @@ int main(int argc, char *argv[]) {
}

// Call the function
uint32_t rc = extism_plugin_call(ctx, plugin, argv[2], data, dataLength);
uint32_t rc = extism_plugin_call(plugin, argv[2], data, dataLength);
if (rc != 0) {
BAIL("%s", extism_error(ctx, plugin));
BAIL("%s", extism_error(plugin));
} else {
// Handle error
const uint8_t *output = extism_plugin_output_data(ctx, plugin);
size_t outputLength = extism_plugin_output_length(ctx, plugin);
const uint8_t *output = extism_plugin_output_data(plugin);
size_t outputLength = extism_plugin_output_length(plugin);
write(STDOUT_FILENO, output, outputLength);
}

Expand All @@ -94,8 +95,11 @@ int main(int argc, char *argv[]) {
free(data); // Free data
}

extism_plugin_free(ctx, plugin); // Free plugin
extism_context_free(ctx); // Free ctx
if (errmsg != NULL) {
extism_plugin_new_error_free(errmsg);
}

extism_plugin_free(plugin); // Free plugin
return ret;
}

Expand Down

0 comments on commit 7a14e22

Please sign in to comment.