Files
supabase/apps/docs/content/guides/functions/wasm.mdx
Colum Ferry 95cf9a78a7 docs(cli): show config examples in TOML and JSONC (#53449)
## Problem

The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0,
but every docs page still shows `config.toml` only. There's also no page
explaining the formats, how to switch, the `$schema` / `#:schema`
declaration, or editor setup, and no reference pages for the new
`supabase config convert` and `supabase config validate` commands.

Linear: CLI-2871

## Solution

- **Dual-format examples from one source.** A new directive
(`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ````
fence with `name=supabase/config.toml` and renders it as
`supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is
generated at build time with `convertCliConfigTomlToJsonc` from
`@supabase/config`, the same converter `supabase config convert` uses,
so authors only write TOML and the JSONC matches what the CLI would
produce (comments included). Inside `<$CodeTabs>` the JSONC is added as
an extra tab.
- **The format choice sticks.** `ConfigCodeTabs` keeps the selected
format in `localStorage`, so choosing JSONC switches every config
example on the page and on later pages.
- **Config reference.** The `usage` examples on
`/guides/local-development/cli/config` use the same tabs (they were
highlighted as Python before), and the intro mentions `config.jsonc`.
The `remotes.<branch_name>` example now uses `[remotes.staging]`, since
`<branch_name>` isn't a valid TOML key.
- **New guide, "Config file formats"**
(`/guides/local-development/cli/config-formats`): which file wins,
minimum CLI version, `convert` and `validate`, schema declaration and
versioning, and editor setup (VS Code trusted domains, Even Better TOML,
Tombi, SchemaStore).
- **CLI reference.** Adds `supabase-config-convert` and
`supabase-config-validate` to the CLI reference nav.
`cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to
the release bot's update in #53463, so the two PRs don't conflict.
- **Content.** About 60 existing config examples across the guides,
including the Branching configuration page, are tagged
`name=supabase/config.toml`. Branching reads `config.json` and
`config.jsonc` as well, and the Branching configuration page now says
so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era
`[inbucket]` before/after snippet stay TOML-only.
- **Format-neutral prose.** Sentences that described the config as
`config.toml` now say "your config file", naming `supabase/config.toml`
and `supabase/config.jsonc` once per page. TOML section syntax in prose
(`max_frequency` under `[auth.email]`) is written as key paths
(`auth.email.max_frequency`), which read the same in both formats.
Headings that named `config.toml` keep their old anchors. Sentences
about what `supabase init` creates still say `config.toml`.
- **Markdown export for agents.**
`internals/generate-guides-markdown.ts` runs the same transform, so the
`.md` pages served to AI agents include the JSONC example after each
TOML one.
- A test converts every tagged example under `content/`, so a broken
TOML example fails tests instead of the build.

New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and
`effect` (the same `effect` version Studio pins).

`config convert` and `config validate` ship in CLI v3.2.0, which is now
stable.

## Review instructions

1. Open `/docs/guides/local-development/seeding-your-database` on the
preview. Switch an example to `supabase/config.jsonc` and check the
other examples on the page switch too.
2. Open `/docs/guides/local-development/cli/config` and check the usage
examples open on JSONC.
3. Read `/docs/guides/local-development/cli/config-formats`.
4. Open `/docs/reference/cli/supabase-config-convert` and
`/docs/reference/cli/supabase-config-validate`.

## Self-review

Ran the `review-the-docs` local self-review (content, pipeline, and
component checks) over the 54 changed pages.

- No blockers. Fixed the nits it found: leftover TOML section syntax in
prose (diff engines, declarative schemas, Branching, the common settings
table on Local and hosted projects), a few long or ungrammatical
sentences, and the conversion follow-up steps on Config file formats,
now a list.
- Links, custom anchors, nav wiring, and frontmatter check out.
- The `.md` export on the preview shows each TOML example followed by
its JSONC version.
- `test-the-docs` deferred: the changed fences are config snippets, and
`ConfigFormats.test.ts` already converts every tagged example. No
procedural steps changed apart from the `config convert` and `config
validate` commands on the new page.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-20 14:34:59 +00:00

140 lines
4.1 KiB
Plaintext

---
id: 'function-wasm'
title: 'Using Wasm modules'
component: true
description: 'How to use WebAssembly in Edge Functions.'
subtitle: 'Use WebAssembly in Edge Functions.'
---
Edge Functions supports running [WebAssembly (Wasm)](https://developer.mozilla.org/en-US/docs/WebAssembly) modules. WebAssembly is useful if you want to optimize code that's slower to run in JavaScript or require low-level manipulation.
This allows you to:
- Optimize performance-critical code beyond JavaScript capabilities
- Port existing libraries from other languages (C, C++, Rust) to JavaScript
- Access low-level system operations not available in JavaScript
For example, libraries like [magick-wasm](/docs/guides/functions/examples/image-manipulation) port existing C libraries to WebAssembly for complex image processing.
---
## Writing a Wasm module
You can use different languages and SDKs to write Wasm modules. For this tutorial, we will write a basic Wasm module in Rust that adds two numbers.
<Admonition type="note">
Follow this [guide on writing Wasm modules in Rust](https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Rust_to_Wasm) to setup your dev environment.
</Admonition>
<StepHikeCompact>
<StepHikeCompact.Step step={1} fullWidth>
<StepHikeCompact.Details title="Create a new Edge Function" fullWidth>
Create a new Edge Function called `wasm-add`
```bash
supabase functions new wasm-add
```
</StepHikeCompact.Details>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={2} fullWidth>
<StepHikeCompact.Details title="Create a new Cargo project" fullWidth>
Create a new Cargo project for the Wasm module inside the function's directory:
```bash
cd supabase/functions/wasm-add
cargo new --lib add-wasm
```
</StepHikeCompact.Details>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={3} fullWidth>
<StepHikeCompact.Details title="Add the Wasm module code" fullWidth>
Add the following code to `add-wasm/src/lib.rs`.
<$CodeSample
path="edge-functions/supabase/functions/wasm-modules/add-wasm/src/lib.rs"
lines={[[1, -1]]}
meta="lib.rs"
language="rust"
/>
</StepHikeCompact.Details>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={4} fullWidth>
<StepHikeCompact.Details title="Update the Cargo.toml file" fullWidth>
Update the `add-wasm/Cargo.toml` to include the `wasm-bindgen` dependency.
<$CodeSample
path="edge-functions/supabase/functions/wasm-modules/add-wasm/Cargo.toml"
lines={[[1, -1]]}
meta="Cargo.toml"
/>
</StepHikeCompact.Details>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={5} fullWidth>
<StepHikeCompact.Details title="Build the Wasm module" fullWidth>
Build the package by running:
```bash
wasm-pack build --target deno
```
This will produce a Wasm binary file inside `add-wasm/pkg` directory.
</StepHikeCompact.Details>
</StepHikeCompact.Step>
</StepHikeCompact>
---
## Calling the Wasm module from the Edge Function
Update your Edge Function to call the add function from the Wasm module:
<$CodeSample
path="edge-functions/supabase/functions/wasm-modules/index.ts"
lines={[[1, -1]]}
meta="index.ts"
/>
<Admonition type="note">
Supabase Edge Functions currently use Deno 1.46. From [Deno 2.1, importing Wasm modules](https://deno.com/blog/v2.1) will require even less boilerplate code.
</Admonition>
---
## Bundle and deploy
Before deploying, ensure the Wasm module is bundled with your function by defining it in your config file (`supabase/config.toml` or `supabase/config.jsonc`):
<Admonition type="note">
- You will need update Supabase CLI to 2.7.0 or higher for the `static_files` support.
- Static files cannot be deployed using the `--use-api` API flag. You need to build them with [Docker on the CLI](/docs/guides/functions/quickstart#step-6-deploy-to-production).
</Admonition>
```toml supabase/config.toml
[functions.wasm-add]
static_files = [ "./functions/wasm-add/add-wasm/pkg/*"]
```
Deploy the function by running:
```bash
supabase functions deploy wasm-add
```