Skip to content

Configure Wasmtime wasm features from toml config file#444

Open
tanishiking wants to merge 2 commits into
spinframework:mainfrom
tanishiking:wasm-features
Open

Configure Wasmtime wasm features from toml config file#444
tanishiking wants to merge 2 commits into
spinframework:mainfrom
tanishiking:wasm-features

Conversation

@tanishiking

Copy link
Copy Markdown

Close #431

context:
Thanks to spinframework/spin#3377, we can now run Scala-wasm generated Wasm Component binary with GC/EH locally on spin 🎉
Here's the Scala Spin templates: https://github.com/scala-wasm/scala-wasm-spin-templates

However, we cannot run those binaries on neither spinkube (,Fermyon cloud nor Akamai Function) yet, because there's no way to configure Wasm features for those environments.

This PR enables spinkube to configure the Wasm features by mounting TOML file to the pod.


Load Wasmtime CLI TOML feature flags so the workloads that requires proposals like GC and exception handling can run on Spinkube.

Wasmtime configuration should be configured as the TOML format https://docs.wasmtime.dev/cli-options.html#cli-options-using-toml-file

We should monunt the config file into the pod as a volume. By default, shim reads the configuration file from /runtime/wasmtime.toml, but we can configure the path by SPIN_WASMTIME_CONFIG_PATH environment variable at cluster level.

For example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: wasmtime-config-gc
data:
  wasmtime.toml: |
    [wasm]
    gc = true
    exceptions = true
    function-references = true
    reference-types = true
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: scala-wasm-health-smoke
spec:
  replicas: 1
  selector:
    matchLabels:
      app: scala-wasm-health-smoke
  template:
    metadata:
      labels:
        app: scala-wasm-health-smoke
    spec:
      runtimeClassName: wasmtime-spin-v2
      containers:
        - name: app
          image: ttl.sh/scala-wasm-health-smoke:1h
          command: ["/"]
          ports:
            - containerPort: 80
          volumeMounts:
            - name: wasmtime-config
              mountPath: /runtime/wasmtime.toml
              subPath: wasmtime.toml
              readOnly: true
      volumes:
        - name: wasmtime-config
          configMap:
            name: wasmtime-config-gc

spin-core = { git = "https://github.com/spinframework/spin", tag = "v3.6.3" }
spin-factor-outbound-networking = { git = "https://github.com/spinframework/spin", tag = "v3.6.3" }
wasmtime = "42.0.2"
wasmtime-cli-flags = { version = "42.0.2", features = ["component-model", "gc"] }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanishiking

tanishiking commented May 18, 2026

Copy link
Copy Markdown
Author

Ah, wait, it doesn't work for precompilation. (I randomly put the same /runtime/wasmtime.toml to the local k8s node, and it worked, but we shouldn't configure that at node level).

We might need to runwasi to read config.json for the wasmtime configuration, and spin-shim to configure the engine based on that information for precompile.

@tanishiking

tanishiking commented May 18, 2026

Copy link
Copy Markdown
Author

e186ac7 allows precompilation to read the Wasmtime configuration from the Pod-mounted wasmtime.toml.
Based on containerd/runwasi#1128 that reads OCI spec, and give it to Shim::compiler

@tanishiking tanishiking marked this pull request as ready for review May 18, 2026 15:33
Load Wasmtime CLI TOML feature flags so the workloads that requires
proposals like GC and exception handling can run on Spinkube.

Wasmtime configuration should be configured as the TOML format
https://docs.wasmtime.dev/cli-options.html#cli-options-using-toml-file

We should monunt the config file into the pod as a volume.
By default, shim reads the configuration file from
`/runtime/wasmtime.toml`, but we can configure the path by
`SPIN_WASMTIME_CONFIG_PATH` environment variable at cluster level.

For example:

```toml
apiVersion: v1
kind: ConfigMap
metadata:
  name: wasmtime-config-gc
data:
  wasmtime.toml: |
    [wasm]
    gc = true
    exceptions = true
    function-references = true
    reference-types = true
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: scala-wasm-health-smoke
spec:
  replicas: 1
  selector:
    matchLabels:
      app: scala-wasm-health-smoke
  template:
    metadata:
      labels:
        app: scala-wasm-health-smoke
    spec:
      runtimeClassName: wasmtime-spin-v2
      containers:
        - name: app
          image: ttl.sh/scala-wasm-health-smoke:1h
          command: ["/"]
          ports:
            - containerPort: 80
          volumeMounts:
            - name: wasmtime-config
              mountPath: /runtime/wasmtime.toml
              subPath: wasmtime.toml
              readOnly: true
      volumes:
        - name: wasmtime-config
          configMap:
            name: wasmtime-config-gc
```

Signed-off-by: Rikito Taniguchi <rikitotaniguchi@proton.me>
Use the OCI spec provided by runwasi to resolve the `wasmtime.toml`
and create the precompiler engine using that config.

This enables pod mounted Wasmtime config during AOT compilation
without having `/runtime/wasmtime.toml` on the node.

Signed-off-by: Rikito Taniguchi <rikitotaniguchi@proton.me>
jsturtevant pushed a commit to containerd/runwasi that referenced this pull request Jun 13, 2026
spinframework/containerd-shim-spin#444 adds Wasmtime TOML feature configuration.
Runtime configuration can be provided through a Pod mounted
`/runtime/wasmtime.toml` for example, but precompilation currently
creates the compiler before the shim has access to the configuration.

This commits adds `Shim::compiler_with_spec(&Spec)`. Instance creation
now loads `config.json` before loading OCI Wasm layers and passes the
spec to the compiler through that new API.
Downstream shims precompilation should be able to read the spec to
configure the wasmtime engine.

Concern, this might add a small per-container-start cost:
- we read `config.json` before precopmile
- construct a precompiler per container rather than once per shim process.
@tanishiking

Copy link
Copy Markdown
Author

upstream containerd/runwasi#1128 is merged, but it's not yet released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuration of wasmtime features

1 participant