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
…#9073)

## Description

Closes #8530

Closes #7511
#7525 as no longer
useful / relevant

This PR updates the Barretenberg README with more information about the
project, its installation, usage, and development.

It also refactors `bbup` with `commander` to match the rest of the
repository's CLI tooling.

## Changes

### bb readme
- Added a project banner and reorganized the README structure
- Expanded usage instructions for UltraHonk and MegaHonk

### bbup
- Refactored bbup installation script and related files
- Included detailed installation instructions in its README

## Testing

`bbup` won't change much so it is deployed manually on `npm`. You can
try it immediately with:

```bash
curl -L bbup.dev | bash
bbup
```

---------

Co-authored-by: Savio <[email protected]>
  • Loading branch information
signorecello and Savio-Sou authored Oct 10, 2024
1 parent 09c3b28 commit 662b61e
Show file tree
Hide file tree
Showing 22 changed files with 1,734 additions and 435 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.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ terraform.tfstate*

# tmux
tmux-client-*.log
.supermavenignore
1 change: 1 addition & 0 deletions .supermavenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md
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.

4 changes: 4 additions & 0 deletions barretenberg/bbup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
yarn.lock
*.js
.yarn
4 changes: 4 additions & 0 deletions barretenberg/bbup/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
yarn.lock
*.ts
.yarn
54 changes: 54 additions & 0 deletions barretenberg/bbup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.

It assumes you are using [Noir](https://noir-lang.org) as the frontend language.

## Installation

### Dependencies

TODO

### Installation script

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 current installed Noir version (ex. installed with [noirup](https://github.com/noir-lang/noirup)), run:

```bash
bbup
```

Check if the installation was successful:

```bash
bb --version
```

If installation was successful, the command would print the version of `bb` installed.

### Options

You can install any specific version of `bb` with the `-v` flag. Example:

```bash
bbup -v 0.56.0
```

You can also can pass [any Noir version](https://github.com/noir-lang/noir/tags) with the `-nv` flag, or specify `nightly` for the nightly version. Examples:

```bash
bbup # installs the barretenberg version matching your current nargo version
bbup -nv 0.34.0 # installs the barretenberg version compatible with Noir 0.34.0 release
bbup -nv nightly # installs the barretenberg version compatible with Noir nightly release
```
48 changes: 48 additions & 0 deletions barretenberg/bbup/bbup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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();
71 changes: 71 additions & 0 deletions barretenberg/bbup/bbup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env node
import { Command, Option } 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.")
.addOption(
new Option(
"-v, --version <version>",
"The Barretenberg version to install"
).implies({ noirVersion: null })
)
.addOption(
new Option(
"-nv, --noir-version <version>",
"The Noir version to match"
).default("current")
)
.action(async ({ version, noirVersion }) => {
let resolvedBBVersion = "";
if (noirVersion) {
let resolvedNoirVersion = noirVersion;
if (noirVersion === "current") {
spinner.start(`Querying noir version from nargo`);
try {
const output = execSync("nargo --version", { encoding: "utf-8" });
resolvedNoirVersion = output.match(
/nargo version = (\d+\.\d+\.\d+)/
)![1];
spinner.stopAndPersist({
text: `Resolved noir version ${resolvedNoirVersion} 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 ${resolvedNoirVersion}`
);
resolvedBBVersion = await getBbVersionForNoir(
resolvedNoirVersion,
spinner
);
spinner.stopAndPersist({
text: `Resolved to barretenberg version ${resolvedBBVersion}`,
symbol: logSymbols.success,
});
} else if (version) {
resolvedBBVersion = version;
}

spinner.start(`Installing barretenberg`);

await installBB(resolvedBBVersion, 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.7",
"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]"
}
68 changes: 68 additions & 0 deletions barretenberg/bbup/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { execSync } from "child_process";
import logSymbols from "log-symbols";
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, options = {}) {
return execSync(cmd, {
encoding: "utf-8",
stdio: "pipe",
...options,
});
}
export async function installBB(version, spinner) {
let architecture = os.arch();
if (architecture === "arm64") {
architecture = "aarch64";
}
else if (architecture === "x64") {
architecture = "x86_64";
}
let platform = 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(fs.mkdtempSync("bb-"), "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));
fs.rmSync(path.dirname(tempTarPath), { recursive: true });
spinner.stopAndPersist({
text: `Installed barretenberg to ${bbPath}`,
symbol: logSymbols.success,
});
}
Loading

0 comments on commit 662b61e

Please sign in to comment.