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

chore: setup zksync workflow #3

Merged
merged 6 commits into from
Aug 20, 2024
Merged
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
1,030 changes: 0 additions & 1,030 deletions .all-contributorsrc

This file was deleted.

1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Karrq marked this conversation as resolved.
Show resolved Hide resolved

- name: Update
run: |
git config --global user.email "[email protected]"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/projects/**/cache/
/out/
/projects/**/out/

/bin
193 changes: 2 additions & 191 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions book.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[book]
authors = ["Oliver Nordbjerg"]
authors = ["Moonsong-Labs"]
language = "en"
multilingual = false
src = "src"
title = "Foundry Book"
description = "A book on all things Foundry"
title = "foundry-zksync book"
description = "A book on all things foundry-zksync"

[build]
create-missing = false

[preprocessor.external-links]

[output.html]
git-repository-url = "https://github.com/foundry-rs/book"
edit-url-template = "https://github.com/foundry-rs/book/edit/master/{path}"
git-repository-url = "https://github.com/Moonsong-Labs/foundry-zksync-book"
edit-url-template = "https://github.com/Moonsong-Labs/foundry-zksync-book/edit/main/{path}"
default-theme = "ayu"
additional-js = ["src/static/solidity.min.js"]
cname = "book.getfoundry.sh"
cname = "96ba0f25.book-3fk.pages.dev"
Karrq marked this conversation as resolved.
Show resolved Hide resolved
additional-css = ["src/static/custom.css"]

[output.html.fold]
Expand Down
17 changes: 9 additions & 8 deletions scripts/gen_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ set -eo pipefail

source "$(dirname "$0")/common"

source "$SCRIPTS/gen_output/cast.sh"
source "$SCRIPTS/gen_output/chisel.sh"
# source "$SCRIPTS/gen_output/cast.sh"
# source "$SCRIPTS/gen_output/chisel.sh"
source "$SCRIPTS/gen_output/zksync.sh"
source "$SCRIPTS/gen_output/forge.sh"
source "$SCRIPTS/gen_output/help.sh"

need_cmd git
need_cmd mktemp
need_cmd sed

need_cmd forge
need_cmd cast
need_cmd anvil
need_cmd chisel
# download zksync nightlies
download_nightlies
Karrq marked this conversation as resolved.
Show resolved Hide resolved

need_cmd bin/forge
need_cmd bin/cast

gen_help
gen_cast
gen_chisel
gen_forge
gen_cast
3 changes: 3 additions & 0 deletions scripts/gen_output/cast.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -eo pipefail

# use foundry-zksync binary path
export PATH=$PWD/bin:$PATH

gen_cast() {
source "$(dirname "$0")/common"

Expand Down
3 changes: 3 additions & 0 deletions scripts/gen_output/forge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -eo pipefail

# use foundry-zksync binary path
export PATH=$PWD/bin:$PATH

gen_forge() {
need_cmd git
need_cmd forge
Expand Down
5 changes: 4 additions & 1 deletion scripts/gen_output/help.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env bash
set -eo pipefail

# use foundry-zksync binary path
export PATH=$PWD/bin:$PATH

gen_help() {
bins=(forge cast anvil chisel)
bins=(forge cast)
for bin in "${bins[@]}"; do
need_cmd "$bin"
echo "Generating help output ($bin)..."
Expand Down
114 changes: 114 additions & 0 deletions scripts/gen_output/zksync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash
set -eo pipefail

BINS=(forge cast)

download_nightlies() {
uname_s=$(uname -s)
PLATFORM=$(tolower "${FOUNDRYUP_PLATFORM:-$uname_s}")
EXT="tar.gz"
case $PLATFORM in
linux) ;;
darwin | mac*)
PLATFORM="darwin"
;;
mingw* | win*)
EXT="zip"
PLATFORM="win32"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac

uname_m=$(uname -m)
ARCHITECTURE=$(tolower "${FOUNDRYUP_ARCH:-$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" ] || [ "${ARCHITECTURE}" = "aarch64" ]; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi

# Compute the URL of the release tarball in the Foundry repository.
FOUNDRYUP_TAG=nightly
FOUNDRYUP_VERSION=$FOUNDRYUP_TAG
FOUNDRYUP_REPO=matter-labs/foundry-zksync
RELEASE_URL="https://github.com/${FOUNDRYUP_REPO}/releases/download/${FOUNDRYUP_TAG}/"
BIN_ARCHIVE_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.$EXT"
FOUNDRY_BIN_DIR=${FOUNDRY_BIN_DIR:-bin}

mkdir -p "${FOUNDRY_BIN_DIR}"

# Download and extract the binaries archive
say "downloading latest: ${BINS[*]}"
if [ "$PLATFORM" = "win32" ]; then
tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry-zksync.zip"
ensure download "$BIN_ARCHIVE_URL" "$tmp"
ensure unzip "$tmp" -d "$FOUNDRY_BIN_DIR"
rm -f "$tmp"
else
ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_BIN_DIR"
fi

for bin in "${BINS[@]}"; do
bin_path="$FOUNDRY_BIN_DIR/$bin"

# Print installed msg
say "installed - $(ensure "$bin_path" --version)"
done

say "done!"
}

say() {
printf "foundryup-zksync: %s\n" "$1"
}

warn() {
say "warning: ${1}" >&2
}

err() {
say "$1" >&2
exit 1
}

tolower() {
echo "$1" | awk '{print tolower($0)}'
}

# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
}

# Downloads $1 into $2 or stdout
download() {
if [ -n "$2" ]; then
# output into $2
if check_cmd curl; then
curl -#o "$2" -L "$1"
else
wget --show-progress -qO "$2" "$1"
fi
else
# output to stdout
if check_cmd curl; then
curl -#L "$1"
else
wget --show-progress -qO- "$1"
fi
fi
}

check_cmd() {
command -v "$1" &>/dev/null
}
Loading