hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.25k stars 450 forks source link

Support WebAssembly #280

Open magodo opened 1 year ago

magodo commented 1 year ago

This PR supports running go-plugin based application in the browser.

The basic idea is to leverage the Shared Web Worker API to replace the tcp/uds transport layer, but not touch the application protocol layer (i.e. netrpc/grpc). Meanwhile, the Shared Web Worker also fits well to the parent/child process model, so there is a new runner, wasmrunner, as a replacement for the cmdrunner.

The changes of this PR can be categaried to the following parts:

Unfortunately, due to the limitation of the WASM environment, we only implemented the basic functionalities of the go-plugin, with (at least) below limitations:

Beside these limitations, it actually works pretty well. We have been using it in some Terraform based projects, where we used this lightweighted TF client for importing resources from any provider (though some huge provider might causes WASM build failure due to its size, where needs to be trimmed a bit), in the browser, with only one line change in the go.mod to replace the go-plugin.