Skip to content

Improved WASMER_METADATA_{prefix} for static artifacts #5189

Open
@Destructor17

Description

@Destructor17

Motivation

When making module from static artifact, it is currently required to include C header made using gen-c-header subcommand. This header includes implementation of generate_serialized_data_{prefix} function. It makes loading static artifacts more complicated, especially from Rust.

generate_serialized_data_{prefix} is actually simple: it accepts no parameters and concatenates WASMER_METADATA_{prefix} with some function pointers. Every invocation of generate_serialized_data_{prefix} returns same data.

Proposed solution

The idea is to append these function pointers to WASMER_METADATA_{prefix} and add WASMER_METADATA_{prefix}_SIZE, so static artifact can be loaded without including generated C header. This solution should not break loading static artifact using generated C header.

Alternatives

It is theoretically possible to move generate_serialized_data_{prefix} to object generated using create-exe and create-obj subcommand, but it seems to be too complicated and not reasonable.

Additional context

Example code loading static artifact. No C code is used.

extern "C" {
    static WASMER_METADATA_WR_AOT: u8;
    static WASMER_METADATA_WR_AOT_SIZE: usize;
}

let module = unsafe {
    wasmer::Module::deserialize(
        &store,
        std::slice::from_raw_parts(&WASMER_METADATA_WR_AOT, WASMER_METADATA_WR_AOT_SIZE),
    )?
};

Here is a draft implementation of this feature. I am not very experienced in rust, so it is not likely that I will make a PR.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions