pub fn build(config: impl Into<WasmModuleConfig> + Debug) -> Result<Self> {
        let config = config.into();
        let output_file = config
            .artifact_cache
            .join(config.path.file_stem().ok_or("A file is required")?)
            .with_extension("so");

        // Prepwork
        fs::create_dir_all(&config.artifact_cache)?;
        hostcall::ensure_linked();

        let artifact_cache = ArtifactCache::new(config.artifact_cache.clone())?;

        let internal_event_compilation = internal_events::WasmCompilation::begin(config.role);
        if artifact_cache.has_fresh(&config.path)? {
            // We can be lazy and do nothing! How wonderful.
            internal_event_compilation.cached();
        } else {
            let fingerprint = compile(&config.path, &output_file)?;
            let mut artifact_cache = artifact_cache; // Just for this scope.
            artifact_cache.upsert(&config.path, fingerprint)?;
            internal_event_compilation.complete();
        }

        // load the compiled Lucet module
        let module = DlModule::load(&output_file)?;

        // create a new memory region with default limits on heap and stack size
        let region = &MmapRegion::create(
            1,
            &Limits {
                heap_memory_size: config.max_heap_memory_size,
                ..Limits::default()
            },
        )?;

        // instantiate the module in the memory region
        let instance = region
            .new_instance_builder(module)
            .with_embed_ctx::<WasmModuleConfig>(config.clone())
            .with_embed_ctx::<Option<Registration>>(None)
            .with_embed_ctx::<context::RaisedError>(Default::default())
            .build()?;

        let mut wasm_module = Self {
            config,
            instance,
            role: Role::Transform,
        };

        let wasi_ctx = WasiCtxBuilder::new().inherit_stdio().build()?;
        wasm_module.instance.insert_embed_ctx(wasi_ctx);

        wasm_module.instance.run("init", &[])?.returned()?;
        let registration = wasm_module
            .instance
            .remove_embed_ctx::<Option<Registration>>()
            .and_then(|v| v);

        if let None = registration {
            error!("Not registered! Please fill your `init` call with a `Registration::transform().register()`!");
        }

        Ok(wasm_module)
    }
/// Build the WASM instance from a given config.
Build the WASM instance from a given config.
Build the WASM instance from a given config .
pub fn build(config: impl Into<WasmModuleConfig> + Debug) -> Result<Self> {
        let config = config.into();
        let output_file = config
            .artifact_cache
            .join(config.path.file_stem().ok_or("A file is required")?)
            .with_extension("so");
        // Prepwork
        fs::create_dir_all(&config.artifact_cache)?;
        hostcall::ensure_linked();
        let artifact_cache = ArtifactCache::new(config.artifact_cache.clone())?;
        let internal_event_compilation = internal_events::WasmCompilation::begin(config.role);
        if artifact_cache.has_fresh(&config.path)? {
            // We can be lazy and do nothing! How wonderful.
            internal_event_compilation.cached();
        } else {
            let fingerprint = compile(&config.path, &output_file)?;
            let mut artifact_cache = artifact_cache; // Just for this scope.
            artifact_cache.upsert(&config.path, fingerprint)?;
            internal_event_compilation.complete();
        }
        // load the compiled Lucet module
        let module = DlModule::load(&output_file)?;
        // create a new memory region with default limits on heap and stack size
        let region = &MmapRegion::create(
            1,
            &Limits {
                heap_memory_size: config.max_heap_memory_size,
                ..Limits::default()
            },
        )?;
        // instantiate the module in the memory region
        let instance = region
            .new_instance_builder(module)
            .with_embed_ctx::<WasmModuleConfig>(config.clone())
            .with_embed_ctx::<Option<Registration>>(None)
            .with_embed_ctx::<context::RaisedError>(Default::default())
            .build()?;
        let mut wasm_module = Self {
            config,
            instance,
            role: Role::Transform,
        };
        let wasi_ctx = WasiCtxBuilder::new().inherit_stdio().build()?;
        wasm_module.instance.insert_embed_ctx(wasi_ctx);
        wasm_module.instance.run("init", &[])?.returned()?;
        let registration = wasm_module
            .instance
            .remove_embed_ctx::<Option<Registration>>()
            .and_then(|v| v);
        if let None = registration {
            error!("Not registered! Please fill your `init` call with a `Registration::transform().register()`!");
        }
        Ok(wasm_module)
    }
pub fn build ( config : impl Into < WasmModuleConfig > + Debug ) -> Result < Self > { let config = config . into ( ) ; let output_file = config . artifact_cache . join ( config . path . file_stem ( ) . ok_or ( " " ) ? ) . with_extension ( " " ) ; // Prepwork fs :: create_dir_all ( & config . artifact_cache ) ? ; hostcall :: ensure_linked ( ) ; let artifact_cache = ArtifactCache :: new ( config . artifact_cache . clone ( ) ) ? ; let internal_event_compilation = internal_events :: WasmCompilation :: begin ( config . role ) ; if artifact_cache . has_fresh ( & config . path ) ? { // We can be lazy and do nothing! How wonderful. internal_event_compilation . cached ( ) ; } else { let fingerprint = compile ( & config . path , & output_file ) ? ; let mut artifact_cache = artifact_cache ; // Just for this scope. artifact_cache . upsert ( & config . path , fingerprint ) ? ; internal_event_compilation . complete ( ) ; } // load the compiled Lucet module let module = DlModule :: load ( & output_file ) ? ; // create a new memory region with default limits on heap and stack size let region = & MmapRegion :: create ( 1 , & Limits { heap_memory_size : config . max_heap_memory_size , .. Limits :: default ( ) } , ) ? ; // instantiate the module in the memory region let instance = region . new_instance_builder ( module ) . with_embed_ctx :: < WasmModuleConfig > ( config . clone ( ) ) . with_embed_ctx :: < Option < Registration > > ( None ) . with_embed_ctx :: < context :: RaisedError > ( Default :: default ( ) ) . build ( ) ? ; let mut wasm_module = Self { config , instance , role : Role :: Transform , } ; let wasi_ctx = WasiCtxBuilder :: new ( ) . inherit_stdio ( ) . build ( ) ? ; wasm_module . instance . insert_embed_ctx ( wasi_ctx ) ; wasm_module . instance . run ( " " , & [ ] ) ? . returned ( ) ? ; let registration = wasm_module . instance . remove_embed_ctx :: < Option < Registration > > ( ) . and_then ( | v | v ) ; if let None = registration { error ! ( " " ) ; } Ok ( wasm_module ) }
Build the WASM instance from a given config.
Build the WASM instance from a given config .
config
impl Into<WasmModuleConfig> + Debug