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

Machine readable info #51

Open
bitdivine opened this issue Nov 7, 2023 · 1 comment
Open

Machine readable info #51

bitdivine opened this issue Nov 7, 2023 · 1 comment

Comments

@bitdivine
Copy link
Member

First off, thank you for a useful project.

I used to use wasm-nm (src) to get the symbol table from a Wasm file. It's basically the UNIX nm but for Wasms. Unfortunately wasm-nm is unmaintained and doesn't work on recent Wasm files that have new instructions.

Thankfully ic-wasm info also provides the list of exported functions and it works with recent wasms, so that is great. My only minor gripe is that the output is not very machine readable. I have to parse it with sed and if ever you change the format, those sed scripts might well break.

Would you be open to providing a machine readable output? For example, ic-wasm info --json so that the output can be parsed with jq?

If so, I would be happy to provide a PR to do this. I would propose to gather all the info collected here into a struct. On that struct I would have a to_string() method that provides output identical to the current output. I would then add the option of serializing that struct as JSON instead.

What do you think?

@chenyan-dfinity
Copy link
Contributor

Sounds good to me. The current output is for human only, so we don't even need to keep the current format. Feel free to adjust the format as you see fit.

bitdivine added a commit that referenced this issue Nov 10, 2023
# Motivation
The output of `ic-wasm info` is useful but not reliably machine readable.  See #51 for more details.

# Changes
- Add a `--json` flag to `ic-wasm info`.
- Define a structure for the Wasm info and define Display and JSON Serialize traits on that structure.
  - The Display output matches the existing output exactly.
  - The JSON output provides the same data but in machine readable format.

# Tests
- The existing test for human readable output passes with no changes.
- A similar test has been added for JSON output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants