Skip to content

Commit

Permalink
scarb 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
shramee committed Oct 30, 2023
1 parent 9015007 commit 0bd6387
Show file tree
Hide file tree
Showing 21 changed files with 3,626 additions and 1,148 deletions.
3,700 changes: 3,354 additions & 346 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 5 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,10 @@ glob = "0.3.0"
cairo-felt = "0.8.2"

# Cairo runner dependencies
cairo-lang-runner = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-test-runner = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-compiler = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-casm = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-diagnostics = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-debug = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-defs = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-sierra = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-sierra-ap-change = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-sierra-gas = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-sierra-generator = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-semantic = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-sierra-to-casm = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-utils = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-filesystem = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-starknet = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-syntax = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-plugins = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}
cairo-lang-lowering = {git = "https://github.com/starkware-libs/cairo", tag = "v2.2.0"}

cairo-lang-test-runner = {git = "https://github.com/starkware-libs/cairo", tag = "v2.3.0"}
cairo-lang-test-plugin = {git = "https://github.com/starkware-libs/cairo", tag = "v2.3.0"}
scarb = { git = "https://github.com/software-mansion/scarb", version = "2.3.0" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", version = "0.1.0" }

anyhow = "1.0.66"
ark-ff = "0.4.0-alpha.7"
Expand All @@ -57,6 +41,7 @@ thiserror = "1.0.32"
rayon = "0.9.0"
colored = "2"
unescaper = "0.1.1"
camino = "1.1.6"

[dev-dependencies]
assert_cmd = "0.11.0"
Expand All @@ -66,11 +51,3 @@ glob = "0.3.0"
[[bin]]
name = "starklings"
path = "src/main.rs"

[[bin]]
name = "starklings-runner"
path = "src/starklings_runner.rs"

[[bin]]
name = "starklings-tester"
path = "src/starklings_tester.rs"
10 changes: 0 additions & 10 deletions Scarb.toml

This file was deleted.

6 changes: 6 additions & 0 deletions corelib/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "core"
version = "2.2.0"
46 changes: 23 additions & 23 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
[[exercises]]
name = "intro1"
path = "exercises/intro/intro1.cairo"
mode = "compile"
mode = "build"
hint = """
No hints this time ;)
"""

[[exercises]]
name = "intro2"
path = "exercises/intro/intro2.cairo"
mode = "compile"
mode = "build"
hint = """
No hints this time ;)
"""
Expand All @@ -21,15 +21,15 @@ No hints this time ;)
[[exercises]]
name = "variables1"
path = "exercises/variables/variables1.cairo"
mode = "compile"
mode = "build"
hint = """
The declaration on line 8 is missing a keyword that is needed in Cairo
to create a new variable binding."""

[[exercises]]
name = "variables2"
path = "exercises/variables/variables2.cairo"
mode = "compile"
mode = "build"
hint = """
What happens if you annotate line 7 with a type annotation?
What if you give x a value?
Expand All @@ -40,7 +40,7 @@ What if x is the same type as 10? What if it's a different type? (e.g. a u8)"""
[[exercises]]
name = "variables3"
path = "exercises/variables/variables3.cairo"
mode = "compile"
mode = "build"
hint = """
Oops! In this exercise, we have a variable binding that we've created on
line 7, and we're trying to use it on line 8, but we haven't given it a
Expand All @@ -51,7 +51,7 @@ programming language -- thankfully the Cairo compiler has caught this for us!"""
[[exercises]]
name = "variables4"
path = "exercises/variables/variables4.cairo"
mode = "compile"
mode = "build"
hint = """
In Cairo, variable bindings are immutable by default. But here we're trying
to reassign a different value to x! There's a keyword we can use to make
Expand All @@ -60,7 +60,7 @@ a variable binding mutable instead."""
[[exercises]]
name = "variables5"
path = "exercises/variables/variables5.cairo"
mode = "compile"
mode = "build"
hint = """
In variables4 we already learned how to make an immutable variable mutable
using a special keyword. Unfortunately this doesn't help us much in this exercise
Expand All @@ -75,7 +75,7 @@ Try to solve this exercise afterwards using this technique."""
[[exercises]]
name = "variables6"
path = "exercises/variables/variables6.cairo"
mode = "compile"
mode = "build"
hint = """
We know about variables and mutability, but there is another important type of
variable available: constants.
Expand All @@ -90,19 +90,19 @@ You can read about the constants here: https://cairo-book.github.io/ch02-01-vari
[[exercises]]
name = "primitive_types1"
path = "exercises/primitive_types/primitive_types1.cairo"
mode = "compile"
mode = "build"
hint = "No hints this time ;)"

[[exercises]]
name = "primitive_types2"
path = "exercises/primitive_types/primitive_types2.cairo"
mode = "compile"
mode = "build"
hint = "No hints this time ;)"

[[exercises]]
name = "primitive_types3"
path = "exercises/primitive_types/primitive_types3.cairo"
mode = "compile"
mode = "build"
hint = """
You'll need to make a pattern to bind `name` and `age` to the appropriate parts
of the tuple.
Expand Down Expand Up @@ -168,7 +168,7 @@ conditions checking different input values."""
[[exercises]]
name = "functions1"
path = "exercises/functions/functions1.cairo"
mode = "compile"
mode = "build"
hint = """
This main function is calling a function that it expects to exist, but the
function doesn't exist. It expects this function to have the name `call_me`.
Expand All @@ -178,15 +178,15 @@ Sounds a lot like `main`, doesn't it?"""
[[exercises]]
name = "functions2"
path = "exercises/functions/functions2.cairo"
mode = "compile"
mode = "build"
hint = """
Cairo requires that all parts of a function's signature have type annotations,
but `call_me` is missing the type annotation of `num`. What is the basic type in Cairo?"""

[[exercises]]
name = "functions3"
path = "exercises/functions/functions3.cairo"
mode = "compile"
mode = "build"
hint = """
This time, the function *declaration* is okay, but there's something wrong
with the place where we're calling the function.
Expand All @@ -197,7 +197,7 @@ Watch mode will only jump to the next exercise if you remove the I AM NOT DONE c
[[exercises]]
name = "functions4"
path = "exercises/functions/functions4.cairo"
mode = "compile"
mode = "build"
hint = """
The error message points to line 18 and says it expects a type after the
`->`. This is where the function's return type should be -- take a look at
Expand Down Expand Up @@ -235,13 +235,13 @@ You can return values from loops by adding the value you want returned after the
[[exercises]]
name = "enums1"
path = "exercises/enums/enums1.cairo"
mode = "compile"
mode = "build"
hint = "https://cairo-book.github.io/ch06-01-enums.html"

[[exercises]]
name = "enums2"
path = "exercises/enums/enums2.cairo"
mode = "compile"
mode = "build"
hint = """
You can create enumerations that have different variants with different types
such as no data, structs, a single felt string, tuples, ...etc
Expand Down Expand Up @@ -385,7 +385,7 @@ This section will help you understanding more about methods https://cairo-book.g
[[exercises]]
name = "move_semantics1"
path = "exercises/move_semantics/move_semantics1.cairo"
mode = "compile"
mode = "build"
hint = """
So you've got the "ref argument must be a mutable variable." error on line 17,
right? The fix for this is going to be adding one keyword, and the addition is NOT on line 17
Expand All @@ -399,7 +399,7 @@ Read more about move semantics and ownership here: https://cairo-book.github.io/
[[exercises]]
name = "move_semantics2"
path = "exercises/move_semantics/move_semantics2.cairo"
mode = "compile"
mode = "build"
hint = """
So, `arr0` is passed into the `fill_arr` function as an argument. In Cairo,
when an argument is passed to a function and it's not explicitly returned,
Expand All @@ -420,7 +420,7 @@ There's a few ways to fix this, try them all if you want:
[[exercises]]
name = "move_semantics3"
path = "exercises/move_semantics/move_semantics3.cairo"
mode = "compile"
mode = "build"
hint = """
The difference between this one and the previous ones is that the first line
of `fn fill_arr` that had `let mut arr = arr;` is no longer there. You can,
Expand All @@ -430,7 +430,7 @@ an existing binding to be a mutable binding instead of an immutable one :)"""
[[exercises]]
name = "move_semantics4"
path = "exercises/move_semantics/move_semantics4.cairo"
mode = "compile"
mode = "build"
hint = """
Stop reading whenever you feel like you have enough direction :) Or try
doing one step and then fixing the compiler errors that result!
Expand All @@ -445,7 +445,7 @@ So the end goal is to:
[[exercises]]
name = "move_semantics5"
path = "exercises/move_semantics/move_semantics5.cairo"
mode = "compile"
mode = "build"
hint = """
Carefully reason about how each function takes ownership of the variable passed.
It depends on the keyword used to pass the variable.
Expand All @@ -456,7 +456,7 @@ Can we still use it later on?
[[exercises]]
name = "move_semantics6"
path = "exercises/move_semantics/move_semantics6.cairo"
mode = "compile"
mode = "build"
hint = """
The first problem is that `get_value` is taking ownership of the Number struct.
So `Number` is moved and can't be used for `set_value`
Expand Down
1 change: 1 addition & 0 deletions runner-crate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
6 changes: 6 additions & 0 deletions runner-crate/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "runner_crate"
version = "0.1.0"
8 changes: 8 additions & 0 deletions runner-crate/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "runner_crate"
version = "0.1.0"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
# foo = { path = "vendor/foo" }
25 changes: 25 additions & 0 deletions runner-crate/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// move_semantics2.cairo
// Make me compile without changing line 16 or moving line 13!
// Execute `starklings hint move_semantics2` or use the `hint` watch subcommand for a hint.

use array::ArrayTrait;
use debug::PrintTrait;

fn main() {
let mut arr0 = ArrayTrait::new();

let mut arr1 = fill_arr(arr0);

// Do not change the following line!
arr0.print();
}

fn fill_arr(arr: Array<felt252>) -> Array<felt252> {
let mut arr = arr;

arr.append(22);
arr.append(44);
arr.append(66);

arr
}
24 changes: 10 additions & 14 deletions src/exercise.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use regex::Regex;
use serde::Deserialize;

use crate::starklings_runner::{run_cairo_program, Args as RunnerArgs};
use crate::starklings_tester::run_exercise_tests;
use std::fmt::{self, Display, Formatter};
use std::fs::{remove_file, File};
use std::io::Read;
use std::path::PathBuf;
use std::process::{self};

use crate::scarb::{scarb_build, scarb_test};

const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE";
const CONTEXT: usize = 2;

Expand All @@ -28,7 +28,7 @@ fn temp_file() -> String {
#[serde(rename_all = "lowercase")]
pub enum Mode {
// Indicates that the exercise should be compiled as a binary
Compile,
Build,
// Indicates that the exercise should be tested
Test,
}
Expand All @@ -46,7 +46,7 @@ pub struct Exercise {
pub name: String,
// The path to the file containing the exercise's source code
pub path: PathBuf,
// The mode of the exercise (Test, Compile, or Clippy)
// The mode of the exercise (Test/Build)
pub mode: Mode,
// The hint text associated with the exercise
pub hint: String,
Expand Down Expand Up @@ -91,16 +91,12 @@ impl Drop for FileHandle {
}

impl Exercise {
pub fn run_cairo(&self) -> anyhow::Result<String> {
run_cairo_program(&RunnerArgs {
path: self.path.to_str().unwrap().parse()?,
available_gas: Some(20000000000),
print_full_memory: false,
})
pub fn build(&self) -> anyhow::Result<String> {
scarb_build(&self.path)
}

pub fn test_cairo(&self) -> anyhow::Result<String> {
run_exercise_tests(self.path.to_str().unwrap())
pub fn test(&self) -> anyhow::Result<String> {
scarb_test(&self.path)
}

pub fn state(&self) -> State {
Expand Down Expand Up @@ -177,7 +173,7 @@ mod test {
let exercise = Exercise {
name: "finished_exercise".into(),
path: PathBuf::from("tests/fixture/cairo/compilePass.cairo"),
mode: Mode::Compile,
mode: Mode::Build,
hint: String::new(),
};

Expand All @@ -189,7 +185,7 @@ mod test {
let exercise = Exercise {
name: "testPass".into(),
path: PathBuf::from("tests/fixture/cairo/testPass.cairo"),
mode: Mode::Compile,
mode: Mode::Build,
hint: String::new(),
};

Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ mod ui;
mod exercise;
mod project;
mod run;
pub mod starklings_runner;
pub mod starklings_tester;
mod scarb;
mod verify;

// In sync with crate version
Expand Down
Loading

0 comments on commit 0bd6387

Please sign in to comment.