Skip to content

Commit

Permalink
Merge pull request #9 from itsdevbear/bump
Browse files Browse the repository at this point in the history
feat(makefile): add a `Makefile` to help create `bindings` crate.
  • Loading branch information
mattsse authored Nov 28, 2023
2 parents f5673ff + 8fb8b3d commit 645c092
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 551 deletions.
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 --skip-cargo-toml
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"] }
2 changes: 2 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
src = 'src'
out = 'out'
libs = ['lib']
solidity_version = '0.8.22'
evm_version = 'shanghai'

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
3 changes: 2 additions & 1 deletion bindings/Cargo.toml → crates/bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "bindings"
version = "0.0.1"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ethers = { version = "2", default-features = false, features = ["abigen"] }
serde = "1"
Loading

0 comments on commit 645c092

Please sign in to comment.