Skip to content

Commit 0f2bfdf

Browse files
authored
Add cargo xtask set-cairo-version --path (#1578)
This small utility seems very helpful when setting up custom Scarb checkout for testing some work on the Cairo compiler. Signed-off-by: Marek Kaput <[email protected]>
1 parent 64c9eb6 commit 0f2bfdf

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

CONTRIBUTING.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Scarb is actively developed and open for contributions!
66
Grab any unassigned issue labeled with [`help-wanted`](https://github.com/software-mansion/scarb/labels/help%20wanted)!
77

88
*Looking for some easy warmup tasks?*
9-
Check out issues labeled with [`good-first-issue`](https://github.com/software-mansion/scarb/labels/good%20first%20issue)!
9+
Check out issues labeled with [
10+
`good-first-issue`](https://github.com/software-mansion/scarb/labels/good%20first%20issue)!
1011

1112
*Need some guidance?*
1213
Reach out to other developers on [Telegram](https://t.me/+1pMLtrNj5NthZWJk)!
@@ -17,7 +18,8 @@ Latest stable Rust is the only thing you really need.
1718
It is recommended to use [rustup](https://rustup.rs/) for getting it.
1819

1920
If you wish to work on Scarb's website, you will need [Node.js](https://nodejs.org/).
20-
We recommend to install it using [asdf](https://asdf-vm.com/) (via [nodejs](https://github.com/asdf-vm/asdf-nodejs) plugin).
21+
We recommend to install it using [asdf](https://asdf-vm.com/) (via [nodejs](https://github.com/asdf-vm/asdf-nodejs)
22+
plugin).
2123

2224
## Contributing
2325

@@ -56,13 +58,31 @@ Each commit should pass lints and tests.
5658
Then, set up a stack of pull requests, separate PR for each commit, and pointing to the previous one.
5759

5860
While your PR is being reviewed on, you can push merge commits and
59-
use [`git commit --fixup`](https://git-scm.com/docs/git-commit/2.32.0#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
61+
use [
62+
`git commit --fixup`](https://git-scm.com/docs/git-commit/2.32.0#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6063
to push further changes to your commits.
6164

6265
### Typos
66+
6367
Our policy is to not accept PRs that only fix typos in the documentation and code. We appreciate your effort, but we
6468
encourage you to focus on bugs and features instead.
6569

70+
## Tips
71+
72+
### Testing custom Cairo compiler changes
73+
74+
Sometimes you may happen to work on a feature to the Cairo compiler, and you would like to test how it works in Scarb
75+
(for example, if you are working on Starknet Foundry).
76+
77+
We have a script that edits the `Cargo.toml` file to use a local checkout of the Cairo compiler.
78+
To use this tool, run:
79+
80+
```shell
81+
cargo xtask set-cairo-version --path ../path/to/cairo
82+
```
83+
84+
And then you can `cargo build` Scarb with your custom Cairo compiler changes.
85+
6686
---
6787

6888
Thanks! ❤️ ❤️ ❤️

xtask/src/set_cairo_version.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Result;
22
use clap::Parser;
33
use semver::Version;
4+
use std::path::PathBuf;
45
use toml_edit::{DocumentMut, InlineTable, Value};
56
use xshell::{cmd, Shell};
67

@@ -22,6 +23,8 @@ struct Spec {
2223
rev: Option<String>,
2324
#[arg(short, long)]
2425
branch: Option<String>,
26+
#[arg(short, long, conflicts_with_all = ["rev", "branch"])]
27+
path: Option<PathBuf>,
2528
}
2629

2730
pub fn main(args: Args) -> Result<()> {
@@ -32,10 +35,11 @@ pub fn main(args: Args) -> Result<()> {
3235
.as_table_mut()
3336
.unwrap();
3437

35-
for (_, dep) in deps
38+
for (dep_name, dep) in deps
3639
.iter_mut()
3740
.filter(|(key, _)| key.get().starts_with("cairo-lang-"))
3841
{
42+
let dep_name = dep_name.get();
3943
let dep = dep.as_value_mut().unwrap();
4044

4145
// Start with expanded form: { version = "X" }
@@ -45,7 +49,7 @@ pub fn main(args: Args) -> Result<()> {
4549
new_dep.insert("version", version.to_string().into());
4650
}
4751

48-
// Add Git branch/revision reference if requested.
52+
// Add a Git branch or revision reference if requested.
4953
if args.spec.rev.is_some() || args.spec.branch.is_some() {
5054
new_dep.insert("git", "https://github.com/starkware-libs/cairo".into());
5155
}
@@ -58,6 +62,20 @@ pub fn main(args: Args) -> Result<()> {
5862
new_dep.insert("rev", rev.as_str().into());
5963
}
6064

65+
// Add local path reference if requested.
66+
// For local path sources, Cargo is not looking for crates recursively therefore,
67+
// we need to manually provide full paths to Cairo workspace member crates.
68+
if let Some(path) = &args.spec.path {
69+
new_dep.insert(
70+
"path",
71+
path.join("crates")
72+
.join(dep_name)
73+
.to_string_lossy()
74+
.into_owned()
75+
.into(),
76+
);
77+
}
78+
6179
// Sometimes we might specify extra features. Let's preserve these.
6280
if let Some(dep) = dep.as_inline_table() {
6381
if let Some(features) = dep.get("features") {

0 commit comments

Comments
 (0)