{"id":50275386,"url":"https://github.com/opencow42/swift-wasmtime","last_synced_at":"2026-05-27T20:01:01.050Z","repository":{"id":359974133,"uuid":"1245907676","full_name":"OpenCow42/swift-wasmtime","owner":"OpenCow42","description":"Swift 6 Wasmtime wrapper for SwiftPM, vendoring the official C API artifacts for macOS, Linux, and Windows.","archived":false,"fork":false,"pushed_at":"2026-05-23T10:21:52.000Z","size":96955,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-24T12:37:26.025Z","etag":null,"topics":["c-api","linux","macos","swift","swift-package-manager","swift6","wasi","wasm","wasmtime","webassembly","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenCow42.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":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-21T17:16:55.000Z","updated_at":"2026-05-23T14:07:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/OpenCow42/swift-wasmtime","commit_stats":null,"previous_names":["opencow42/swift-wasmtime"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/OpenCow42/swift-wasmtime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCow42%2Fswift-wasmtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCow42%2Fswift-wasmtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCow42%2Fswift-wasmtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCow42%2Fswift-wasmtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenCow42","download_url":"https://codeload.github.com/OpenCow42/swift-wasmtime/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCow42%2Fswift-wasmtime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33581559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-api","linux","macos","swift","swift-package-manager","swift6","wasi","wasm","wasmtime","webassembly","windows"],"created_at":"2026-05-27T20:01:00.299Z","updated_at":"2026-05-27T20:01:01.016Z","avatar_url":"https://github.com/OpenCow42.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift Wasmtime\n\n[![Swift Package Index](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOpenCow42%2Fswift-wasmtime%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/OpenCow42/swift-wasmtime)\n[![Swift Package Index](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOpenCow42%2Fswift-wasmtime%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/OpenCow42/swift-wasmtime)\n\n🪟 Windows is supported alongside macOS and Linux.\n\nSwift Wasmtime is a SwiftPM wrapper around the official Wasmtime C API. The\npackage vendors Wasmtime C API libraries for macOS, Linux, and Windows, exposes a\nsmall Swift 6 API, and keeps the C ownership rules explicit.\n\n## Project Status\n\nThis is a community build/test package, not an official Wasmtime distribution.\nIt exists to explore a small, Swift-native API over Wasmtime while keeping usage\nfrom SwiftPM projects as straightforward as possible.\n\nThe current vendoring model is intentionally pragmatic and somewhat subpar:\nWasmtime is implemented in Rust and distributed to C consumers as prebuilt C API\nartifacts, while SwiftPM does not currently have a first-class cross-platform\nstory for vendored Rust-built C ABI libraries. This package therefore vendors\nthe official Wasmtime C API artifacts and uses linker search paths selected by\nplatform and architecture. Ease of use from SwiftPM is important to this project,\neven though the packaging tradeoff is not as clean as a native SwiftPM C/C++\nsource target. Upstream Rust toolchain requirements apply when building\nWasmtime itself from source; normal Swift package consumers use the prebuilt C\nAPI artifacts vendored here.\n\n## Current Scope\n\n- Core runtime wrappers: `Config`, `Engine`, `Store`, `Module`,\n  `ModuleImport`, `ModuleExport`, `ModuleExternType`, `Instance`,\n  `InstancePre`, `Linker`, `Extern`, `Func`, `GlobalType`, `Global`,\n  `TableElementKind`, `TableElement`, `TableType`, `Table`, `MemoryType`,\n  `Memory`, `Value`, `Trap`, `WasmtimeError`, and `WasiConfig`.\n- Swift 6 thread-safe surface: `EngineOptions` for sendable engine\n  configuration, `WasiOptions` for sendable WASI configuration, and\n  `WasmtimeRuntime` for actor-serialized store execution.\n- Config knobs for component model, core Wasm proposals, SIMD/relaxed SIMD,\n  compilation strategy including Winch selection, Cranelift optimization,\n  regalloc algorithm, flags/debug verification/NaN canonicalization, profiling\n  strategy, target triples, trap handling, debug info, native unwind info,\n  macOS Mach-port handling, parallel compilation, linear-memory\n  reservation/guard sizing and copy-on-write initialization, fuel consumption,\n  epoch interruption, and maximum Wasm stack size.\n- Resource-control APIs for fuel, epoch deadlines, epoch interruption callbacks,\n  store resource limits, explicit store GC, and engine epoch increments, exposed\n  both through low-level `Store`/`Engine` wrappers and `WasmtimeRuntime`.\n- Early component-model wrappers: `Component`, `ComponentLinker`,\n  `ComponentInstance`, and `ComponentFunction` for compiling components,\n  registering WASIp2/WASI HTTP host interfaces, instantiating components, and\n  calling zero-parameter, zero-result component functions.\n- Module compilation from Wasm bytes, `Data`, or WAT text via Wasmtime's\n  `wat2wasm` C API, validation of Wasm bytes before compilation, shallow\n  module cloning, compiled module serialization/deserialization artifacts, plus\n  import/export type metadata inspection for functions, globals, tables, and\n  memories.\n- Direct instantiation, linker instantiation, exported function lookup, checked\n  calls for `i32`, `i64`, `f32`, `f64`, and SIMD-backed `v128`, function\n  signature introspection, trap/error conversion with typed `TrapCode`,\n  host-side trap/error helpers, `WasmFrame`/`WasmTrace` diagnostics, and WASI\n  configuration including arguments, environment, stdio files, stdin bytes,\n  stdout/stderr callbacks, preopened directories, network inheritance, and IP\n  name lookup.\n- Linear memory support through `MemoryType`, `Memory`, exported memory lookup,\n  safe copy-based memory reads/writes, memory growth, and actor-isolated\n  `WasmtimeRuntime` memory helpers.\n- Numeric scalar and `v128` global support through `GlobalType`, `Global`,\n  exported global lookup, immutable and mutable global reads/writes,\n  linker-defined globals, and actor-isolated `WasmtimeRuntime` global helpers.\n- Table support through `TableType`, `Table`, exported table lookup, table size,\n  table growth, linker-defined tables, function references, and null\n  `funcref`/`externref` elements, including actor-isolated `WasmtimeRuntime`\n  table helpers. Arbitrary non-null host `externref` payloads are intentionally\n  deferred until broader reference value modeling exists.\n- General extern lookup through `Instance.export(named:)`,\n  `Instance.export(at:)`, `Instance.exports()`, `Extern`, and\n  `Linker.get(store:module:name:)`. Functions, globals, tables, and memories\n  have first-class wrappers today; tags and shared memories are reported by\n  kind until their dedicated wrappers land.\n- Linker support for WASI registration, import shadowing, host functions,\n  store-bound functions, defining unknown imports as traps or default values,\n  store-bound globals and memories, defining an instantiated module namespace,\n  registering a module by name, cloning linker definitions, resolving a named\n  module's default function, instantiating modules through that linker, and\n  pre-instantiating modules with `InstancePre` for reuse across compatible\n  stores. The remaining low-level extern definition surface for tags is not\n  exposed yet.\n- Vendored Wasmtime version: `v45.0.0`.\n- Vendored platforms: macOS, Linux, and Windows on `arm64`/`x86_64`.\n\n## Runtime Safety\n\nPrefer `WasmtimeRuntime` when values cross Swift concurrency domains. It keeps\nstore-bound Wasmtime handles inside an actor and serializes access to the store.\n\nThe lower-level wrappers mirror Wasmtime's C API more directly. `Config`,\n`Store`, `Instance`, `InstancePre`, `Linker`, `Func`, `WasiConfig`, and\n`Caller` are not `Sendable`; keep each store-bound object graph on one\nserialized execution path and do not call into it concurrently.\n\nLow-level handles should come from the same engine/store graph. For example, use\na `Module` with a `Store` created from the same `Engine`, and use store-bound\nfunctions and instances only with the `Store` that owns them.\n\n`Module.deserialize(engine:serialized:)`, `Module.deserialize(engine:data:)`,\nand `Module.deserializeFile(engine:path:)` must only consume trusted artifacts\npreviously produced by `Module.serialize()` for a compatible Wasmtime engine,\nversion, target platform, and configuration. They are not safe APIs for loading\narbitrary user-controlled bytes.\n\n`InstancePre` is created by `Linker.instantiatePre(module:)` after import\nresolution has succeeded. It can instantiate into multiple compatible stores,\nbut each returned `Instance` is still bound to the store passed to\n`InstancePre.instantiate(store:)`.\n\n`Config` and `WasiConfig` are consumed by `Engine.init(config:)` and\n`Store.setWasi(_:)` respectively. After consumption, using the same object again\nis a programmer error. Prefer `EngineOptions` and `WasiOptions` for reusable,\nsendable configuration values.\n\nThe public API is still intentionally small and pre-release in spirit. Public\nenums such as `Value`, `ValueKind`, `WasmtimeError`, and `ExternKind` may gain\ncases as more Wasmtime C API surface is wrapped.\n\nTrap diagnostics are exposed as Swift value snapshots. `WasmFrame` and\n`WasmTrace` copy the useful metadata from Wasmtime frames, including function\nindexes, offsets, and optional names, but they do not expose borrowed frame\nhandles or store-bound frame instance handles. This keeps diagnostic values\n`Sendable` and safe to retain after the original trap or error has been\nreleased.\n\n## Importing From SwiftPM\n\nAdd the package dependency and point your target at the vendored Wasmtime library\ndirectory in SwiftPM's checkout. This mirrors the workaround used by downstream\nSwiftPM packages that need to stay inside SwiftPM without XCFrameworks or a\nsystem Wasmtime install.\n\nSwiftPM may still warn about this package's own relative `Vendor/...` search\npath when it is built as a dependency; the consumer target search path below is\nthe path that makes the final link step succeed.\n\n```swift\n// swift-tools-version: 6.3\n\nimport PackageDescription\n\n#if os(macOS)\nlet wasmtimeOS = \"macos\"\n#elseif os(Linux)\nlet wasmtimeOS = \"linux\"\n#elseif os(Windows)\nlet wasmtimeOS = \"windows\"\n#else\n#error(\"swift-wasmtime currently supports macOS, Linux, and Windows\")\n#endif\n\n#if arch(arm64)\nlet wasmtimeArch = \"aarch64\"\n#elseif arch(x86_64)\nlet wasmtimeArch = \"x86_64\"\n#else\n#error(\"swift-wasmtime currently supports arm64 and x86_64\")\n#endif\n\nlet wasmtimeVersion = \"v45.0.0\"\nlet wasmtimeLibraryPath = \".build/checkouts/swift-wasmtime/Vendor/Wasmtime/\\(wasmtimeVersion)/\\(wasmtimeArch)-\\(wasmtimeOS)/lib\"\n\nlet package = Package(\n    name: \"MyPackage\",\n    dependencies: [\n        .package(\n            url: \"https://github.com/OpenCow42/swift-wasmtime.git\",\n            .upToNextMajor(from: \"45.0.0\")\n        ),\n    ],\n    targets: [\n        .target(\n            name: \"MyTarget\",\n            dependencies: [\n                .product(name: \"Wasmtime\", package: \"swift-wasmtime\"),\n            ],\n            linkerSettings: [\n                .unsafeFlags([\"-L\", wasmtimeLibraryPath]),\n            ]\n        ),\n    ],\n    swiftLanguageModes: [.v6]\n)\n```\n\nThen import and use the Swift module:\n\n```swift\nimport Wasmtime\n\nlet engine = try Engine()\nlet store = try Store(engine: engine)\nlet module = try Module(\n    engine: engine,\n    wat: \"\"\"\n    (module\n      (func (export \"add\") (param i32 i32) (result i32)\n        local.get 0\n        local.get 1\n        i32.add))\n    \"\"\"\n)\n\nlet instance = try Instance(store: store, module: module)\nlet add = try instance.exportedFunction(named: \"add\")\nlet result = try add.call([.i32(20), .i32(22)])\n```\n\nFor code that crosses Swift concurrency domains, prefer the actor runtime:\n\n```swift\nimport Wasmtime\n\nlet runtime = try WasmtimeRuntime()\nlet instance = try await runtime.instantiate(\n    wat: \"\"\"\n    (module\n      (func (export \"add\") (param i32 i32) (result i32)\n        local.get 0\n        local.get 1\n        i32.add))\n    \"\"\"\n)\nlet result = try await runtime.call(\"add\", in: instance, arguments: [.i32(20), .i32(22)])\n```\n\nThe actor runtime also exposes the package's WASI, linker, and early component\nworkflows without leaking store-bound handles across concurrency domains:\n\n```swift\nlet wasi = WasiOptions(\n    arguments: [\"guest.wasm\"],\n    environment: [\"LOG\": \"debug\"],\n    standardInputBytes: Array(\"request body\".utf8),\n    standardOutputHandler: { output in\n        print(String(decoding: output, as: UTF8.self))\n        return output.count\n    }\n)\ntry await runtime.setWasi(wasi)\n\nlet linked = try await runtime.instantiateWithLinker(\n    module,\n    defineWasi: true,\n    defineUnknownImportsAsDefaultValues: false\n)\ntry await runtime.call(\"_start\", in: linked)\n\nlet hostBacked = try await runtime.instantiateWithLinker(\n    module,\n    hostFunctions: [\n        RuntimeHostFunction(\n            module: \"host\",\n            name: \"double\",\n            parameters: [.i32],\n            results: [.i32]\n        ) { arguments in\n            guard case .i32(let value) = arguments[0] else {\n                throw WasmtimeError.api(message: \"unexpected argument\", exitStatus: nil)\n            }\n            return [.i32(value * 2)]\n        },\n    ]\n)\n```\n\nLow-level `Linker.defineFunction` callbacks are `@Sendable`. The `Caller`\nvalue passed to a host callback is only valid for that callback invocation;\ncopy any data you need from guest memory before returning.\n\n```swift\nlet componentRuntime = try WasmtimeRuntime(\n    options: EngineOptions(isComponentModelEnabled: true)\n)\nlet component = try await componentRuntime.compileComponent(wat: componentWat)\nlet componentInstance = try await componentRuntime.instantiateComponent(component)\ntry await componentRuntime.call(\"run\", in: componentInstance)\n```\n\n## Version Tags\n\nGit release tags use SwiftPM-friendly semantic versions without a leading `v`.\nFor example, this package tag is `45.0.0`, matching the vendored Wasmtime\n`v45.0.0` release. Upstream Wasmtime still uses `v`-prefixed tags, so scripts\nand vendored paths keep the upstream spelling where they interact with\nBytecode Alliance release assets.\n\n## License\n\nSwift Wasmtime is licensed under Apache-2.0 WITH LLVM-exception. The vendored\nWasmtime C API artifacts and headers are provided by the Bytecode Alliance\nWasmtime project under the same license. See `LICENSE` and\n`THIRD_PARTY_NOTICES.md`.\n\n## Build And Test\n\nFor local development with Xcode on macOS, keep Swift and Clang module caches\ninside the workspace:\n\n```sh\nDEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \\\nCLANG_MODULE_CACHE_PATH=\"$PWD/.build/clang-module-cache\" \\\nswift test --disable-sandbox\n```\n\nCoverage:\n\n```sh\nDEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \\\nCLANG_MODULE_CACHE_PATH=\"$PWD/.build/clang-module-cache\" \\\nscripts/test-coverage.sh\n```\n\nThe coverage script focuses on `Sources/Wasmtime` and excludes the vendored C\nheaders, C shim, fixtures, and package plumbing. Lines marked\n`coverage:ignore` are narrow defensive C-interop branches that cannot be\nreached deterministically from Swift without faking Wasmtime allocation failure\nor intentionally triggering a process abort.\n\n## Vendoring Wasmtime\n\nTo refresh the vendored C API artifacts:\n\n```sh\nscripts/vendor-wasmtime.sh v45.0.0\n```\n\nThe script downloads release metadata from GitHub, reads the official asset\ndigests, downloads the supported C API archives, verifies SHA256 checksums,\ncopies headers, preserves the upstream license, and stores platform libraries\nunder `Vendor/Wasmtime`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencow42%2Fswift-wasmtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencow42%2Fswift-wasmtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencow42%2Fswift-wasmtime/lists"}