Skip to content

Commit 99338d0

Browse files
doc: add development setup guide
fix ast-grep#157
1 parent 3b7e581 commit 99338d0

4 files changed

Lines changed: 76 additions & 1 deletion

File tree

website/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default defineConfig({
9191
text: 'Contributing',
9292
items: [
9393
{ text: 'Guide', link: '/contributing/how-to.html' },
94+
{ text: 'Development', link: '/contributing/development.html' },
9495
],
9596
collapsed: true,
9697
},
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.

website/contributing/how-to.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We appreciate your feedback on the project. Whether you have a feature request,
1919

2020
We welcome your code contributions to the project. Whether you want to fix a bug, implement a feature, improve the documentation, or add a new integration, we are grateful for your help. You can use the following repositories to contribute your code:
2121

22-
- **CLI Main Repo**: The [main repository for ast-grep](https://github.com/ast-grep/ast-grep) command-line interface (CLI). It contains the core logic and functionality of ast-grep. For small features or typo fixes, you can fork this repository and submit pull requests with your changes. _For larger features or big changes, please make an issue for discussion before jumping into it._
22+
- **CLI Main Repo**: The [main repository for ast-grep](https://github.com/ast-grep/ast-grep) command-line interface (CLI). It contains the core logic and functionality of ast-grep. For small features or typo fixes, you can fork this repository and submit pull requests with your changes. [This guide](/contributing/development.html) may help you set up essential tools for development. _For larger features or big changes, please make an issue for discussion before jumping into it._
2323

2424
<!-- Please follow the [code style guide] and the [testing guide] before submitting your pull requests. -->
2525

website/contributing/setup.md

Whitespace-only changes.

0 commit comments

Comments
 (0)