Detect components in wasmtime compile more robustly (#5592)

The binary version of component is going to change over time so use a
more robust method than checking for a fixed 8 bytes.
This commit is contained in:
Alex Crichton
2023-01-18 18:39:35 -06:00
committed by GitHub
parent 0e92fba7e1
commit d24c2fe48c
3 changed files with 11 additions and 1 deletions

View File

@@ -90,7 +90,15 @@ impl CompileCommand {
// bytes with the current component model proposal.
#[cfg(feature = "component-model")]
{
if input.starts_with(b"\0asm\x0a\0\x01\0") {
if let Ok(wasmparser::Chunk::Parsed {
payload:
wasmparser::Payload::Version {
encoding: wasmparser::Encoding::Component,
..
},
..
}) = wasmparser::Parser::new(0).parse(&input, true)
{
fs::write(output, engine.precompile_component(&input)?)?;
return Ok(());
}