-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): rewriting bbup script, refactoring bb readme for clarity
- Loading branch information
1 parent
97e4b9b
commit 374b846
Showing
16 changed files
with
501 additions
and
424 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
|
@@ -26,4 +26,5 @@ terraform.tfstate* | |
.bb_tmp | ||
|
||
# Terraform | ||
*.tfvars | ||
*.tfvars | ||
.supermavenignore |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
node_modules | ||
yarn.lock | ||
*.js |
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,3 @@ | ||
node_modules | ||
yarn.lock | ||
*.ts |
Binary file not shown.
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,33 @@ | ||
# BBup | ||
|
||
BBup is a CLI tool that makes it easy to install the [Barretenberg](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/README.md) proving backend. | ||
|
||
Although extensible, it assumes you are using [Noir](https://noir-lang.org) as the frontend language. | ||
|
||
## Installation | ||
|
||
BBup is an installer for whatever version of BB you may want. Install BBup with: | ||
|
||
```bash | ||
curl -L bbup.dev | bash | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> *Always* check what scripts do. The above one redirects to [the install script](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/bbup/install) which checks if you have `npm`, installing it with `nvm` otherwise. It then installs [bbup](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/bbup/bbup.ts) globally. | ||
## Usage | ||
|
||
To install the Barretenberg version compatible with the stable Noir version, run: | ||
|
||
```bash | ||
bbup | ||
``` | ||
|
||
You can specify the `-f` flag to match a different frontend language. At the moment only Noir is available, so `-f noir` is defaulted. | ||
|
||
You can pass [any Noir version](https://github.com/noir-lang/noir/tags) with the `-v` flag, or specify `nightly` for the nightly version. Examples: | ||
|
||
```bash | ||
bbup -v 0.34.0 # installs the barretenberg version compatible with Noir 0.34.0 release | ||
bbup -v nightly # installs the barretenberg version compatible with Noir nightly release | ||
``` |
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,44 @@ | ||
#!/usr/bin/env node | ||
import { Command } from "commander"; | ||
const program = new Command(); | ||
import { installBB } from "./shell.js"; | ||
import ora from "ora"; | ||
import logSymbols from "log-symbols"; | ||
import { getBbVersionForNoir } from "./versions.js"; | ||
|
||
const spinner = ora({ color: "blue", discardStdin: false }); | ||
|
||
const bbup = program | ||
.command("install", { isDefault: true }) | ||
.description("Installs Barretenberg.") | ||
.option( | ||
"-f, --frontend", | ||
"Match the version of a specific frontend language", | ||
"noir" | ||
); | ||
|
||
const options = bbup.opts(); | ||
|
||
if (options.frontend === "noir") { | ||
bbup | ||
.requiredOption( | ||
"-v, --version <version>", | ||
"The Noir version to match", | ||
"stable" | ||
) | ||
.action(async ({ version }) => { | ||
spinner.stopAndPersist({ | ||
text: `Getting compatible barretenberg version for noir version ${version}...`, | ||
symbol: logSymbols.info, | ||
}); | ||
const compatibleVersion = await getBbVersionForNoir(version, spinner); | ||
spinner.stopAndPersist({ | ||
text: `Resolved to barretenberg version ${compatibleVersion}`, | ||
symbol: logSymbols.success, | ||
}); | ||
spinner.start(`Installing barretenberg`); | ||
await installBB(compatibleVersion, spinner); | ||
}); | ||
} | ||
|
||
bbup.parse(); |
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,42 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Function to check if a command exists | ||
command_exists() { | ||
command -v "$1" >/dev/null 2>&1 | ||
} | ||
|
||
# Function to install NVM and Node.js | ||
install_nvm_and_node() { | ||
echo "Installing NVM..." | ||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash | ||
|
||
# Load NVM | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
|
||
# Install the latest LTS version of Node.js | ||
echo "Installing the latest LTS version of Node.js..." | ||
nvm install --lts | ||
|
||
# Use the installed version | ||
nvm use --lts | ||
|
||
# Verify installation | ||
node --version | ||
npm --version | ||
} | ||
|
||
# Check if NPM is installed | ||
if ! command_exists npm; then | ||
install_nvm_and_node | ||
fi | ||
|
||
|
||
# Install bbup globally | ||
echo "Installing bbup..." | ||
npm install -g bbup | ||
|
||
echo "Installation complete. You can now use the 'bbup' command." | ||
echo "Please restart your terminal or run 'source ~/.bashrc' (or your shell's equivalent) to start using bbup." |
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,24 @@ | ||
{ | ||
"name": "bbup", | ||
"type": "module", | ||
"description": "Barretenberg installation script", | ||
"bin": "bbup.js", | ||
"version": "0.0.2", | ||
"license": "ISC", | ||
"scripts": { | ||
"start": "npx tsx bbup.ts", | ||
"compile": "tsc bbup.ts --esModuleInterop true --module nodenext && chmod +x bbup.js", | ||
"publish": "yarn compile && yarn npm publish --access public" | ||
}, | ||
"dependencies": { | ||
"@inquirer/input": "^1.2.16", | ||
"@inquirer/select": "^1.3.3", | ||
"axios": "^1.7.7", | ||
"commander": "^11.1.0", | ||
"log-symbols": "^7.0.0", | ||
"ora": "^8.1.0", | ||
"tar-fs": "^3.0.6", | ||
"tiged": "^2.12.6" | ||
}, | ||
"packageManager": "yarn@4.5.0" | ||
} |
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,63 @@ | ||
import { execSync } from 'child_process'; | ||
import logSymbols from 'log-symbols'; | ||
import { Ora } from 'ora'; | ||
import os from 'os'; | ||
import axios from 'axios'; | ||
import fs from 'fs'; | ||
import { createGunzip } from 'zlib'; | ||
import tar from 'tar-fs'; | ||
import { promisify } from 'util'; | ||
|
||
import { pipeline } from 'stream'; | ||
import path from 'path'; | ||
|
||
export function sourceShellConfig() { | ||
const shell = execSync('echo $SHELL', { encoding: 'utf-8' }).trim(); | ||
|
||
if (shell.includes('bash')) { | ||
process.env.PATH = execSync('echo $PATH', { encoding: 'utf-8' }).trim(); | ||
} else if (shell.includes('zsh')) { | ||
process.env.PATH = execSync('zsh -c "echo $PATH"', { encoding: 'utf-8' }).trim(); | ||
} else if (shell.includes('fish')) { | ||
process.env.PATH = execSync('fish -c "echo $PATH"', { encoding: 'utf-8' }).trim(); | ||
} | ||
} | ||
|
||
export function exec(cmd: string, options = {}) { | ||
return execSync(cmd, { | ||
encoding: 'utf-8', | ||
stdio: 'pipe', | ||
...options, | ||
}); | ||
} | ||
export async function installBB(version: string, spinner: Ora) { | ||
let architecture = os.arch(); | ||
if (architecture === 'arm64') architecture = 'aarch64'; | ||
|
||
let platform: string = os.platform(); | ||
if (platform === 'darwin') { | ||
platform = 'apple-darwin'; | ||
} else if (platform === 'linux') { | ||
platform = 'linux-gnu'; | ||
} | ||
|
||
const home = os.homedir(); | ||
const bbPath = path.join(home, '.bb'); | ||
|
||
spinner.start(`Installing to ${bbPath}`); | ||
const tempTarPath = path.join(home, 'temp.tar.gz'); | ||
|
||
if (!['x64', 'aarch64'].includes(architecture) || !['linux-gnu', 'apple-darwin'].includes(platform)) { | ||
throw new Error(`Unsupported architecture ${architecture} and platform ${platform}`); | ||
} | ||
|
||
const releaseUrl = `https://github.com/AztecProtocol/aztec-packages/releases/download/aztec-packages-v${version}`; | ||
const binaryUrl = `${releaseUrl}/barretenberg-${architecture}-${platform}.tar.gz`; | ||
|
||
const response = await axios.get(binaryUrl, { responseType: 'stream' }); | ||
|
||
const pipelineAsync = promisify(pipeline); | ||
await pipelineAsync(response.data, fs.createWriteStream(tempTarPath)); | ||
await pipelineAsync(fs.createReadStream(tempTarPath), createGunzip(), tar.extract(bbPath)); | ||
spinner.stopAndPersist({ text: `Installed barretenberg to ${bbPath}`, symbol: logSymbols.success }); | ||
} |
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,52 @@ | ||
import axios from 'axios'; | ||
import logSymbols from 'log-symbols'; | ||
import { Ora } from 'ora'; | ||
|
||
async function getNamedVersions(githubToken?: string) { | ||
const fetchOpts = { | ||
// eslint-disable-next-line camelcase | ||
params: { per_page: 100 }, | ||
headers: {}, | ||
}; | ||
|
||
if (githubToken) fetchOpts.headers = { Authorization: `token ${githubToken}` }; | ||
|
||
const { data } = await axios.get(`https://api.github.com/repos/noir-lang/noir/releases`, fetchOpts); | ||
|
||
const stable = data.filter( | ||
(release: any) => | ||
!release.tag_name.includes('aztec') && !release.tag_name.includes('nightly') && !release.prerelease, | ||
)[0].tag_name; | ||
const nightly = data.filter((release: any) => release.tag_name.startsWith('nightly'))[0].tag_name; | ||
|
||
return { | ||
stable, | ||
nightly, | ||
}; | ||
} | ||
|
||
export async function getBbVersionForNoir(noirVersion: string, spinner: Ora, githubToken?: string) { | ||
let url = ''; | ||
|
||
if (noirVersion === 'stable' || noirVersion === 'nightly') { | ||
spinner.start(`Resolving noir version ${noirVersion}...`); | ||
const resolvedVersions = await getNamedVersions(githubToken); | ||
spinner.stopAndPersist({ | ||
text: `Resolved noir version ${noirVersion} to ${resolvedVersions[noirVersion]}`, | ||
symbol: logSymbols.success, | ||
}); | ||
url = `https://raw.githubusercontent.com/noir-lang/noir/${resolvedVersions[noirVersion]}/scripts/install_bb.sh`; | ||
} else { | ||
url = `https://raw.githubusercontent.com/noir-lang/noir/v${noirVersion}/scripts/install_bb.sh`; | ||
} | ||
|
||
try { | ||
const { data } = await axios.get(url); | ||
const versionMatch = data.match(/VERSION="([\d.]+)"/); | ||
const version = versionMatch ? versionMatch[1] : null; | ||
|
||
return version; | ||
} catch (e: any) { | ||
throw new Error(e.message || e); | ||
} | ||
} |
Oops, something went wrong.