Skip to content

Commit

Permalink
Refactored and cleaned up interfaces between codegen and cli packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmarmour committed Feb 8, 2025
1 parent 9699d9f commit 4aaa655
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 351 deletions.
90 changes: 0 additions & 90 deletions crates/cli/src/codegen/builder.rs

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>> {
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::wit, js::JS};

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

#[derive(Clone)]
pub(crate) struct Export {
pub wit: String,
pub js: String,
Expand Down
Loading

0 comments on commit 4aaa655

Please sign in to comment.