Skip to content

Commit

Permalink
chore(docs): rewriting bbup script, refactoring bb readme for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Oct 8, 2024
1 parent 97e4b9b commit 9c9de83
Show file tree
Hide file tree
Showing 18 changed files with 535 additions and 436 deletions.
Binary file added .github/img/bb_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ terraform.tfstate*
.bb_tmp

# Terraform
*.tfvars
*.tfvars
.supermavenignore
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,6 @@
},
"files.trimTrailingWhitespace": true,
"cmake.sourceDirectory": "${workspaceFolder}/barretenberg/cpp",
"typescript.tsserver.maxTsServerMemory": 4096
"typescript.tsserver.maxTsServerMemory": 4096,
"markdown.extension.toc.levels": "2..6"
}
5 changes: 0 additions & 5 deletions avm-transpiler/Dockerfile.dockerignore

This file was deleted.

6 changes: 0 additions & 6 deletions aztec-nargo/Dockerfile.dockerignore

This file was deleted.

343 changes: 225 additions & 118 deletions barretenberg/README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions barretenberg/bbup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn.lock
*.js
3 changes: 3 additions & 0 deletions barretenberg/bbup/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn.lock
*.ts
Binary file added barretenberg/bbup/.yarn/install-state.gz
Binary file not shown.
33 changes: 33 additions & 0 deletions barretenberg/bbup/README.md
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
```
66 changes: 66 additions & 0 deletions barretenberg/bbup/bbup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/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";
import { execSync } from "child_process";

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",
"current"
)
.action(async ({ version }) => {
let resolvedVersion = version;
if (version === "current") {
spinner.start(`Querying noir version from nargo`);
try {
const output = execSync("nargo --version", { encoding: "utf-8" });
resolvedVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)![1];
spinner.stopAndPersist({
text: `Resolved noir version ${resolvedVersion} from nargo`,
symbol: logSymbols.success,
});
} catch (e) {
spinner.stopAndPersist({
text: `Could not get noir version from nargo --version. Please specify a version.`,
symbol: logSymbols.error,
});
process.exit(1);
}
}

spinner.start(
`Getting compatible barretenberg version for noir version ${resolvedVersion}`
);
const compatibleVersion = await getBbVersionForNoir(
resolvedVersion,
spinner
);
spinner.stopAndPersist({
text: `Resolved to barretenberg version ${compatibleVersion}`,
symbol: logSymbols.success,
});
spinner.start(`Installing barretenberg`);
await installBB(compatibleVersion, spinner);
});
}

bbup.parse();
42 changes: 42 additions & 0 deletions barretenberg/bbup/install
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."
24 changes: 24 additions & 0 deletions barretenberg/bbup/package.json
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.5",
"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": "[email protected]"
}
83 changes: 83 additions & 0 deletions barretenberg/bbup/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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";
} else if (architecture === "x64") {
architecture = "x86_64";
}

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 (
!["x86_64", "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,
});
}
52 changes: 52 additions & 0 deletions barretenberg/bbup/versions.ts
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);
}
}
Loading

0 comments on commit 9c9de83

Please sign in to comment.