diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..4046bf0 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-target, wasm32-wasi] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f370694 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +examples = $(shell ls examples) + +build: + @for f in $(examples); do \ + $(MAKE) -C examples/$$f; \ + done diff --git a/examples/count-vowels/count-vowels.c b/examples/count-vowels/count-vowels.c index 1d53e7d..1e5b40d 100644 --- a/examples/count-vowels/count-vowels.c +++ b/examples/count-vowels/count-vowels.c @@ -1,6 +1,7 @@ #include "../../extism-pdk.h" #include +#include int32_t count_vowels() { uint64_t count = 0; diff --git a/examples/count-vowels/count-vowels.wasm b/examples/count-vowels/count-vowels.wasm index 43abc0a..f72eaae 100755 Binary files a/examples/count-vowels/count-vowels.wasm and b/examples/count-vowels/count-vowels.wasm differ diff --git a/examples/globals/globals.wasm b/examples/globals/globals.wasm index 0f22c62..ca3d276 100755 Binary files a/examples/globals/globals.wasm and b/examples/globals/globals.wasm differ diff --git a/examples/host-functions/host-functions.c b/examples/host-functions/host-functions.c index 3d77601..43a3d00 100644 --- a/examples/host-functions/host-functions.c +++ b/examples/host-functions/host-functions.c @@ -2,6 +2,7 @@ #include +IMPORT("extism:host/user", "hello_world") extern uint64_t hello_world(uint64_t); int32_t count_vowels() { diff --git a/examples/infinite-loop/infinite-loop.wasm b/examples/infinite-loop/infinite-loop.wasm index b6eeb93..c2f52ef 100755 Binary files a/examples/infinite-loop/infinite-loop.wasm and b/examples/infinite-loop/infinite-loop.wasm differ diff --git a/extism-pdk.h b/extism-pdk.h index 399b29b..524710e 100644 --- a/extism-pdk.h +++ b/extism-pdk.h @@ -2,61 +2,71 @@ #include -#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