swc/tests/rust-plugins/swc_internal_plugin
2022-01-19 05:01:45 +00:00
..
.cargo feat(plugin): Allow multi-value for the plugin signature (#3216) 2022-01-09 15:02:56 +09:00
multivalue-polyfill feat(plugin): Add PluginError (#3300) 2022-01-18 12:26:04 +09:00
src feat(plugin): Add PluginError (#3300) 2022-01-18 12:26:04 +09:00
build.cmd feat(plugin/runnner): Support wasm32-wasi targets (#3271) 2022-01-15 04:40:00 +00:00
build.sh feat(plugin/runnner): Support wasm32-wasi targets (#3271) 2022-01-15 04:40:00 +00:00
Cargo.lock test(plugin/runner): Pin dependencies for the integration test (#3306) 2022-01-19 05:01:45 +00:00
Cargo.toml feat(plugin/macro): Add safe API for plugins based on a proc-macro (#3240) 2022-01-12 09:32:52 +00:00
README.md feat(plugin): Allow multi-value for the plugin signature (#3216) 2022-01-09 15:02:56 +09:00

SWC plugin

Multivalue-polyfill

Once plugin completes transform, transformed Program will be re-serialized into array bytes. Host (SWC) will reconstruct & deserialize it via raw pointer to the array bytes plugin's process returns. However since size of serialized array bytes is non-deterministic plugin also should return size of the array as well. In result, signature of raw plugin process fn looks like this:

fn proces(...args) -> (i32, i32)

Rust compiler have target feature (target-feature=+multivalue) to genetare wasm binary with these multivalue support, but there are some known upstream issues like https://github.com/rust-lang/rust/issues/73755 prevents to use it. The other way around is to use bindings like wasm-bindgen.

In this plugin example generated binary polyfills multivalue only instead of relying on whole wasm-bindgen workflow (https://github.com/vmx/wasm-multi-value-reverse-polyfill). This polyfill can be removed once upstream compiler feature works as expected or if we decide to use wasm-bindgen fully.

Since cargo doesn't support workflow like post-build integrating whole process into build is bit unergonomic. build.* is naive substitution to mimic those behaviors. Or otherwise multivalue-polyfill can be excuted manually after main plugin build steps.