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

feat: streamlined build system and workflows #165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
92 changes: 88 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,96 @@
# Configuration variables
DOCKER_COMPOSE = docker compose
CARGO = cargo
RUSTFLAGS = -Dwarnings
MALACHITE_REPO = [email protected]:informalsystems/malachite.git
MALACHITE_COMMIT = 8a9f3702eb41199bc8a7f45139adba233a04744a
MALACHITE_DIR = ../malachite

# Help target - lists all available targets with descriptions
.PHONY: help
help:
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Development Workflow:"
@echo " dev - Start development environment with watch mode"
@echo " local-build - Build project locally including Malachite dependency"
@echo ""
@echo "Code Quality:"
@echo " check-commit - Run all code quality checks before committing"
@echo " lint - Run formatting and clippy checks"
@echo " fmt - Format code using rustfmt"
@echo " test - Run test suite"
@echo ""
@echo "Docker Commands:"
@echo " build - Build Docker containers"
@echo " clean - Remove all containers, volumes, images and build artifacts"
@echo ""
@echo "Examples:"
@echo " make dev - Start development environment"
@echo " make check-commit - Run all checks before committing"
@echo " make fmt && make test - Format code and run tests"
@echo ""
@echo "Common Workflows:"
@echo " 1. First time setup: make local-build"
@echo " 2. Regular development: make dev"
@echo " 3. Before committing: make check-commit"
@echo " 4. Clean environment: make clean"
@echo ""

# Set RUSTFLAGS for all cargo commands
export RUSTFLAGS

# Docker-related targets
.PHONY: build
build:
docker compose build --ssh default
$(DOCKER_COMPOSE) build --ssh default

.PHONY: dev
dev: build
docker compose up --watch
$(DOCKER_COMPOSE) up --watch

.PHONY: clean
clean:
docker compose down --remove-orphans --volumes --rmi=all
cargo clean
$(DOCKER_COMPOSE) down --remove-orphans --volumes --rmi=all
$(CARGO) clean

# Local development targets
.PHONY: local-build
local-build: setup-malachite
$(CARGO) build

.PHONY: setup-malachite
setup-malachite:
@if [ ! -d "$(MALACHITE_DIR)" ]; then \
cd .. && git clone $(MALACHITE_REPO); \
fi
cd $(MALACHITE_DIR) && \
git fetch && \
git checkout $(MALACHITE_COMMIT) && \
cd code && $(CARGO) build

# Code quality targets
.PHONY: check-commit
check-commit: test lint

.PHONY: test
test:
$(CARGO) test

.PHONY: lint
lint: fmt-check
$(CARGO) clippy -- -D warnings

.PHONY: fmt-check
fmt-check:
$(CARGO) fmt --all --check

.PHONY: fmt
fmt:
$(CARGO) fmt --all

# Default target
.DEFAULT_GOAL := help

.PHONY: all build dev clean local-build setup-malachite check-commit test lint fmt fmt-check help
72 changes: 29 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,42 @@
Prototype for the snapchain proposal

## Prerequisites

Before you begin, ensure you have the following installed:
- Rust (latest stable version)
- Cargo (comes with Rust)
- Protocol Buffers compiler (protoc)

## Installation

1. First clone the malachite repo and checkout the correct commit:
```
- `Rust` (latest stable version) + `Cargo`
- Protocol Buffers compiler (`protoc`)
- `Docker` + `Docker Compose` (for containerized run)
- `malachite` (commit 8a9f3702eb41199bc8a7f45139adba233a04744a)
```bash
git clone [email protected]:informalsystems/malachite.git
cd malachite
git checkout 8a9f3702eb41199bc8a7f45139adba233a04744a # Remember to update GitHub workflow when changing
cd code && cargo build
```
2. Then clone the snapchain repo and build it:
```
cd ..
git clone https://github.com/farcasterxyz/snapchain-v0.git
cd snapchain-v0
cargo build
```

## Testing

After setting up your Rust toolchain above, you can run tests with:

```
cargo test
```

## Running the Application
There are two ways to run the application:

For development, you can run multiple nodes by running:
```
make dev
```

These will be configured to communicate with each other.

To query a node, you can run `grpcurl` from within the container:

```
docker compose exec node1 grpcurl -import-path proto -proto proto/rpc.proto list
```

## Clean up
### 1. Using Docker (recommended)
- For development, you can run multiple nodes by running the below command and they will be configured to communicate with each other
```bash
make dev
```
- To query a node, you can run `grpcurl` from within the container:
```bash
docker compose exec node1 grpcurl -import-path proto -proto proto/rpc.proto list
```

You can remove any cached items by running:
### 2. Local build without Docker
- Setup dependencies and build
```bash
make local-build
```

```
make clean
```
## Other useful commands
- Remove all artifacts and containers
```bash
make clean
```
- For all available commands, run:
```bash
make help
```