Support casm serialised output
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
libtarget properties to allow casm artefact format specification-
libtarget properties are defined here: https://github.com/software-mansion/scarb/blob/ba2c45574cf149a2d7422cb7c89aef5a203ec970/scarb/src/compiler/compilers/lib.rs#L18-L22 - Analogously to
sierraartefact, it should allowcasmandcasm_textboolean inputs. -
casmshould create json serialized artefacts, whilecasm-textshould create textual ones. - By default both should be disabled.
- This properties will be available to users as
casmandcasm-textkeys on[lib]object inScarb.tomlmanifest files.
-
- Modify
libtarget 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.jsonextension into the target directory with target name as filename. - Artefact for textual output should be written with
.casmextension 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.
I am taking this one 🙋
- Analogously to
sierraartefact, it should allowcasmandcasm_textboolean inputs.casmshould create json serialized artefacts, whilecasm-textshould create textual ones.- By default both should be disabled.
- This properties will be available to users as
casmandcasm-textkeys on[lib]object inScarb.tomlmanifest 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?
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.
I've asked Cairo team about this.
OK, discussed privately with @orizi. Let's make JSON the default, and add casm-text option.
Hi @rodrigo-pino ! Are you working on this?
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!
Sure, I understand completely! I will put it back to backlog, but it's still yours!
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.