wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

wasi configurations in wasm_module_t

Open yamt opened this issue 7 months ago • 5 comments

wasm_runtime_set_wasi_args / wasm_runtime_set_wasi_args_ex sets wasi configurations on wasm_module_t. it isn't intuitive because those configuartions logically belong to wasm_module_inst_t. ideally it would be nice to allow to instantiate multiple wasm_module_inst_t from a single wasm_module_t.

one way to fix it is to make them a part of InstantiationArgs. it's unfortunate InstantiationArgs is defined in a way which can't be extended without breaking the ABI.

(i thought i filed this issue long time ago. but i couldn't find it. sorry if it's duplicated.)

yamt avatar Jun 13 '25 04:06 yamt

You are right. The current design doesn't accommodate usage scenarios like varying WASI contexts for multiple instances (either continuously in one thread or parallelly across multiple threads) of a module.

I prefer to add a new API like wasm_runtime_instantiate_with_wasi(wasm_module_t, InstantiationArgs*, WasiConfigArgs*, char*, uint32_t) and a new set of helpers for building WasiConfigArgs.

lum1n0us avatar Jun 18 '25 01:06 lum1n0us

#4256

lum1n0us avatar Jun 23 '25 00:06 lum1n0us

#4256

oh, was it this May? i thought it was at least a few years ago. it seems my memory is severely broken.

yamt avatar Jun 23 '25 01:06 yamt

You are right. The current design doesn't accommodate usage scenarios like varying WASI contexts for multiple instances (either continuously in one thread or parallelly across multiple threads) of a module.

I prefer to add a new API like wasm_runtime_instantiate_with_wasi(wasm_module_t, InstantiationArgs*, WasiConfigArgs*, char*, uint32_t) and a new set of helpers for building WasiConfigArgs.

how about:

struct InstantiationArgs2;

bool
wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p);
void
wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p);

void
wasm_runtime_instantiation_args_set_default_stack_size(
    struct InstantiationArgs2 *p, uint32 v);

WASM_RUNTIME_API_EXTERN wasm_module_inst_t
wasm_runtime_instantiate_ex2(const wasm_module_t module,
                             const struct InstantiationArgs2 *args,
                             char *error_buf, uint32_t error_buf_size);

this way we can add wasm_runtime_instantiation_args_set_xxx without breaking api/abi.

yamt avatar Jul 01 '25 06:07 yamt

Looks good to me. Let's see how it goes.

lum1n0us avatar Jul 02 '25 01:07 lum1n0us