scarb icon indicating copy to clipboard operation
scarb copied to clipboard

Support casm serialised output

Open maciektr opened this issue 2 years ago • 8 comments

Problem

As of now, lib target compilation (as opposed to starknet contract targets) is capable of producing CASM artefacts in a textual, human readable format only (equivalent to sierra-compile compiler cli). In contrast, starknet contract compilation uses serialisable json format instead. It is possible to define a similar serialisable casm format for non-contract projects as well. This alternative should be supported as an artefact of lib target compilation.

Proposed solution

  • Modify lib target properties to allow casm artefact format specification
    • lib target properties are defined here: https://github.com/software-mansion/scarb/blob/ba2c45574cf149a2d7422cb7c89aef5a203ec970/scarb/src/compiler/compilers/lib.rs#L18-L22
    • Analogously to sierra artefact, it should allow casm and casm_text boolean inputs.
    • casm should create json serialized artefacts, while casm-text should create textual ones.
    • By default both should be disabled.
    • This properties will be available to users as casm and casm-text keys on [lib] object in Scarb.toml manifest files.
  • Modify lib target compiler to produce new artefacts.
    • This compiler abstraction is implemented in this file: https://github.com/software-mansion/scarb/blob/ba2c45574cf149a2d7422cb7c89aef5a203ec970/scarb/src/compiler/compilers/lib.rs#L39
    • Should read properties from previous point and produce artefacts accordingly to user specification.
    • Artefact for serialised output should be written with .casm.json extension into the target directory with target name as filename.
    • Artefact for textual output should be written with .casm extension into the target directory, with the same name.
  • Ensure new artefact type is produced
    • It should be enough to modify this test case https://github.com/software-mansion/scarb/blob/ba2c45574cf149a2d7422cb7c89aef5a203ec970/scarb/tests/build_targets.rs#L72

Notes

See https://github.com/software-mansion/scarb/pull/637/files for similar change introducing new artefact format.

maciektr avatar Sep 14 '23 09:09 maciektr

I am taking this one 🙋

rodrodros avatar Sep 14 '23 13:09 rodrodros

  • Analogously to sierra artefact, it should allow casm and casm_text boolean inputs.
  • casm should create json serialized artefacts, while casm-text should create textual ones.
  • By default both should be disabled.
  • This properties will be available to users as casm and casm-text keys on [lib] object in Scarb.toml manifest files.

I'm not entirely sure about this ones; perhaps we should consult this with Ori or Ariel. For CASM it kinda makes sense to still output text as the default, isn't it?

mkaput avatar Sep 15 '23 08:09 mkaput

I'm not entirely sure about this ones; perhaps we should consult this with Ori or Ariel. For CASM it kinda makes sense to still output text as the default, isn't it?

The only I can think of is that it is for Cairo devs to verify the Casm of some high-level Cairo code is as expected. Beyond that, I really don't see much use.

Given the knowledge I have, for casm to make sense it needs to have some metadata that describes it such as Entrypoints, Builtins and Hints that it is using. If it is in something easily parseable format (such as json) it really helps other non-rusty tools.

rodrodros avatar Sep 15 '23 23:09 rodrodros

I've asked Cairo team about this.

mkaput avatar Sep 19 '23 10:09 mkaput

OK, discussed privately with @orizi. Let's make JSON the default, and add casm-text option.

mkaput avatar Sep 20 '23 07:09 mkaput

Hi @rodrigo-pino ! Are you working on this?

maciektr avatar Oct 31 '23 11:10 maciektr

Hi @maciektr, sorry just did an initial scope analysis gathering what I needed to implement, I found in that search that I will need Sierra metadata as well since in order to made a Cairo 1 runner you require metadata that exists on both Sierra and Casm (but that can be another separate PR)

I haven't implemented much, but be sure I (or someone from the team) will take on this since we do need it at some point in not the far future. If you want to put it backlog or something, I understand. I'll ping you right here as soon as we are ready to take on this!

rodrodros avatar Oct 31 '23 14:10 rodrodros

Sure, I understand completely! I will put it back to backlog, but it's still yours!

maciektr avatar Nov 02 '23 09:11 maciektr

Closing as not planned since release of universal-sierra-compiler (software-mansion/universal-sierra-compiler) which should provide support for all different kinds of sierra to casm compilation.

maciektr avatar Jun 03 '24 10:06 maciektr