Skip to content

Commit 2cd52b7

Browse files
authored
Allow creation of a CacheConfig without loading from a file (#10665)
* cache: Add builder pattern for CacheConfig * wasmtime: Add cache_config method to wasmtime::Config * Refactor test_builder_default to use test_prolog helper * Remove enabled option from CacheConfigBuilder and always set to true * Change builder methods to take &mut self and return &mut Self * Simplify cache configuration API A new `cache_config(Option<CacheConfig>)` method replaces multiple methods for controlling module caching. Now `None` disables caching, and users can directly provide a cache config or load one from a file. * Make cache configuration optional * Add Cache struct to separate configuration from runtime (wip) * Ensure default values earlier * Consolidate CacheConfig and CacheConfigBuilder * Set Cache directly on wastime::Config and make it easier to create one from a file * Validate after loading file again * Move cache to top-level module * Fix tests
1 parent 3a5dda5 commit 2cd52b7

File tree

15 files changed

+590
-450
lines changed

15 files changed

+590
-450
lines changed

crates/bench-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl BenchState {
436436
) -> Result<Self> {
437437
let mut config = options.config(None)?;
438438
// NB: always disable the compilation cache.
439-
config.disable_cache();
439+
config.cache(None);
440440
let engine = Engine::new(&config)?;
441441
let mut linker = Linker::<HostState>::new(&engine);
442442

crates/c-api/src/config.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,18 @@ pub unsafe extern "C" fn wasmtime_config_cache_config_load(
211211
c: &mut wasm_config_t,
212212
filename: *const c_char,
213213
) -> Option<Box<wasmtime_error_t>> {
214+
use std::path::Path;
215+
216+
use wasmtime::Cache;
217+
214218
handle_result(
215219
if filename.is_null() {
216-
c.config.cache_config_load_default()
220+
Cache::from_file(None).map(|cache| c.config.cache(Some(cache)))
217221
} else {
218222
match CStr::from_ptr(filename).to_str() {
219-
Ok(s) => c.config.cache_config_load(s),
223+
Ok(s) => {
224+
Cache::from_file(Some(&Path::new(s))).map(|cache| c.config.cache(Some(cache)))
225+
}
220226
Err(e) => Err(e.into()),
221227
}
222228
},

0 commit comments

Comments
 (0)