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

Add cargo xtask set-cairo-version --path #1578

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Scarb is actively developed and open for contributions!
Grab any unassigned issue labeled with [`help-wanted`](https://github.com/software-mansion/scarb/labels/help%20wanted)!

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

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

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

## Contributing

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

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

### Typos

Our policy is to not accept PRs that only fix typos in the documentation and code. We appreciate your effort, but we
encourage you to focus on bugs and features instead.

## Tips

### Testing custom Cairo compiler changes

Sometimes you may happen to work on a feature to the Cairo compiler, and you would like to test how it works in Scarb
(for example, if you are working on Starknet Foundry).

We have a script that edits the `Cargo.toml` file to use a local checkout of the Cairo compiler.
To use this tool, run:

```shell
cargo xtask set-cairo-version --path ../path/to/cairo
```

And then you can `cargo build` Scarb with your custom Cairo compiler changes.

---

Thanks! ❤️ ❤️ ❤️
Expand Down
22 changes: 20 additions & 2 deletions xtask/src/set_cairo_version.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use clap::Parser;
use semver::Version;
use std::path::PathBuf;
use toml_edit::{DocumentMut, InlineTable, Value};
use xshell::{cmd, Shell};

Expand All @@ -22,6 +23,8 @@ struct Spec {
rev: Option<String>,
#[arg(short, long)]
branch: Option<String>,
#[arg(short, long, conflicts_with_all = ["rev", "branch"])]
path: Option<PathBuf>,
}

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

for (_, dep) in deps
for (dep_name, dep) in deps
.iter_mut()
.filter(|(key, _)| key.get().starts_with("cairo-lang-"))
{
let dep_name = dep_name.get();
let dep = dep.as_value_mut().unwrap();

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

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

// Add local path reference if requested.
// For local path sources, Cargo is not looking for crates recursively therefore,
// we need to manually provide full paths to Cairo workspace member crates.
if let Some(path) = &args.spec.path {
new_dep.insert(
"path",
path.join("crates")
.join(dep_name)
.to_string_lossy()
.into_owned()
.into(),
);
}

// Sometimes we might specify extra features. Let's preserve these.
if let Some(dep) = dep.as_inline_table() {
if let Some(features) = dep.get("features") {
Expand Down
Loading