Hey, I have 3 questions surrounding Component::serialize:
Engine::precompile_module
. Am I correct to assume this? Component::from_file
on a component compiled with wasmtime compile
, I get the following errror: Error: failed to parse
led.cwasm: input bytes aren't valid utf-8
. After looking at the sourcecode for the compile command, I see that it calls precompile_module, does this mean that a compiled component should be loaded with Component::deserialize_file
instead?Engine::precompile_module
it states the following:The output of this method is safe to send to another host machine for later execution. As the output is already a compiled module, translation and code generation will be skipped and this will improve the performance of constructing a
Module
from the output of this method.
Does this also apply if the other host machine has a different architecture? I suppose so, but I'm not 100% certain.
If I'm comprehending the documentation correctly, this function isn't that different from
Engine::precompile_module
. Am I correct to assume this?
Correct, with the minor correction that the matching function would be Engine::precompile_component
(component vs module); Component
/Module::serialize
should produce the same output as Engine::precompile_component
/_module
.
When I try to do
Component::from_file
on a component compiled withwasmtime compile
, I get the following [...] does this mean that a compiled component should be loaded withComponent::deserialize_file
instead?
Yep: from_file
is for loading "regular" binary or text (WAT) wasm from a file. deserialize_file
is for Wasmtime/Cranelift-precompiled "cwasm".
In the documentation of
Engine::precompile_module
it states the following: The output of this method is safe to send to another host machine for later execution. [...] Does this also apply if the other host machine has a different architecture?
It is "safe" in the sense that it will fail to load rather than execute incorrectly, but a precompiled cwasm contains native, non-portable binary code which will not work on a different architecture, and might not even work across different processor models with the same architecture due to different features/configuration. See Module::deserialize
for details.
It should be possible to cross-compile cwasm from one architecture to another through careful configuration of, e.g. Config::target
, but this is really an advanced use case and not something that I have personal experience with.
Big thanks for the explanation! It all makes sense now.
Friedrich Vandenberghe has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC