{"id":18462665,"url":"https://github.com/extism/wamr-sdk","last_synced_at":"2025-04-08T07:32:21.301Z","repository":{"id":238749520,"uuid":"796921150","full_name":"extism/wamr-sdk","owner":"extism","description":"A lightweight WAMR backend for Extism","archived":false,"fork":false,"pushed_at":"2024-08-09T02:02:35.000Z","size":193,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-23T08:42:00.137Z","etag":null,"topics":["extism","iot","plugins","runtime","wamr","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://extism.org","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/extism.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T21:43:48.000Z","updated_at":"2024-07-09T00:59:22.000Z","dependencies_parsed_at":"2024-08-08T00:54:33.317Z","dependency_job_id":"01db20fa-6c9d-4dea-92ad-e767086ce9b6","html_url":"https://github.com/extism/wamr-sdk","commit_stats":null,"previous_names":["extism/extism-wamr","extism/wamr-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extism%2Fwamr-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extism%2Fwamr-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extism%2Fwamr-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extism%2Fwamr-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extism","download_url":"https://codeload.github.com/extism/wamr-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796295,"owners_count":20997545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extism","iot","plugins","runtime","wamr","wasm","webassembly"],"created_at":"2024-11-06T09:03:57.447Z","updated_at":"2025-04-08T07:32:21.015Z","avatar_url":"https://github.com/extism.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# WAMR SDK\n\nA lightweight [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) backend for Extism\n\nSupports a limited set of features compared to [extism/extism](https://github.com/extism/extism):\n\n- Host functions\n- Memory limits\n\nIn progress:\n\n- Linking multiple Wasm modules\n\n\n## Building\n\nRequires:\n- CMake\n- C compiler\n\n```bash\nmkdir build\ncd build\ncmake ..\nmake\n```\n\nor:\n\n```bash\nmake\n```\n\n## Getting started\n\n- `extism_runtime_init` should always be called before creating any plugins, and there\n  is only a single global runtime that host functions can be loaded into\n- The plugins listed in `ExtismManifest` that depend on other Wasm modules must have all \n  dependencies listed first in the manifest with module names specified.\n\n### Creating and calling a plugin\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cextism-wamr.h\u003e\n\n// Read a file from disk - an implementation of `read_file` can be found \n// in `bin/extism-wamr.c`\nuint8_t *read_file(const char *, size_t *);\n\n// Return the input as-is\nuint64_t host_reflect(ExtismExecEnv *env, uint64_t x) { return x; }\n\n// Run an Extism plugin and print the output\nExtismStatus run_wasm(const char *wasm_file, const char *func_name, const char *input, size_t input_len){\n  char errbuf[1024];\n  size_t datalen = 0, len = 0;\n  uint8_t *data = read_file(wasm_file, \u0026datalen);\n  if (data == NULL) {\n    return ExtismStatusErr;\n  }\n\n  // Initialize the runtime, this must be done before anything else \n  extism_runtime_init();\n\n  // Specify the modules to be loaded, setting `name` to `NULL` marks a module\n  // at the main module\n  ExtismWasm wasm = {\n      .data = data,\n      .length = datalen,\n      .name = NULL,\n  };\n  ExtismManifest manifest;\n  extism_manifest_init(\u0026manifest, \u0026wasm, 1, NULL, 0, NULL);\n\n  // Define a host function\n  extism_host_function(\"extism:host/user\", \"host_reflect\", \"(I)I\", host_reflect,\n                       NULL);\n\n  // Create the plugin instance\n  ExtismPlugin *plugin = extism_plugin_new(\u0026manifest, errbuf, 1024);\n  if (plugin == NULL) {\n    fputs(\"ERROR: \", stderr);\n    fputs(errbuf, stderr);\n    fputs(\"\\n\", stderr);\n    free(data);\n    extism_runtime_cleanup();\n    return ExtismStatusErr;\n  }\n\n  // Call `func_name`\n  if ((status = extism_plugin_call(plugin, func_name, (const void *)input,\n                                   input_len)) != ExtismStatusOk) {\n    // Print error if it fails\n    const char *s = extism_plugin_error(plugin, \u0026len);\n    fprintf(stderr, \"ERROR(%d): \", status);\n    fwrite(s, len, 1, stderr);\n    fputc('\\n', stderr);\n  } else {\n    // Otherwise print the output\n    uint8_t *output = extism_plugin_output(plugin, \u0026len);\n    if (len \u003e 0) {\n      fwrite(output, len, 1, stdout);\n      fputc('\\n', stdout);\n    }\n  }\n\n  // Cleanup\n  extism_plugin_free(plugin);\n  extism_runtime_cleanup();\n  free(data);\n  return ExtismStatusOk;\n}\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextism%2Fwamr-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextism%2Fwamr-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextism%2Fwamr-sdk/lists"}