Skip to content

Commit

Permalink
feat: introduce mise (ethereum-optimism#13156)
Browse files Browse the repository at this point in the history
Introduces mise for polyglot tool dependency management.
  • Loading branch information
smartcontracts authored Dec 2, 2024
1 parent a2b1a7e commit 3f43f03
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 512 deletions.
73 changes: 32 additions & 41 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,54 @@ Interactions within this repository are subject to a [Code of Conduct](https://g

## Development Quick Start

### Software Dependencies

| Dependency | Version | Version Check Command |
| ------------------------------------------------------------- | -------- | ------------------------ |
| [git](https://git-scm.com/) | `^2` | `git --version` |
| [go](https://go.dev/) | `^1.21` | `go version` |
| [node](https://nodejs.org/en/) | `^20` | `node --version` |
| [nvm](https://github.com/nvm-sh/nvm) | `^0.39` | `nvm --version` |
| [just](https://github.com/casey/just) | `^1.34.0`| `just --version` |
| [foundry](https://github.com/foundry-rs/foundry#installation) | `^0.2.0` | `forge --version` |
| [make](https://linux.die.net/man/1/make) | `^3` | `make --version` |
| [jq](https://github.com/jqlang/jq) | `^1.6` | `jq --version` |
| [direnv](https://direnv.net) | `^2` | `direnv --version` |
| [docker](https://docs.docker.com/get-docker/) | `^24` | `docker --version` |
| [docker compose](https://docs.docker.com/compose/install/) | `^2.23` | `docker compose version` |
### Setting Up

### Notes on Specific Dependencies
Clone the repository and open it:

#### `node`
```bash
git clone [email protected]:ethereum-optimism/optimism.git
cd optimism
```

Make sure to use the version of `node` specified within [`.nvmrc`](./.nvmrc).
You can use [`nvm`](https://github.com/nvm-sh/nvm) to manage multiple versions of Node.js on your machine and automatically switch to the correct version when you enter this repository.
### Software Dependencies

#### `foundry`
You will need to install a number of software dependencies to effectively contribute to the
Optimism Monorepo. We use [`mise`](https://mise.jdx.dev/) as a dependency manager for these tools.
Once properly installed, `mise` will provide the correct versions for each tool. `mise` does not
replace any other installations of these binaries and will only serve these binaries when you are
working inside of the `optimism` directory.

`foundry` is updated frequently and occasionally contains breaking changes.
This repository pins a specific version of `foundry` inside of [`versions.json`](./versions.json).
Use the command `just update-foundry` at the root of the monorepo to make sure that your version of `foundry` is the same as the one currently being used in CI.
#### Install `mise`

#### `direnv`
Install `mise` by following the instructions provided on the
[Getting Started page](https://mise.jdx.dev/getting-started.html#_1-install-mise-cli).

[`direnv`](https://direnv.net) is a tool used to load environment variables from [`.envrc`](./.envrc) into your shell so you don't have to manually export variables every time you want to use them.
`direnv` only has access to files that you explicitly allow it to see.
After [installing `direnv`](https://direnv.net/docs/installation.html), you will need to **make sure that [`direnv` is hooked into your shell](https://direnv.net/docs/hook.html)**.
Make sure you've followed [the guide on the `direnv` website](https://direnv.net/docs/hook.html), then **close your terminal and reopen it** so that the changes take effect (or `source` your config file if you know how to do that).
#### Trust the `mise.toml` file

#### `docker compose`
`mise` requires that you explicitly trust the `mise.toml` file which lists the dependencies that
this repository uses. After you've installed `mise` you'll be able to trust the file via:

[Docker Desktop](https://docs.docker.com/get-docker/) should come with `docker compose` installed by default.
You'll have to install the `compose` plugin if you're not using Docker Desktop or you're on linux.
```bash
mise trust mise.toml
```

### Setting Up
#### Install dependencies

Clone the repository and open it:
Use `mise` to install the correct versions for all of the required tools:

```bash
git clone [email protected]:ethereum-optimism/optimism.git
cd optimism
mise install
```

### Building the Monorepo
#### Installing updates

Make sure that you've installed all of the required [Software Dependencies](#software-dependencies) before you continue.
You will need [foundry](https://github.com/foundry-rs/foundry) to build the smart contracts found within this repository.
Refer to the note on [foundry as a dependency](#foundry) for instructions.
`mise` will notify you if any dependencies are outdated. Simply run `mise install` again to install
the latest versions of the dependencies if you receive these notifications.

### Building the Monorepo

Install dependencies and build all packages within the monorepo by running:
You must install all of the required [Software Dependencies](#software-dependencies) to build the
Optimism Monorepo. Once you've done so, run the following command to build:

```bash
make build
Expand All @@ -88,7 +79,7 @@ Use the above command to rebuild the monorepo.

### Running tests

Before running tests: **follow the above instructions to get everything built.**
Before running tests: **follow the above instructions to get everything built**.

#### Running unit tests (solidity)

Expand Down
88 changes: 0 additions & 88 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,91 +13,3 @@ semgrep-test:
# Runs shellcheck.
shellcheck:
find . -type f -name '*.sh' -not -path '*/node_modules/*' -not -path './packages/contracts-bedrock/lib/*' -not -path './packages/contracts-bedrock/kout*/*' -exec sh -c 'echo "Checking $1"; shellcheck "$1"' _ {} \;

########################################################
# DEPENDENCY MANAGEMENT #
########################################################

# Generic task for checking if a tool version is up to date.
check-tool-version tool:
#!/usr/bin/env bash
EXPECTED=$(jq -r .{{tool}} < versions.json)
ACTUAL=$(just print-{{tool}})
if [ "$ACTUAL" = "$EXPECTED" ]; then
echo "✓ {{tool}} versions match"
else
echo "✗ {{tool}} version mismatch (expected $EXPECTED, got $ACTUAL), run 'just install-{{tool}}' to upgrade"
exit 1
fi
# Installs foundry
install-foundry:
bash ./ops/scripts/install-foundry.sh

# Prints current foundry version.
print-foundry:
forge --version

# Checks if installed foundry version is correct.
check-foundry:
bash ./ops/scripts/check-foundry.sh

# Installs correct kontrol version.
install-kontrol:
bash ./ops/scripts/install-kontrol.sh

# Prints current kontrol version.
print-kontrol:
kontrol version

# Checks if installed kontrol version is correct.
check-kontrol:
just check-tool-version kontrol

# Installs correct abigen version.
install-abigen:
go install github.com/ethereum/go-ethereum/cmd/abigen@$(jq -r .abigen < versions.json)

# Prints current abigen version.
print-abigen:
abigen --version | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' -e 's/ /./g' -e 's/^/v/'

# Checks if installed abigen version is correct.
check-abigen:
just check-tool-version abigen

# Installs correct slither version.
install-slither:
pip3 install slither-analyzer==$(jq -r .slither < versions.json)

# Prints current slither version.
print-slither:
slither --version

# Checks if installed slither version is correct.
check-slither:
just check-tool-version slither

# Installs correct semgrep version.
install-semgrep:
pip3 install semgrep=="$(jq -r .semgrep < versions.json)"

# Prints current semgrep version.
print-semgrep:
semgrep --version | head -n 1

# Checks if installed semgrep version is correct.
check-semgrep:
just check-tool-version semgrep

# Installs correct go version.
install-go:
echo "error: go must be installed manually" && exit 1

# Prints current go version.
print-go:
go version | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/'

# Checks if installed go version is correct.
check-go:
just check-tool-version go
52 changes: 52 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[tools]

# Core dependencies
go = "1.22.7"
rust = "1.83.0"
python = "3.12.0"
uv = "0.5.5"
jq = "1.7.1"
shellcheck = "0.10.0"
direnv = "2.35.0"

# Cargo dependencies
"cargo:just" = "1.37.0"
"cargo:svm-rs" = "0.5.8"

# Go dependencies
"go:github.com/ethereum/go-ethereum/cmd/abigen" = "1.10.25"
"go:github.com/ethereum/go-ethereum/cmd/geth" = "1.14.7"
"go:github.com/protolambda/eth2-testnet-genesis" = "0.10.0"
"go:gotest.tools/gotestsum" = "1.12.0"
"go:github.com/vektra/mockery/v2" = "2.46.0"
"go:github.com/golangci/golangci-lint/cmd/golangci-lint" = "1.61.0"
"go:github.com/mikefarah/yq/v4" = "4.44.3"

# Python dependencies
"pipx:slither-analyzer" = "0.10.2"
"pipx:semgrep" = "1.90.0"

# Foundry dependencies
# Foundry is a special case because it supplies multiple binaries at the same
# GitHub release, so we need to use the aliasing trick to get mise to not error
forge = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"
cast = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"
anvil = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"

# Fake dependencies
# Put things here if you need to track versions of tools or projects that can't
# actually be managed by mise (yet). Make sure that anything you put in here is
# also found inside of disabled_tools or mise will try to install it.
asterisc = "1.1.1"
kontrol = "1.0.53"
binary_signer = "1.0.4"

[alias]
forge = "ubi:foundry-rs/foundry[exe=forge]"
cast = "ubi:foundry-rs/foundry[exe=cast]"
anvil = "ubi:foundry-rs/foundry[exe=anvil]"

[settings]
experimental = true
pipx.uvx = true
disable_tools = ["asterisc", "kontrol", "binary_signer"]
Loading

0 comments on commit 3f43f03

Please sign in to comment.