-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
noirup
installation script (#418)
* feat: add nargoup script * refactor: rename nargoup to noirup * refactor: correct casing in message to remove cargo install Co-authored-by: guipublic <[email protected]>
- Loading branch information
1 parent
e885d42
commit 10ce7a8
Showing
3 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# `noirup` | ||
|
||
Update or revert to a specific Nargo branch with ease. | ||
|
||
## Installing | ||
|
||
```sh | ||
curl -L https://raw.githubusercontent.com/noir-lang/noir/master/noirup/install | bash | ||
``` | ||
|
||
## Usage | ||
|
||
To install the **nightly** version: | ||
|
||
```sh | ||
noirup | ||
``` | ||
|
||
To install a specific **version** (in this case the `nightly` version): | ||
|
||
```sh | ||
noirup --version nightly | ||
``` | ||
|
||
To install a specific **branch** (in this case the `release/0.1.0` branch's latest commit): | ||
|
||
```sh | ||
noirup --branch release/0.1.0 | ||
``` | ||
|
||
To install a **fork's main branch** (in this case `tomafrench/noir`'s main branch): | ||
|
||
```sh | ||
noirup --repo tomafrench/noir | ||
``` | ||
|
||
To install a **specific branch in a fork** (in this case the `patch-10` branch's latest commit in `tomafrench/noir`): | ||
|
||
```sh | ||
noirup --repo tomafrench/noir --branch patch-10 | ||
``` | ||
|
||
To install from a **specific Pull Request**: | ||
|
||
```sh | ||
noirup --pr 367 | ||
``` | ||
|
||
To install from a **specific commit**: | ||
|
||
```sh | ||
noirup -C 20048e7 | ||
``` | ||
|
||
To install a local directory or repository (e.g. one located at `~/git/noir`, assuming you're in the home directory) | ||
|
||
##### Note: --branch, --repo, and --version flags are ignored during local installations. | ||
|
||
```sh | ||
noirup --path ./git/noir | ||
``` | ||
|
||
--- | ||
|
||
**Tip**: All flags have a single character shorthand equivalent! You can use `-v` instead of `--version`, etc. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo Installing noirup... | ||
|
||
NARGO_DIR=${NARGO_DIR-"$HOME/.nargo"} | ||
NARGO_BIN_DIR="$NARGO_DIR/bin" | ||
|
||
BIN_URL="https://raw.githubusercontent.com/noir-lang/noir/master/noirup/noirup" | ||
BIN_PATH="$NARGO_BIN_DIR/noirup" | ||
|
||
# Create the .nargo bin directory and noirup binary if it doesn't exist. | ||
mkdir -p $NARGO_BIN_DIR | ||
curl -# -L $BIN_URL -o $BIN_PATH | ||
chmod +x $BIN_PATH | ||
|
||
# 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/.bashrc | ||
PREF_SHELL=bash | ||
;; | ||
*/fish) | ||
PROFILE=$HOME/.config/fish/config.fish | ||
PREF_SHELL=fish | ||
;; | ||
*/ash) | ||
PROFILE=$HOME/.profile | ||
PREF_SHELL=ash | ||
;; | ||
*) | ||
echo "noirup: could not detect shell, manually add ${NARGO_BIN_DIR} to your PATH." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Only add noirup if it isn't already in PATH. | ||
if [[ ":$PATH:" != *":${NARGO_BIN_DIR}:"* ]]; then | ||
# Add the noirup directory to the path and ensure the old PATH variables remain. | ||
echo >>$PROFILE && echo "export PATH=\"\$PATH:$NARGO_BIN_DIR\"" >>$PROFILE | ||
fi | ||
|
||
echo && echo "Detected your preferred shell is ${PREF_SHELL} and added noirup to PATH. Run 'source ${PROFILE}' or start a new terminal session to use noirup." | ||
echo "Then, simply run 'noirup' to install Nargo." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
NARGO_DIR=${NARGO_DIR-"$HOME/.nargo"} | ||
NARGO_BIN_DIR="$NARGO_DIR/bin" | ||
|
||
main() { | ||
need_cmd git | ||
need_cmd curl | ||
|
||
while [[ $1 ]]; do | ||
case $1 in | ||
--) shift; break;; | ||
|
||
-r|--repo) shift; NOIRUP_REPO=$1;; | ||
-b|--branch) shift; NOIRUP_BRANCH=$1;; | ||
-v|--version) shift; NOIRUP_VERSION=$1;; | ||
-p|--path) shift; NOIRUP_LOCAL_REPO=$1;; | ||
-P|--pr) shift; NOIRUP_PR=$1;; | ||
-C|--commit) shift; NOIRUP_COMMIT=$1;; | ||
-h|--help) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
err "internal error: unknown option "$1"\n";; | ||
esac; shift | ||
done | ||
|
||
if [ -n "$NOIRUP_PR" ]; then | ||
if [ -z "$NOIRUP_BRANCH" ]; then | ||
NOIRUP_BRANCH="refs/pull/$NOIRUP_PR/head" | ||
else | ||
err "can't use --pr and --branch at the same time" | ||
fi | ||
fi | ||
|
||
# Installs nargo from a local repository if --path parameter is provided | ||
if [[ -n "$NOIRUP_LOCAL_REPO" ]]; then | ||
need_cmd cargo | ||
|
||
# Ignore branches/versions as we do not want to modify local git state | ||
if [ -n "$NOIRUP_REPO" ] || [ -n "$NOIRUP_BRANCH" ] || [ -n "$NOIRUP_VERSION" ]; then | ||
warn "--branch, --version, and --repo arguments are ignored during local install" | ||
fi | ||
|
||
# Enter local repo and build | ||
say "installing from $NOIRUP_LOCAL_REPO" | ||
cd $NOIRUP_LOCAL_REPO | ||
RUSTFLAGS="-C target-cpu=native" ensure cargo build --release # need 4 speed | ||
|
||
# Remove prior installations if they exist | ||
rm -f "$NARGO_BIN_DIR/nargo" | ||
|
||
# Symlink from local repo binaries to bin dir | ||
ensure ln -s "$PWD/target/release/nargo" "$NARGO_BIN_DIR/nargo" | ||
|
||
say "done" | ||
exit 0 | ||
fi | ||
|
||
NOIRUP_REPO=${NOIRUP_REPO-noir-lang/noir} | ||
|
||
# Noir doesn't publish binaries currently so we always build from source. | ||
|
||
# if [[ "$NOIRUP_REPO" == "noir-lang/noir" && -z "$NOIRUP_BRANCH" && -z "$NOIRUP_COMMIT" ]]; then | ||
# NOIRUP_VERSION=${NOIRUP_VERSION-nightly} | ||
# NOIRUP_TAG=$NOIRUP_VERSION | ||
|
||
# # Normalize versions (handle channels, versions without v prefix | ||
# if [[ "$NOIRUP_VERSION" == "nightly" ]]; then | ||
# # Locate real nightly tag | ||
# SHA=$(ensure curl -sSf https://api.github.com/repos/${NOIRUP_REPO}/git/refs/tags/nightly \ | ||
# | grep -Eo '"sha"[^,]*' \ | ||
# | grep -Eo '[^:]*$' \ | ||
# | tr -d '"' \ | ||
# | tr -d ' ') | ||
# NOIRUP_TAG="nightly-${SHA}" | ||
# elif [[ "$NOIRUP_VERSION" == nightly* ]]; then | ||
# NOIRUP_VERSION="nightly" | ||
# elif [[ "$NOIRUP_VERSION" == [[:digit:]]* ]]; then | ||
# # Add v prefix | ||
# NOIRUP_VERSION="v${NOIRUP_VERSION}" | ||
# NOIRUP_TAG="${NOIRUP_VERSION}" | ||
# fi | ||
|
||
# say "installing nargo (version ${NOIRUP_VERSION}, tag ${NOIRUP_TAG})" | ||
|
||
# PLATFORM="$(uname -s)" | ||
# case $PLATFORM in | ||
# Linux) | ||
# PLATFORM="linux" | ||
# ;; | ||
# Darwin) | ||
# PLATFORM="darwin" | ||
# ;; | ||
# *) | ||
# err "unsupported platform: $PLATFORM" | ||
# ;; | ||
# 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" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then | ||
# ARCHITECTURE="arm64" # Arm. | ||
# else | ||
# ARCHITECTURE="amd64" # Amd. | ||
# fi | ||
|
||
# # Compute the URL of the release tarball in the Noir repository. | ||
# RELEASE_URL="https://github.com/${NOIRUP_REPO}/releases/download/${NOIRUP_TAG}/" | ||
# BIN_TARBALL_URL="${RELEASE_URL}nargo-${PLATFORM}_${NOIRUP_VERSION}.tar.gz" | ||
# MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${NOIRUP_VERSION}.tar.gz" | ||
|
||
# # Download the binaries tarball and unpack it into the .foundry bin directory. | ||
# say "downloading latest nargo" | ||
# ensure curl -# -L $BIN_TARBALL_URL | tar -xzC $NARGO_BIN_DIR | ||
|
||
# if [[ $(which nargo) =~ "cargo" ]]; then | ||
# warn "it appears your system has already has forge installed via cargo. you may need to run 'rm $(which nargo)' to allow noirup to take precedence!" | ||
# fi | ||
# else | ||
need_cmd cargo | ||
NOIRUP_BRANCH=${NOIRUP_BRANCH-master} | ||
REPO_PATH="${NARGO_DIR}/${NOIRUP_REPO}" | ||
|
||
if [ ! -d $REPO_PATH ]; then | ||
# Repo path did not exist, grab the author from the repo, make a directory in .nargo, cd to it and clone. | ||
IFS="/" read -ra AUTHOR <<<"$NOIRUP_REPO" | ||
ensure mkdir -p "$NARGO_DIR/$AUTHOR" | ||
cd "$NARGO_DIR/$AUTHOR" | ||
ensure git clone https://github.com/${NOIRUP_REPO} | ||
fi | ||
# force checkout, discarding any local changes | ||
cd $REPO_PATH | ||
ensure git fetch origin ${NOIRUP_BRANCH}:remotes/origin/${NOIRUP_BRANCH} | ||
ensure git checkout origin/${NOIRUP_BRANCH} | ||
# If set, checkout specific commit from branch | ||
if [ ! -z $NOIRUP_COMMIT ]; then | ||
say "installing at commit ${NOIRUP_COMMIT}" | ||
ensure git checkout ${NOIRUP_COMMIT} | ||
fi | ||
# Build the repo and install it locally to the .nargo bin directory. | ||
# --root appends /bin to the directory it is given, so we pass NARGO_DIR. | ||
RUSTFLAGS="-C target-cpu=native" ensure cargo install --path ./crates/nargo --bins --locked --force --root $NARGO_DIR | ||
|
||
if [[ $(which nargo) =~ "cargo" ]]; then | ||
warn "it appears your system has already has nargo installed via cargo. you may need to run 'rm $(which nargo)' to allow noirup to take precedence!" | ||
fi | ||
|
||
say "done" | ||
# fi | ||
} | ||
|
||
usage() { | ||
cat 1>&2 <<EOF | ||
The installer for Nargo. | ||
Update or revert to a specific Nargo version with ease. | ||
USAGE: | ||
noirup <OPTIONS> | ||
OPTIONS: | ||
-h, --help Print help information | ||
-v, --version Install a specific version | ||
-b, --branch Install a specific branch | ||
-P, --pr Install a specific Pull Request | ||
-C, --commit Install a specific commit | ||
-r, --repo Install from a remote GitHub repo (uses default branch if no other options are set) | ||
-p, --path Install a local repository | ||
EOF | ||
} | ||
|
||
say() { | ||
printf 'noirup: %s\n' "$1" | ||
} | ||
|
||
warn() { | ||
say "warning: ${1}" >&2 | ||
} | ||
|
||
err() { | ||
say "$1" >&2 | ||
exit 1 | ||
} | ||
|
||
need_cmd() { | ||
if ! check_cmd "$1"; then | ||
err "need '$1' (command not found)" | ||
fi | ||
} | ||
|
||
check_cmd() { | ||
command -v "$1" >/dev/null 2>&1 | ||
} | ||
|
||
# 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 | ||
} | ||
|
||
main "$@" || exit 1 |