|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +## Environment Setup |
| 4 | + |
| 5 | + |
| 6 | +ast-grep is written in [Rust](https://www.rust-lang.org/) and hosted by [git](https://git-scm.com/). |
| 7 | + |
| 8 | +You need to have rust environment installed to build ast-grep. |
| 9 | +The recommended way to install rust is via [rustup](https://rustup.rs/). |
| 10 | +Once you have rustup installed, you can install rust by running: |
| 11 | + |
| 12 | +```bash |
| 13 | +rustup install stable |
| 14 | +``` |
| 15 | + |
| 16 | +You also need [pre-commit](https://pre-commit.com/) to setup git hooks for type checking, formatting and clippy. |
| 17 | + |
| 18 | +Run pre-commit install to set up the git hook scripts. |
| 19 | + |
| 20 | +```bash |
| 21 | +pre-commit install |
| 22 | +``` |
| 23 | + |
| 24 | +Optionally, you can also install [nodejs](https://github.com/Schniz/fnm) and [yarn](https://yarnpkg.com/) for napi binding development. |
| 25 | + |
| 26 | +That's it! You have setup the environment for ast-grep! |
| 27 | + |
| 28 | +## Common Commands |
| 29 | + |
| 30 | +The below are some cargo commands common to any Rust project. |
| 31 | + |
| 32 | +```bash |
| 33 | +cargo test # Run test |
| 34 | +cargo check # Run checking |
| 35 | +cargo clippy # Run clippy |
| 36 | +cargo fmt # Run formatting |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | +Below are some ast-grep specific commands. |
| 41 | + |
| 42 | +## N-API Development |
| 43 | + |
| 44 | +[@ast-grep/napi](https://www.npmjs.com/package/@ast-grep/napi) is the [nodejs binding](https://napi.rs/) for ast-grep. |
| 45 | + |
| 46 | +The source code of napi binding is under the `crates/napi` folder. You can refer to the [package.json](https://github.com/ast-grep/ast-grep/blob/main/crates/napi/package.json) for available commands. |
| 47 | + |
| 48 | +```bash |
| 49 | +cd crates/napi |
| 50 | +yarn # Install dependencies |
| 51 | +yarn build # Build the binding |
| 52 | +yarn test # Run test |
| 53 | +``` |
| 54 | + |
| 55 | +## Run Benchmark |
| 56 | +ast-grep's Benchmark is not included in the default cargo test. You need to run the benchmark command in `benches` folder. |
| 57 | + |
| 58 | +```bash |
| 59 | +cd benches |
| 60 | +cargo bench |
| 61 | +``` |
| 62 | + |
| 63 | +ast-grep's benchmarking suite is not well developed yet. The result may fluctuate too much. |
| 64 | + |
| 65 | +## Release New Version |
| 66 | + |
| 67 | +The command below will bump version and create a git tag for ast-grep. |
| 68 | +Once pushed to GitHub, the tag will trigger [GitHub actions](https://github.com/ast-grep/ast-grep/blob/main/.github/workflows/coverage.yml) to build and publish the new version to [crates.io](https://github.com/ast-grep/ast-grep/blob/main/.github/workflows/pypi.yml), [npm](https://github.com/ast-grep/ast-grep/blob/main/.github/workflows/napi.yml) and [PyPi](https://github.com/ast-grep/ast-grep/blob/main/.github/workflows/pypi.yml). |
| 69 | + |
| 70 | +```bash |
| 71 | +cargo xtask [version-number] |
| 72 | +``` |
| 73 | + |
| 74 | +See [xtask](https://github.com/ast-grep/ast-grep/blob/main/xtask/src/main.rs) file for more details. |
0 commit comments