-
Notifications
You must be signed in to change notification settings - Fork 293
[TKN-683] Add setup.sh script for local Whirlpools build
#1074
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # ============================================================================= | ||
| # DEPENDENCY VERSIONS | ||
| # ============================================================================= | ||
| NVM_VERSION="v0.40.3" | ||
| NODE_VERSION="22" | ||
| YARN_VERSION="4.6.0" | ||
| SOLANA_VERSION="v1.17.25" | ||
| ANCHOR_VERSION="v0.29.0" | ||
| RUST_VERSION_FOR_ANCHOR="1.76.0" # Required for building Anchor v0.29.0 | ||
| RUST_VERSION_FOR_PROJECT="1.85.1" # Required for building Whirlpools project | ||
|
|
||
| # Resolve repo root from this script's directory | ||
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" | ||
| REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)" | ||
| echo "=== Repo root: $REPO_ROOT ===" | ||
|
|
||
| echo "=== Detecting system ===" | ||
| UNAME_OUT="$(uname -s)" | ||
| case "${UNAME_OUT}" in | ||
| Linux*) OS=Linux;; | ||
| Darwin*) OS=Mac;; | ||
| *) OS="UNKNOWN:${UNAME_OUT}" | ||
| esac | ||
| echo "Detected: $OS" | ||
|
|
||
| if [[ "$OS" == "Linux" ]]; then | ||
| echo "=== Updating system packages (Linux) ===" | ||
| sudo apt-get update && sudo apt-get upgrade -y | ||
| sudo apt-get install -y build-essential pkg-config libssl-dev curl git | ||
| elif [[ "$OS" == "Mac" ]]; then | ||
| echo "=== Installing Xcode Command Line Tools ===" | ||
| xcode-select --install || true | ||
|
|
||
| echo "=== Installing Homebrew and dependencies ===" | ||
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || true | ||
| eval "$(/opt/homebrew/bin/brew shellenv)" 2>/dev/null || eval "$(/usr/local/bin/brew shellenv)" 2>/dev/null || true | ||
| brew update | ||
| brew upgrade | ||
| brew install pkg-config openssl git | ||
| fi | ||
|
|
||
| echo "=== Installing NVM (Node Version Manager) ===" | ||
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh | bash | ||
| export NVM_DIR="$HOME/.nvm" | ||
| source "$NVM_DIR/nvm.sh" | ||
|
|
||
| echo "=== Installing Node.js ${NODE_VERSION} and Yarn (via Corepack) ===" | ||
| nvm install ${NODE_VERSION} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally hate nvm 🦗. I always just do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script runs on both Linux and Mac. Would you recommend installing Brew for Linux as well? I went with |
||
| nvm use ${NODE_VERSION} | ||
| corepack enable | ||
| corepack prepare yarn@${YARN_VERSION} --activate | ||
|
|
||
| echo "=== Installing Rust via rustup ===" | ||
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
| source "$HOME/.cargo/env" | ||
| rustc -V | ||
|
|
||
| echo "=== Installing Solana CLI ===" | ||
| sh -c "$(curl -sSfL https://release.anza.xyz/${SOLANA_VERSION}/install)" | ||
| source "$HOME/.profile" || true | ||
| solana -V | ||
|
|
||
| echo "=== Installing Anchor (${ANCHOR_VERSION}) ===" | ||
| rustup default ${RUST_VERSION_FOR_ANCHOR} | ||
| ANCHOR_TMP_DIR="$(mktemp -d)" | ||
| git clone https://github.com/coral-xyz/anchor "$ANCHOR_TMP_DIR/anchor" | ||
| cd "$ANCHOR_TMP_DIR/anchor" | ||
| git checkout ${ANCHOR_VERSION} | ||
| cd cli | ||
| cargo build --release | ||
|
||
| mkdir -p "$HOME/.cargo/bin" | ||
| cp ../target/release/anchor "$HOME/.cargo/bin/anchor-${ANCHOR_VERSION}" | ||
| ln -sfn "$HOME/.cargo/bin/anchor-${ANCHOR_VERSION}" "$HOME/.cargo/bin/anchor" | ||
| export PATH="$HOME/.cargo/bin:$PATH" | ||
| cd "$REPO_ROOT" | ||
| rm -rf "$ANCHOR_TMP_DIR" | ||
|
|
||
| echo "=== Building local Whirlpools repo ===" | ||
| rustup default ${RUST_VERSION_FOR_PROJECT} | ||
| cd "$REPO_ROOT" | ||
| yarn install | ||
| yarn build | ||
|
|
||
| echo "=== Setup complete ===" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use 1.78.0 ?
yarn buildshould build everything. It uses1.78.0 for contract build. (no need to switch default, we can use Rust 1.85.1 as default because package.json has the following setting)https://github.com/orca-so/whirlpools/blob/main/programs/whirlpool/package.json#L5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Rust version in this line is specific to the installation of Anchor v0.29.0, and not the Whirlpools repo.
Background
I encountered an issue with using AVM to install v0.29.0.
Using Anchor's recommendation for installing Anchor:
yields:
So I decided to install Anchor
v0.29.0from source, but that would not compile with the latest version of Rust that comes with the default Rust installation,v1.90.0. Neither did it compile withv1.85.1. I tried multiple versions of Rust, and landed onv1.76as a compatible version.Testing your suggestions
That said, as a result of you review comment, I just tried
v1.78as well, and that works too. So, I believe we still need to switch the default right before building Anchor.Furthermore, I tested the script without switching the default from
v1.78.0tov1.85.1before tryingyarn installandyarn buildfrom the repo's root, and indeed the Whirlpool program builds, but buildingrust-tx-senderwill fail with Error:I'm happy to switch to another version of Rust instead of 1.85.1, but I believe we still need to switch the default at least twice.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up
@wjthieme 's suggestion to use
cargo install --git https://github.com/coral-xyz/anchor --tag v0.29.0 anchor-cliinstead of my code works without switching the Rust version. So the only thing left to do was to addrustup default ${RUST_VERSION_FOR_PROJECT}right before building the project, with the version beingv1.84.0, which is the same version that's used by the GitHub workflows.(The default
v1.90.0seems to not be compatible with WASM compilation)