{"id":15284382,"url":"https://github.com/craiggleso/workers-zig","last_synced_at":"2025-04-12T23:22:15.878Z","repository":{"id":57750058,"uuid":"525193619","full_name":"CraigglesO/workers-zig","owner":"CraigglesO","description":"Write Cloudflare Workers in Zig via WebAssembly","archived":false,"fork":false,"pushed_at":"2022-09-08T13:59:09.000Z","size":752,"stargazers_count":38,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T17:21:24.012Z","etag":null,"topics":["cloudflare","cloudflare-workers","serverless","workers","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CraigglesO.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}},"created_at":"2022-08-16T01:36:04.000Z","updated_at":"2025-03-24T05:51:04.000Z","dependencies_parsed_at":"2022-08-26T08:30:43.422Z","dependency_job_id":null,"html_url":"https://github.com/CraigglesO/workers-zig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CraigglesO%2Fworkers-zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CraigglesO%2Fworkers-zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CraigglesO%2Fworkers-zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CraigglesO%2Fworkers-zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CraigglesO","download_url":"https://codeload.github.com/CraigglesO/workers-zig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644211,"owners_count":21138570,"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":["cloudflare","cloudflare-workers","serverless","workers","zig"],"created_at":"2024-09-30T14:54:55.149Z","updated_at":"2025-04-12T23:22:15.855Z","avatar_url":"https://github.com/CraigglesO.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workers-Zig\n\n![workers-zig](.github/workers-zig.svg)\n\n**Workers Zig** is a light weight [**Zig**](https://ziglang.org/) bindings for the [**Cloudflare Workers**](https://workers.cloudflare.com/) environment via [**WebAssembly**](https://webassembly.org/).\n\nWhy Zig?\n* Zig is a language that is designed to be a small, fast, and portable.\n* The language already supports WASM and WASI.\n* Small builds are easy to achieve. To expound on this, the basic example provided is `5.8Kb` of WASM code and `6.8Kb` javascript code.\n* I wanted a tool that made it easy for both WASM and JS code to work in tandem.\n* I didn't like that rust wasm bindings would grow the more code you wrote. I came up with a strategy that covers 90% use cases, JS glue doesn't grow, and you can add the 10% as needed.\n* I prefer [**Zig's memory model**](https://www.scattered-thoughts.net/writing/how-safe-is-zig/) over Rust.\n\n\nBe sure to read the [Documentation](https://github.com/CraigglesO/workers-zig/tree/master/docs) for guidance on usage.\n\n## Features\n\n- 🔗 Zero dependencies\n- 🗿 WASI support\n- 🤝 Use in tandem with Javascript or 100% Zig WebAssembly\n- 🎮 JS bindings with support to write your own - [List of supported bindings here](https://github.com/CraigglesO/workers-zig/tree/master/docs/bindings)\n- 📨 Fetch bindings\n- ⏰ Scheduled bindings\n- 🔑 Supports Variables and Secrets from `env`\n- ✨ Cache bindings\n- 📦 KV bindings\n- 🪣 R2 bindings\n- 💾 D1 bindings\n- 🔐 Web-Crypto bindings [partially complete]\n- 💪 Uses TypeScript\n\n## Features coming soon\n\n- 📌 Durable Objects bindings\n- ✉️ WebSockets bindings\n- once CF lands dynamic imports: Only load wasm when needed.\n\n## Install\n\n### Step 1: Install Zig\n\n[Follow the instructions to install Zig](https://ziglang.org/learn/getting-started/)\n\nRelease used: **0.10.0-dev.3838+77f31ebbb**\n\n### Step 2a: Use the skeleton project provided\n\n[Follow the steps provided by the skeleton project](https://github.com/CraigglesO/worker-zig-template)\n\n```bash\n# in one go\ngit clone --recurse-submodules -j8 git@github.com:CraigglesO/worker-zig-template.git\n\n# OR\n\n# clone\ngit clone git@github.com:CraigglesO/worker-zig-template.git\n# enter\ncd worker-zig-template\n# Pull in the submodule\ngit submodule update --init --recursive\n```\n\n### Step 2b: Install the workers-zig package\n\n```bash\n# NPM\nnpm install --save workers-zig\n# Yarn\nyarn add workers-zig\n# PNPM\npnpm add workers-zig\n# BUN\nbun add workers-zig\n```\n\n### Step 3: Add workers-zig as a submodule to your project\n\n```bash\ngit submodule add https://github.com/CraigglesO/workers-zig\n```\n\n### Step 4: Setup a **build.zig** script\n\n```zig\nconst std = @import(\"std\");\nconst Builder = std.build.Builder;\n\npub fn build(b: *Builder) void {\n    b.is_release = true;\n    b.cache_root = \"cache\";\n    b.global_cache_root = \"cache\";\n    b.use_stage1 = true;\n\n    const wasm_build = b.addSharedLibrary(\"zig\", \"lib/main.zig\", .unversioned);\n    wasm_build.setOutputDir(\"dist\");\n    wasm_build.setTarget(std.zig.CrossTarget {\n        .cpu_arch = .wasm32,\n        .os_tag = .freestanding,\n    });\n    wasm_build.build_mode = std.builtin.Mode.ReleaseSmall;\n    wasm_build.strip = true;\n    wasm_build.linkage = std.build.LibExeObjStep.Linkage.dynamic;\n    wasm_build.addPackagePath(\"workers-zig\", \"workers-zig/lib/main.zig\");\n    wasm_build.install();\n}\n```\n\n### Step 5: Recommended wrangler configuration\n\n```toml\nname = \"zig-worker-template\"\nmain = \"dist/worker.mjs\"\ncompatibility_date = \"2022-07-29\"\nusage_model = \"bundled\" # or unbound\naccount_id = \"\"\n\n[build]\ncommand = \"zig build \u0026\u0026 npm run esbuild\"\nwatch_dir = [\n  \"src\",\n  \"lib\"\n]\n\n[[build.upload.rules]]\ntype = \"CompiledWasm\"\nglobs = [\"**/*.wasm\"]\n[[build.upload.rules]]\ntype = \"ESModule\"\nglobs = [\"**/*.mjs\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraiggleso%2Fworkers-zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraiggleso%2Fworkers-zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraiggleso%2Fworkers-zig/lists"}