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

Adds Makefile and env.sh #25

Merged
merged 8 commits into from
Jul 16, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
debug/
target/

.env
.envrc
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: usage deps build check test clean

UNAME := $(shell uname)

usage:
@echo "Usage:"
@echo " deps: Installs the necesarry dependencies."
@echo " build: Builds the crate."
@echo " check: Checks format and lints."
@echo " test: Runs all tests."
@echo " clean: Cleans the built artifacts."

build:
cargo build --release
# cargo build --release --all-features

check:
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings
# cargo clippy --all-targets --all-features -- -D warnings

test:
cargo test
# cargo test --profile ci --all-features

clean:
cargo clean

deps:
ifeq ($(UNAME), Darwin)
deps: deps-macos
endif
deps:

deps-macos:
-brew install llvm@18 --quiet
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
# starknet-replay
Provides a way of reading a real Starknet State, so you can re-execute an existing transaction in any of the Starknet networks in an easy way

## Getting Started

### Prerequisites

- Linux or macOS (aarch64 included) only for now
- LLVM 18 with MLIR
- Rust 1.78.0 or later, since cairo-native makes use of the u128 abi change.
- Git

### Setup

Run the following make target to install dependencies:
```bash
make deps
```
It will automatically install LLVM 18 with MLIR on macos, if you are using linux you must do it manually. On debian, you can use `apt.llvm.org`, or build it from source.

This project is integrated with Cairo Native, see [Cairo Native Setup](#cairo-native-setup) to set it up correctly

Some environment variable are needed, you can automatically set them by sourcing `env.sh`. If the script doesn't adjust to your specific environment you can `cp` it into `.env` or `.envrc` and modify it.
```bash
# Cairo Native
export LLVM_SYS_181_PREFIX=/path/to/llvm-18
export MLIR_SYS_180_PREFIX=/path/to/llvm-18
export TABLEGEN_180_PREFIX=/path/to/llvm-18
export CAIRO_NATIVE_RUNTIME_LIBRARY=/path/to/cairo_native/target/release/libcairo_native_runtime.a
# RPC
export RPC_ENDPOINT_MAINNET=rpc.endpoint.mainnet.com
export RPC_ENDPOINT_TESTNET=rpc.endpoint.testnet.com
```

Once you have installed dependencies and set the needed environment variables, you can build the project and run the tests:
```bash
make build
make test
```

### Cairo Native Setup

Starknet Replay is currenlty integrated with [Cairo Native](https://github.com/lambdaclass/cairo_native), which makes the execution of sierra programs possible through native machine code. To use it, the following needs to be setup:

- LLVM `18` needs to be installed and the `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run
- On mac with brew, running `make deps` should have installed LLVM 18 with MLIR, otherwise, you must install it manually. On Debian, you can use `apt.llvm.org`, or build it from source.

- The `LLVM_SYS_181_PREFIX`, `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run:
```
brew install llvm@18
export MLIR_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18
export LLVM_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18
export MLIR_SYS_181_PREFIX=/opt/homebrew/opt/llvm@18
export TABLEGEN_180_PREFIX=/opt/homebrew/opt/llvm@18
```
and you're set.
Expand Down
38 changes: 38 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
#
# It sets the LLVM environment variables.
#
# You can copy this file to .envrc/.env and adapt it for your environment.

case $(uname) in
Darwin)
# If installed with brew
LLVM_SYS_181_PREFIX="$(brew --prefix llvm@18)"
MLIR_SYS_180_PREFIX="$(brew --prefix llvm@18)"
TABLEGEN_180_PREFIX="$(brew --prefix llvm@18)"

export LLVM_SYS_181_PREFIX
export MLIR_SYS_180_PREFIX
export TABLEGEN_180_PREFIX
;;
Linux)
# If installed from Debian/Ubuntu repository:
LLVM_SYS_181_PREFIX=/usr/lib/llvm-18
MLIR_SYS_180_PREFIX=/usr/lib/llvm-18
TABLEGEN_180_PREFIX=/usr/lib/llvm-18

export LLVM_SYS_181_PREFIX
export MLIR_SYS_180_PREFIX
export TABLEGEN_180_PREFIX
;;
esac

# export CAIRO_NATIVE_RUNTIME_LIBRARY=
# export RPC_ENDPOINT_MAINNET=
# export RPC_ENDPOINT_TESTNET=

echo "loaded LLVM environment variables"
echo "remember you must manually set:"
echo "- RPC_ENDPOINT_MAINNET=rpc.endpoint.mainnet.com"
echo "- RPC_ENDPOINT_TESTNET=rpc.endpoint.testnet.com"
echo "- CAIRO_NATIVE_RUNTIME_LIBRARY=path/to/cairo_native/target/release/libcairo_native_runtime.a"