Skip to content

Commit

Permalink
chore: use extism:host/env namespace (#7)
Browse files Browse the repository at this point in the history
* chore: use extism:env namespace

* chore: update examples

* cleanup: use extism:user namespace for user-defined host functions

* fix: use extism:host/env and extism:host/user
  • Loading branch information
zshipko authored Oct 30, 2023
1 parent e76c421 commit ef615a8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-target, wasm32-wasi]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
examples = $(shell ls examples)

build:
@for f in $(examples); do \
$(MAKE) -C examples/$$f; \
done
1 change: 1 addition & 0 deletions examples/count-vowels/count-vowels.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../../extism-pdk.h"

#include <stdio.h>
#include <string.h>

int32_t count_vowels() {
uint64_t count = 0;
Expand Down
Binary file modified examples/count-vowels/count-vowels.wasm
Binary file not shown.
Binary file modified examples/globals/globals.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions examples/host-functions/host-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stdio.h>

IMPORT("extism:host/user", "hello_world")
extern uint64_t hello_world(uint64_t);

int32_t count_vowels() {
Expand Down
Binary file modified examples/infinite-loop/infinite-loop.wasm
Binary file not shown.
56 changes: 33 additions & 23 deletions extism-pdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,71 @@

#include <stdint.h>

#define IMPORT(a, b) __attribute__((import_module(a), import_name(b)))

typedef uint64_t ExtismPointer;

IMPORT("env", "extism_input_length") extern uint64_t extism_input_length();
IMPORT("env", "extism_length") extern uint64_t extism_length(ExtismPointer);
IMPORT("env", "extism_alloc") extern ExtismPointer extism_alloc(uint64_t);
IMPORT("env", "extism_free") extern void extism_free(ExtismPointer);
#define EXTISM_ENV_MODULE "extism:host/env"
#define EXTISM_USER_MODULE "extism:host/user"

IMPORT("env", "extism_input_load_u8")
#define IMPORT(a, b) __attribute__((import_module(a), import_name(b)))
#define IMPORT_ENV(b) \
__attribute__((import_module(EXTISM_ENV_MODULE), import_name(b)))
#define IMPORT_USER(b) \
__attribute__((import_module(EXTISM_USER_MODULE), import_name(b)))

IMPORT_ENV("input_length")
extern uint64_t extism_input_length();
IMPORT_ENV("length")
extern uint64_t extism_length(ExtismPointer);
IMPORT_ENV("alloc")
extern ExtismPointer extism_alloc(uint64_t);
IMPORT_ENV("free") extern void extism_free(ExtismPointer);

IMPORT_ENV("input_load_u8")
extern uint8_t extism_input_load_u8(ExtismPointer);

IMPORT("env", "extism_input_load_u64")
IMPORT_ENV("input_load_u64")
extern uint64_t extism_input_load_u64(ExtismPointer);

IMPORT("env", "extism_output_set")
IMPORT_ENV("output_set")
extern void extism_output_set(ExtismPointer, uint64_t);

IMPORT("env", "extism_error_set")
IMPORT_ENV("error_set")
extern void extism_error_set(ExtismPointer);

IMPORT("env", "extism_config_get")
IMPORT_ENV("config_get")
extern ExtismPointer extism_config_get(ExtismPointer);

IMPORT("env", "extism_var_get")
IMPORT_ENV("var_get")
extern ExtismPointer extism_var_get(ExtismPointer);

IMPORT("env", "extism_var_set")
IMPORT_ENV("var_set")
extern void extism_var_set(ExtismPointer, ExtismPointer);

IMPORT("env", "extism_store_u8")
IMPORT_ENV("store_u8")
extern void extism_store_u8(ExtismPointer, uint8_t);

IMPORT("env", "extism_load_u8")
IMPORT_ENV("load_u8")
extern uint8_t extism_load_u8(ExtismPointer);

IMPORT("env", "extism_store_u64")
IMPORT_ENV("store_u64")
extern void extism_store_u64(ExtismPointer, uint64_t);

IMPORT("env", "extism_load_u64")
IMPORT_ENV("load_u64")
extern uint64_t extism_load_u64(ExtismPointer);

IMPORT("env", "extism_http_request")
IMPORT_ENV("http_request")
extern ExtismPointer extism_http_request(ExtismPointer, ExtismPointer);

IMPORT("env", "extism_http_status_code")
IMPORT_ENV("http_status_code")
extern int32_t extism_http_status_code();

IMPORT("env", "extism_log_info")
IMPORT_ENV("log_info")
extern void extism_log_info(ExtismPointer);
IMPORT("env", "extism_log_debug")
IMPORT_ENV("log_debug")
extern void extism_log_debug(ExtismPointer);
IMPORT("env", "extism_log_warn")
IMPORT_ENV("log_warn")
extern void extism_log_warn(ExtismPointer);
IMPORT("env", "extism_log_error")
IMPORT_ENV("log_error")
extern void extism_log_error(ExtismPointer);

// Load data from Extism memory
Expand Down

0 comments on commit ef615a8

Please sign in to comment.