Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piwonskp/hello-cairo-plugin
A hello world plugin for cairo language
https://github.com/piwonskp/hello-cairo-plugin
Last synced: 2 months ago
JSON representation
A hello world plugin for cairo language
- Host: GitHub
- URL: https://github.com/piwonskp/hello-cairo-plugin
- Owner: piwonskp
- Created: 2023-11-28T13:32:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-18T16:28:16.000Z (9 months ago)
- Last Synced: 2024-08-05T01:10:55.443Z (6 months ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-starknet - hello-cairo-plugin - Example Cairo plugin. (Additional developer resources)
README
# Hello cairo plugin
The repository demonstrates the usage of cairo plugin system. It contains the plugin which for each function annotated with `hello` attribute prints `Hello, !`.
## Quickstart
### Prerequisites
Setup the cairo environment with the `asdf install` command.
### Usage
To use the plugin in your project annotate a function with `hello` attribute:
```
#[hello]
fn multiply(a: u8, b: u8) -> u8 {
a * b
}
```An example project is located in [example directory](./example/).
### Execution
1. cd into project directory:
```
cd example/
```
2. Run scarb with the hello-cairo-plugin:```
scarb cairo-run
```3. You should see the output:
```
Running examples
[DEBUG] 0x48656c6c6f2c206d61696e21 ('Hello, main!')
[DEBUG] 0x48656c6c6f2c2061646421 ('Hello, add!')
[DEBUG] 0x48656c6c6f2c206d756c7469706c7921 ('Hello, multiply!')
[DEBUG] 0x48656c6c6f2c20666f6f21 ('Hello, foo!')
Run completed successfully, returning []
```## Development
The repository shows the implementation of cairo plugin with macros. For the implementation of macros see [src/lib.rs](./src/lib.rs). The file illustrates two approaches to developing attribute macros:
* hello macro using native cairo parser
* hello_regex macro implementing the same functionality using regexIt is recommended especially for complex macros to use the native cairo parser as regexes are often error prone and have their limitations. They are lightweight however and may be enough for some macros.
For more see [scarb's documentation on procedural macros](https://docs.swmansion.com/scarb/docs/reference/procedural-macro.html#procedural-macro-will-be-called-from-cairo-code).