Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions src/handler_loader/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ pub fn compile(
uncompiled_handlers: LoadedHandlerConfiguration,
compilation_settings: WasmCompilationSettings,
) -> anyhow::Result<WasmHandlerConfiguration> {
uncompiled_handlers.compile_modules(|module_bytes| {
uncompiled_handlers.compile_modules(|module_bytes, module_name| {
crate::wasm_module::WasmModuleSource::from_module_bytes(
module_bytes,
module_name,
&compilation_settings.cache_config_path,
)
})
Expand All @@ -28,12 +29,12 @@ pub fn compile(
impl LoadedHandlerConfiguration {
pub fn compile_modules(
self,
compile: impl Fn(std::sync::Arc<Vec<u8>>) -> anyhow::Result<WasmModuleSource>,
compile: impl Fn(std::sync::Arc<Vec<u8>>, &str) -> anyhow::Result<WasmModuleSource>,
) -> anyhow::Result<WasmHandlerConfiguration> {
let result: anyhow::Result<Vec<WasmHandlerConfigurationEntry>> = self
.entries
.into_iter()
.map(|e| e.compile_module(|m| compile(m)))
.map(|e| e.compile_module(|m, n| compile(m, n)))
.collect();
Ok(WasmHandlerConfiguration { entries: result? })
}
Expand All @@ -42,9 +43,9 @@ impl LoadedHandlerConfiguration {
impl LoadedHandlerConfigurationEntry {
pub fn compile_module(
self,
compile: impl Fn(std::sync::Arc<Vec<u8>>) -> anyhow::Result<WasmModuleSource>,
compile: impl Fn(std::sync::Arc<Vec<u8>>, &str) -> anyhow::Result<WasmModuleSource>,
) -> anyhow::Result<WasmHandlerConfigurationEntry> {
let compiled_module = compile(self.module)
let compiled_module = compile(self.module, &self.info.name)
.with_context(|| format!("Error compiling Wasm module {}", &self.info.name))?;
Ok(WasmHandlerConfigurationEntry {
info: self.info,
Expand Down
3 changes: 2 additions & 1 deletion src/wasm_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ impl WasmModuleSource {

pub fn from_module_bytes(
data: Arc<Vec<u8>>,
module_name: &str,
cache_config_path: &Path,
) -> anyhow::Result<WasmModuleSource> {
let engine = Self::new_engine(cache_config_path)?;
let module = wasmtime::Module::new(&engine, &**data)?;
let module = wasmtime::Module::new_with_name(&engine, &**data, module_name)?;
Ok(WasmModuleSource::Compiled(module, engine))
}

Expand Down