Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API Surface Refactor #879

Merged
merged 8 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }
walrus = "0.23.3"
swc_core = { version = "10.7.0", features = [
"common_sourcemap",
"ecma_ast",
"ecma_parser",
"common_sourcemap",
"ecma_ast",
"ecma_parser",
] }
wit-parser = "0.212.0"
convert_case = "0.7.1"
Expand Down
92 changes: 0 additions & 92 deletions crates/cli/src/codegen/builder.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't see a use case where this was required over just implementing the generator itself as a builder pattern.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ use anyhow::{anyhow, Result};
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
use wasmtime::{AsContextMut, Engine, Instance, Linker, Memory, Module, Store};

use crate::plugins::Plugin;

pub fn compile_source(plugin: &Plugin, js_source_code: &[u8]) -> Result<Vec<u8>> {
let (mut store, instance, memory) = create_wasm_env(plugin)?;
pub(crate) fn compile_source(plugin_bytes: &[u8], js_source_code: &[u8]) -> Result<Vec<u8>> {
jeffcharles marked this conversation as resolved.
Show resolved Hide resolved
let (mut store, instance, memory) = create_wasm_env(plugin_bytes)?;
let (js_src_ptr, js_src_len) =
copy_source_code_into_instance(js_source_code, store.as_context_mut(), &instance, &memory)?;
let ret_ptr = call_compile(js_src_ptr, js_src_len, store.as_context_mut(), &instance)?;
let bytecode = copy_bytecode_from_instance(ret_ptr, store.as_context_mut(), &memory)?;
Ok(bytecode)
}

fn create_wasm_env(plugin: &Plugin) -> Result<(Store<WasiCtx>, Instance, Memory)> {
fn create_wasm_env(plugin_bytes: &[u8]) -> Result<(Store<WasiCtx>, Instance, Memory)> {
let engine = Engine::default();
let module = Module::new(&engine, plugin.as_bytes())?;
let module = Module::new(&engine, plugin_bytes)?;
let mut linker = Linker::new(&engine);
wasi_common::sync::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(
&mut linker,
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/codegen/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use anyhow::{anyhow, Result};
use convert_case::{Case, Casing};
use std::{env, path::Path};

use crate::{js::JS, wit};
use crate::{codegen::js::JS, codegen::wit};

pub(crate) type Exports = Vec<Export>;

#[derive(Clone)]
pub(crate) struct Export {
pub wit: String,
pub js: String,
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/js.rs → crates/cli/src/codegen/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use swc_core::{
},
};

use crate::plugins::Plugin;
use crate::codegen::plugin::Plugin;

#[derive(Clone, Debug)]
pub struct JS {
Expand Down Expand Up @@ -165,10 +165,10 @@ impl JS {

#[cfg(test)]
mod tests {
use crate::js::JS;

use anyhow::Result;

use crate::codegen::js::JS;

#[test]
fn parse_no_exports() -> Result<()> {
let exports = parse("function foo() {}")?;
Expand Down
Loading