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(makefile): add a Makefile to help create bindings crate. #9

Merged
merged 9 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
run: forge build --sizes

- name: Check bindings are correct
run: forge bind --bindings-path ./bindings --root ./contracts --crate-name bindings
run: forge bind --bindings-path ./crates/bindings --root ./contracts --crate-name bindings
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[workspace]
members = [
"bindings",
"app",
"crates/bindings",
]

[workspace.dependencies]
bindings = { path = "crates/bindings" }
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/make -f

# Default target is build
default: build

# Define variables
CARGO=cargo
CRATES_FOLDER=crates
CONTRACTS_PATH=./contracts
BINDINGS_FOLDER=bindings
BINDINGS_CRATES_FOLDER=$(CRATES_FOLDER)/$(BINDINGS_FOLDER)
BINDINGS_OUT_PATH=$(CONTRACTS_PATH)/out/$(BINDINGS_FOLDER)

# Target for generating bindings
bindings:
rm -rf $(BINDINGS_CRATES_FOLDER)
rm -rf $(BINDINGS_OUT_PATH)

# Generate new bindings
@forge bind --root $(CONTRACTS_PATH) --crate-name $(BINDINGS_FOLDER)

# Move bindings to the correct location
@mv -f $(BINDINGS_OUT_PATH) $(CRATES_FOLDER)

# Target for building the project
build: bindings
@$(CARGO) build

# Target for building the project in release mode
build-release: bindings
@$(CARGO) build --release

# Target for cleaning the project
clean:
@forge clean --root $(CONTRACTS_PATH)
@$(CARGO) clean

# Target for formatting the code
fmt:
@forge fmt --check --root $(CONTRACTS_PATH)
@$(CARGO) fmt

# Target for running tests
test:
@forge test --root $(CONTRACTS_PATH)
@$(CARGO) test

# Target for installing forge dependencies
setup:
@forge install


# Declare phony targets
.PHONY: build build-release clean fmt bindings
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ Solidity build artifacts.

The project is structured as a mixed Rust workspace with a Foundry project under
`contracts/` and typesafe auto-generated bindings to the contracts under
`bindings/`.
`crates/bindings/`.

```
├── Cargo.toml
├── app // <-- Your Rust application logic
├── contracts // <- The smart contracts + tests using Foundry
├── bindings // <-- Generated bindings to the smart contracts' abis (like Typechain)
├── crates
└── bindings // <-- Generated bindings to the smart contracts' abis (like Typechain)
```

## Testing
Expand Down
4 changes: 2 additions & 2 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bindings = { path = "../bindings" }
bindings = { workspace = true }
ethers = { version = "2", default-features = false, features = ["rustls"] }
eyre = "0.6"
tokio = { version = "1.19", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1.19", features = ["macros", "rt-multi-thread"] }
Loading
Loading