Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Engines (remove all engines except of one) #2916

Closed
syrusakbary opened this issue Jun 1, 2022 · 1 comment · Fixed by #3029
Closed

Refactor Engines (remove all engines except of one) #2916

syrusakbary opened this issue Jun 1, 2022 · 1 comment · Fixed by #3029
Assignees
Labels
🎉 enhancement New feature! priority-high High priority issue
Milestone

Comments

@syrusakbary
Copy link
Member

syrusakbary commented Jun 1, 2022

Wasmer currently has 3 engines: Universal, Dylib and Staticlib. This causes several issues in practice:

  • It is often unclear to users which engine they should be using and what the advantages/disadvantages of the various engines are.
  • For a long time the Dylib engine wasn’t properly supported on singlepass.
  • The Staticlib engine is poorly documented and hard to use. It basically only exists for wasmer create-exe.
  • There is a lot of code duplication between the various engines.
  • The use of multiple engines requires some types to be behind traits (e.g. Artifact). This makes code that interacts with these types more complicated due to the use of dyn and boxing.
  • The abstraction of serializing and de-serializing a module works well for the Universal engine but breaks down for the other engines. What does de-serializing a dylib or staticlib even mean?

The plan here is to deprecate all the existing engines and replace them with a single engine which covers all the existing use cases. This will also allow simplifying Wasmer by removing the engine crates and eliminating configuration options.

Artifact

The core element of the new engine is the Artifact. An Artifact consists of:

  • A data section, which contains:
    • The compiled code for all functions.
    • Constant data used by functions (.rodata).
    • Unwinding metadata for all functions.
  • A metadata section which contains everything else.
    • Function entry points are encoded as offsets into the data section.
    • This is encoded using rkyv so that it can be used in-place.

Unlike the current artifacts, the compiler is responsible for linking all the compiled code together into a single code block and resolving relocations between functions.

The Artifact format is deliberately simple so that it can be loaded in different ways. The main two are:

  • Memory-mapping the artifact from a file and constructing a Module from the two memory-mapped sections.
  • Having the artifact linked directly into the current program. A Module can be constructed from just the pointers to the data and metadata sections.

2 output formats:

  • Universal format → Dynamic loading by the runtime.
  • Object format → Statically linking. Closes How to use the staticlib engine in Rust #2827
    Way to include a static object (Wasm → .o compiled with Wasmer) and use it with Wasmer
extern "C" {
		static WASMER_FOO_DATA: [u8; 0];
		static WASMER_FOO_METADATA: [u8; 0];
}

unsafe {
		Module::from_ptr(WASMER_FOO_DATA.as_ptr(), WASMER_FOO_METADATA.as_ptr());
}
@syrusakbary
Copy link
Member Author

We need to define the format for the new engine. IMHO we can use the object crate to create the artifact and also to read/use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment