Skip to content

Commit

Permalink
feat: forgeup (gakonst#475)
Browse files Browse the repository at this point in the history
* feat(forgeup): first draft

* feat(forgeup): support cloning

* feat(forgeup): wip

* feat(forgeup): install script

* feat(forgeup): move binaries into cargo bin

* fix(forgeup): stale vars

* fix(forgeup): args & env vars

* fix(forgeup): remove -i

* docs(forgeup): cleanup comments

* docs(forgeup): more comments

* docs(forgeup): cleanup comments

* docs(forgeup): cleanup comments

* fix(forgeup): fix sysctl throw

Co-authored-by: Bjerg <[email protected]>

* refactor(forgeup): cleanup & comments

* docs(forgeup): install instructions

* docs(forgeup): readme

* docs(forgeup): cleanup language

* docs(forgeup): update wording

Co-authored-by: Bjerg <[email protected]>
  • Loading branch information
transmissions11 and onbjerg authored Jan 17, 2022
1 parent 2451c4a commit 0e0e908
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 13 deletions.
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ Foundry consists of:

![demo](./assets/demo.svg)

## Forge
## Installation

```
cargo install --git https://github.com/gakonst/foundry --bin forge --locked
curl https://raw.githubusercontent.com/gakonst/foundry/master/forgeup/install | bash && forgeup
```

If you are on a x86/x86_64 Unix machine, you can also use `--features=solc-asm`
to enable Sha2 Assembly instructions, which further speedup the compilation pipeline cache.
Just get forgeup, the Foundry toolchain installer, and use it to install the latest `forge` and `cast` binaries.

Advanced ways to use `forgeup` and other documentation can be found in the [forgeup package](./forgeup/README.md). Happy forging!

We also recommend using [forgeup](https://github.com/transmissions11/forgeup)
for managing various versions of Forge, so that you can easily test out bleeding edge changes in open pull requests or
forks from contributors.
## Forge

More documentation can be found in the [forge package](./forge/README.md) and in the [CLI README](./cli/README.md).

Expand Down Expand Up @@ -76,12 +75,6 @@ whereas Forge took 9.449 (~4s cached)

Cast is a swiss army knife for interacting with Ethereum applications from the command line.

```shell
cargo install --git https://github.com/gakonst/foundry --bin cast
// Get USDC's total supply
cast call 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 "totalSupply()(uint256)" --rpc-url <..your node url>
```
More documentation can be found in the [cast package](./cast/README.md).

## Setup
Expand Down
47 changes: 47 additions & 0 deletions forgeup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# `forgeup`

Update or revert to a specific Foundry branch with ease.

## Installing

```sh
curl https://raw.githubusercontent.com/gakonst/foundry/master/forgeup/install | bash
```

## Usage

To install the **nightly** version:

```sh
forgeup
```

To install a specific **version** (in this case the `nightly` version):

```sh
forgeup --version nightly
```

To install a specific **branch** (in this case the `release/0.1.0` branch's latest commit):

```sh
forgeup --branch release/0.1.0
```

To install a **fork's main branch** (in this case `transmissions11/foundry`'s main branch):

```sh
forgeup --repo transmissions11/foundry
```

To install a **specific branch in a fork** (in this case the `patch-10` branch's latest commit in `transmissions11/foundry`):

```sh
forgeup --repo transmissions11/foundry --branch patch-10
```

---

**Tip**: All flags have a single character shorthand equivalent! You can use `-v` instead of `--version`, etc.

---
122 changes: 122 additions & 0 deletions forgeup/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash
set -e

echo Installing forgeup...

FORGEUP_DIR=${FORGEUP_DIR-"$HOME/.forgeup"}

FORGEUP='#!/usr/bin/env bash
set -e
FORGEUP_DIR=${FORGEUP_DIR-"$HOME/.forgeup"}
while [[ $1 ]]; do
case $1 in
--) shift; break;;
-r|--repo) shift; FORGEUP_REPO=$1;;
-b|--branch) shift; FORGEUP_BRANCH=$1;;
-v|--version) shift; FORGEUP_VERSION=$1;;
*) printf "forgeup: internal error: %q\\n" "$1"; exit 1
esac; shift
done
FORGEUP_REPO=${FORGEUP_REPO-gakonst/foundry}
if [[ "$FORGEUP_REPO" == "gakonst/foundry" && -z "$FORGEUP_BRANCH" ]]; then
FORGEUP_VERSION=${FORGEUP_VERSION-nightly}
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
echo "forgeup: unsupported platform: $PLATFORM"
exit 1
;;
esac
ARCHITECTURE="$(uname -m)"
if [ "${ARCHITECTURE}" = "x86_64" ]; then
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCHITECTURE="arm64" # Rosetta.
else
ARCHITECTURE="amd64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ]; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi
# Download the release tarball from the repository, unpack it and move the forge and cast binaries into the cargo bin directory.
# Will replace the existing binaries if they were installed via cargo, can be undone at any time by running cargo install again, if desired.
curl -L https://github.com/${FORGEUP_REPO}/releases/download/${FORGEUP_VERSION}/foundry_${FORGEUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.tar.gz | tar xvz
mv forge $HOME/.cargo/bin/forge
mv cast $HOME/.cargo/bin/cast
else
FORGEUP_BRANCH=${FORGEUP_BRANCH-master}
if ! command -v cargo &> /dev/null ; then
# Error if cargo is not already installed.
echo "forgeup: cargo is not installed. Please install it first."
exit 1
fi
REPO_PATH="${FORGEUP_DIR}/${FORGEUP_REPO}"
if [ -d $REPO_PATH ]; then
# If the repo path exists move to it, git pull, and checkout the branch and cargo install local.
cd $REPO_PATH
git pull
git checkout ${FORGEUP_BRANCH}
git pull
cargo install --path ./cli --bins --locked --force
else
# Repo path did not exist, grab the author from the repo, make a directory in .forgeup, cd to it, clone and install.
IFS="/" read -ra AUTHOR <<< "$FORGEUP_REPO"
mkdir -p "$FORGEUP_DIR/$AUTHOR"
cd "$FORGEUP_DIR/$AUTHOR"
git clone https://github.com/${FORGEUP_REPO}
cd $REPO_PATH
git checkout ${FORGEUP_BRANCH}
cargo install --path ./cli --bins --locked --force
fi
fi'

BINARY="$FORGEUP_DIR/forgeup"

# Create the forgeup directory and binary file if it doesn't exist.
mkdir -p $FORGEUP_DIR
echo "$FORGEUP" > $BINARY
chmod +x $BINARY

# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH).
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
PREF_SHELL=zsh
;;
*/bash)
PROFILE=$HOME/.profile
PREF_SHELL=bash
;;
*)
echo "forgeup: could not detect shell, manually add ${FORGEUP_DIR} to your PATH."
exit 1
esac

# Only add forgeup if it isn't already in PATH.
if [[ ":$PATH:" != *":${FORGEUP_DIR}:"* ]]; then
# Add the forgeup directory to the path and ensure the old PATH variables remain.
echo >> $PROFILE && echo "export PATH=\"\$PATH:$FORGEUP_DIR\"" >> $PROFILE
fi

echo && echo "Detected your preferred shell is ${PREF_SHELL} and added forgeup to PATH. Run run source after this script runs, or start a new terminal session to use forgeup."

0 comments on commit 0e0e908

Please sign in to comment.