Files
608040b8cb chore(docs) Resolve 'simple' style warnings where applicable (#46966)
Contributes to DOCS-1052

## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Resolves MDX linting errors related to "simple" where it applies.
There was a couple cases that did not apply. For example, a product with
"Simple" in the name.

These changes are made in context, either by removing or using a more
descriptive synonym like "minimal" or "basic".

## Tophatting

1. Read each of the diffs.
2. See that the text still makes sense in context.

For extra due diligence, you can run `pnpm lint:mdx` locally and see the
'simple' errors that remain and whether they are worth addressing.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

* **Documentation**
* Updated many guide, tutorial, and troubleshooting pages with clearer
“basic”/“minimal” wording across setup steps, local testing
instructions, security cautions, and RLS guidance.
* Refined headings, example descriptions, and inline comments for
consistency (including deployment, MCP, metrics API, and search/function
phrasing).
* Improved readability with small snippet formatting tweaks (whitespace
plus import/comment ordering) and added a self-hosting debugging note
for Envoy admin endpoints via a short-lived `curl` container.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Chris Chinchilla <chris.ward@supabase.io>
Co-authored-by: Nik Richers <nrichers@gmail.com>
2026-06-16 21:45:55 +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/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 `supabase/config.toml`:
<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
[functions.wasm-add]
static_files = [ "./functions/wasm-add/add-wasm/pkg/*"]
```
Deploy the function by running:
```bash
supabase functions deploy wasm-add
```