Skip to content

Commit

Permalink
feat: macros package (#324)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

## Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## Description

This PR introduces a new Alexandria package, `alexandria_macros`. The
idea is to group any and all useful macros in here. As an introduction,
it also adds a humble `pow!` macro that calculates x to the power of y.
I hope many more will follow.

Because Cairo macros are Rust programs, I added a new separate GitHub
workflow just to test macros. Also because of the way macros work (at
least to my understanding), I added a `macros_tests` directory that
serves just as a dummy Scarb project to run tests on; it is not part of
the Alexandria workspace. Not sure this is the best way to go about it,
but having the tests inside the main macros package didn't work for me
(i.e. I didn't find a way how to do it, if there's some, I'm happy to
amend the PR).

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->

---------

Co-authored-by: Marek Kaput <[email protected]>
  • Loading branch information
milancermak and mkaput authored Aug 22, 2024
1 parent caca4f2 commit 7c19379
Show file tree
Hide file tree
Showing 12 changed files with 951 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/macros.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Macros CI

on:
push:
paths:
- 'packages/macros/**'
- 'packages/macros_tests/**'
pull_request:
paths:
- 'packages/macros/**'
- 'packages/macros_tests/**'

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/macros
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release

rustlint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/macros
env:
RUSTFLAGS: "-Dwarnings" # fail on warnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Format check
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all

scarbfmt:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/macros_tests
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
- name: Cairo format check
run: scarb fmt --check
4 changes: 4 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ dependencies = [
"alexandria_math",
]

[[package]]
name = "alexandria_macros"
version = "0.1.0"

[[package]]
name = "alexandria_math"
version = "0.2.1"
Expand Down
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"packages/data_structures",
"packages/encoding",
"packages/linalg",
"packages/macros",
"packages/math",
"packages/merkle_tree",
"packages/numeric",
Expand Down
Loading

0 comments on commit 7c19379

Please sign in to comment.