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

About use of Scarb #44

Closed
mkaput opened this issue Feb 10, 2023 · 0 comments
Closed

About use of Scarb #44

mkaput opened this issue Feb 10, 2023 · 0 comments

Comments

@mkaput
Copy link

mkaput commented Feb 10, 2023

Hey!

@tarrencev reached to me on private channels about the idea of integrating Scarb's compiler ops in Dojo. That's a discussion worth publicizing, so I'll write down my thoughts here:

Preface

  1. Dojo-cli and dojo-plugin as standalone components #40 seems to do a lot of stuff that is already worked out by Scarb's ops::compile.
  2. Scarb is meant to be available as a crate. The only blocker from publishing it to crates.io as of the time of writing this, is that we still depend on unpublished Cairo revisions.
    1. One thing though that I am still thinking of is whether it wouldn't be better to extract Scarb compiler logic (i.e. the ops::compile function to a separate crate), and perhaps even make the compiler an extension provided as a separate library
    2. But this is a nuance at this moment, Dojo and others shouldn't feel this change super hard if it would happen
  3. The only trick for you, I can see is that currently Scarb doesn't provide an entrypoint to boot the compiler with custom plugins. This may be something I would welcome you to contribute if you wish because definitely I and @maciektr don't have spare time at this moment to tackle this 😞

Scarb and Dojo current state context

  1. The general framework of compiler extensibility is the targets mechanism.
  2. https://github.com/software-mansion/scarb/blob/6ba612b08c2e1b7ab5f1998e3d014648164c7eb7/scarb/src/compiler/targets/starknet_contract.rs basically has the code that is reimplemented in Dojo-cli and dojo-plugin as standalone components #40

Plan for extending Scarb to support Dojo's needs

I see two phases here: one that does the meat done, but is still kinda hacky, and second phase which cleans everything up:

Things that I am open to accept contributions

What is crucially missing for Dojo are two things:

  1. There should be a possiblity to register custom targets dynamically:
    • That anyway has to be done when we'll deal with extension targets.
    • Something like type TargetRepository = HashMap<TargetName, Box<dyn Fn(...) -> Box<dyn TargetCompiler>> is missing.
    • This repository object could live within Config, i.e. add target_repository: TargetRepository field to the Config struct.
    • Dojo would then be able to initialize config, inject their target to the repository, and then call ops::compile 🎉
  2. Next, it would be shame if Dojo had to copy-paste https://github.com/software-mansion/scarb/blob/6ba612b08c2e1b7ab5f1998e3d014648164c7eb7/scarb/src/compiler/targets/starknet_contract.rs, so extracting a common interface out of this would be fine.
    • No idea how this should look like, I would happily leave it to the contributor to think out and show me a suggestion.

The hacky part: all of this is still within scarb crate and is pubed from scarb::compiler module.

Things that should be done by myself, but can be deferred

Disclaimer: I am really not sure this should look like this because I didn't think into this deeply.

  1. The compiler part of the scarb crate probably has to be extracted into separate crates:
    1. scarb-build which will contain ops::compileand everything downstream, like TargetCompiler trait and lib target implementation.
    2. scarb-target-starknet-contract which will contain starknet-specific compiler logic.
  2. scarb-target-starknet-contract will depend on scarb-build, and both will depend on slimmed down scarb.
  3. The big benefit of this is that scarb will not depend on cairo-lang-* crates, that's funny, but this will help compilation times significantly I think. (This implies also extracting scarb fmt which is is going to land today).

I'll be very happy to hear your thoughts on this, and also criticism of my design decisions in Scarb. Many of decisions I made in Scarb haven't been validated yet publicly by anyone.

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