wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Add support for .wat files in create-obj command

Open afonso360 opened this issue 1 year ago • 1 comments
trafficstars

👋 Hey

Motivation

The CLI subcommand create-obj supports creating object files from wasm files. It'd be useful if it could also support compiling directly from wat files.

The use case for this is that when adding wasmer support to compiler explorer, I used create-obj to build a object file that could late be disassembled and shown to the user. However since create-obj doesn't support wat files I had to do some slightly hacky things and run it through wat2wasm before compiling.

This works, but is not something I'd like to upstream, so before doing that I'd like to ask if it would be possible to support it in create-obj first.

Proposed solution

Ideally I would be able to pass the text file instead of a wasm module as part of the input file to create-obj. We could detect if the file is a binary module by checking for the WASM magic header, or fall back to parsing a wat file.

Alternatively adding a flag that would interpret the input file as a wat file would also work.

Alternatives

I don't really need it for create-obj to support wat files directly. I only need a disassembly view of a compiled wat file. I don't think wasmer has a disassembly CLI flag (at least I couldn't find one), but that would also work.

Additionally I've also tried to use the compile subcommand, but the output of that doesn't seem to be a valid ELF file that I could disassemble.

Finally, I can also upstream my current implementation using wat2wasm, but I'd prefer to not do that unless there is no better solution.

CC: @syrusakbary since you've previously asked about wasmer support in CE.

afonso360 avatar Jun 11 '24 10:06 afonso360

That's a great idea. Thanks for opening the issue, this should be easy to solve on our side @afonso360

syrusakbary avatar Jun 20 '24 07:06 syrusakbary

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 20 '25 17:06 stale[bot]