8000 Make scala-wasm suitable for standalone Wasm VMs · Issue #117 · tanishiking/scala-wasm · GitHub < 8000 meta name="octolytics-dimension-repository_id" content="752953985" />
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
Make scala-wasm suitable for standalone Wasm VMs #117
@tanishiking

Description

@tanishiking

Why

Currently, the Wasm modules generated by scala-wasm depend on helper functions in JavaScript, making it possible to run them on JavaScript engines like V8, but not on standalone Wasm runtimes such as wasmtime or wasmedge.

While WebAssembly was initially designed to run in web browsers, it has recently been adopted in various environments due to its portability, fast loading and execution times, and security benefits.

For example, WebAssembly is being used in:

  • Plugins/Extensions (Envoy, UDF in TiDB)
  • Serverless/FaaS (Fastly, Fermyon Spin, Cloudflare workers)
  • Containers/k8s (runwasi, containerd-shims)
  • Cloud Apps (wasm-cloud, Wasm Worker Server)
  • Smart Contracts (Ethereum Wasm, Near Protocol)

(I personally believe the significant benefit of compiling Scala to WebAssembly lies in the ability to run it in these environments (as well as the Component Model))

However, to leverage WebAssembly in these environments, the binaries need to be executable on standalone Wasm runtimes, which is not possible with the current state of the generated binaries.

How

To achieve this, two major tasks are required (and the latter will likely be a significant challenge):

  • (1) Support WASI (WebAssembly System Interface) (at least WASI preview 1 for now). This would enable access to the file system and other resources, regardless of the host environment.
  • (2) Remove dependencies on JavaScript. (if it's targeted to pure-WASI)
    • Implementations of strings, closures, and other features currently rely on JavaScript, but these would need to be implemented in pure WebAssembly.
    • Math functions and RegExp implementations would also need to be handled on the WebAssembly side. Could the implementations from Scala Native be reused somehow? (It seems that the Kotlin/Wasm RegExp engine reuses the implementation from Kotlin/Native.)
    • Any JavaScript dependencies, including js.Dynamic, would become unavailable (some of them might be replaceable with WASI?)
    • Third-party libraries that depend on JavaScript might need to be re-implemented for standalone WebAssembly targets. (It should be considered whether to have separate builds for standalone Wasm or introduce annotations to switch implementations at link time, similar to Scala Native.)

State of WasmGC support on standalone Wasm runtimes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0