Skip to content

Commit 662b61e

Browse files
signorecelloSavio-Sou
andauthoredOct 10, 2024··
chore(docs): rewriting bbup script, refactoring bb readme for clarity (#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 <72797635+Savio-Sou@users.noreply.github.com>
1 parent 09c3b28 commit 662b61e

22 files changed

+1734
-435
lines changed
 

‎.github/img/bb_banner.png

354 KB
Loading

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ terraform.tfstate*
3030

3131
# tmux
3232
tmux-client-*.log
33+
.supermavenignore

‎.supermavenignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

‎.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,6 @@
171171
},
172172
"files.trimTrailingWhitespace": true,
173173
"cmake.sourceDirectory": "${workspaceFolder}/barretenberg/cpp",
174-
"typescript.tsserver.maxTsServerMemory": 4096
174+
"typescript.tsserver.maxTsServerMemory": 4096,
175+
"markdown.extension.toc.levels": "2..6"
175176
}

‎avm-transpiler/Dockerfile.dockerignore

-5
This file was deleted.

‎aztec-nargo/Dockerfile.dockerignore

-6
This file was deleted.

‎barretenberg/README.md

+225-118
Large diffs are not rendered by default.

‎barretenberg/bbup/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
yarn.lock
3+
*.js
4+
.yarn

‎barretenberg/bbup/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
yarn.lock
3+
*.ts
4+
.yarn

‎barretenberg/bbup/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# BBup
2+
3+
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.
4+
5+
It assumes you are using [Noir](https://noir-lang.org) as the frontend language.
6+
7+
## Installation
8+
9+
### Dependencies
10+
11+
TODO
12+
13+
### Installation script
14+
15+
BBup is an installer for whatever version of BB you may want. Install BBup with:
16+
17+
```bash
18+
curl -L bbup.dev | bash
19+
```
20+
21+
> [!IMPORTANT]
22+
> *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.
23+
24+
## Usage
25+
26+
To install the Barretenberg version compatible with the current installed Noir version (ex. installed with [noirup](https://github.com/noir-lang/noirup)), run:
27+
28+
```bash
29+
bbup
30+
```
31+
32+
Check if the installation was successful:
33+
34+
```bash
35+
bb --version
36+
```
37+
38+
If installation was successful, the command would print the version of `bb` installed.
39+
40+
### Options
41+
42+
You can install any specific version of `bb` with the `-v` flag. Example:
43+
44+
```bash
45+
bbup -v 0.56.0
46+
```
47+
48+
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:
49+
50+
```bash
51+
bbup # installs the barretenberg version matching your current nargo version
52+
bbup -nv 0.34.0 # installs the barretenberg version compatible with Noir 0.34.0 release
53+
bbup -nv nightly # installs the barretenberg version compatible with Noir nightly release
54+
```

‎barretenberg/bbup/bbup.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
import { Command } from "commander";
3+
const program = new Command();
4+
import { installBB } from "./shell.js";
5+
import ora from "ora";
6+
import logSymbols from "log-symbols";
7+
import { getBbVersionForNoir } from "./versions.js";
8+
import { execSync } from "child_process";
9+
const spinner = ora({ color: "blue", discardStdin: false });
10+
const bbup = program
11+
.command("install", { isDefault: true })
12+
.description("Installs Barretenberg.")
13+
.option("-f, --frontend", "Match the version of a specific frontend language", "noir");
14+
const options = bbup.opts();
15+
if (options.frontend === "noir") {
16+
bbup
17+
.requiredOption("-v, --version <version>", "The Noir version to match", "current")
18+
.action(async ({ version }) => {
19+
let resolvedVersion = version;
20+
if (version === "current") {
21+
spinner.start(`Querying noir version from nargo`);
22+
try {
23+
const output = execSync("nargo --version", { encoding: "utf-8" });
24+
resolvedVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1];
25+
spinner.stopAndPersist({
26+
text: `Resolved noir version ${resolvedVersion} from nargo`,
27+
symbol: logSymbols.success,
28+
});
29+
}
30+
catch (e) {
31+
spinner.stopAndPersist({
32+
text: `Could not get noir version from nargo --version. Please specify a version.`,
33+
symbol: logSymbols.error,
34+
});
35+
process.exit(1);
36+
}
37+
}
38+
spinner.start(`Getting compatible barretenberg version for noir version ${resolvedVersion}`);
39+
const compatibleVersion = await getBbVersionForNoir(resolvedVersion, spinner);
40+
spinner.stopAndPersist({
41+
text: `Resolved to barretenberg version ${compatibleVersion}`,
42+
symbol: logSymbols.success,
43+
});
44+
spinner.start(`Installing barretenberg`);
45+
await installBB(compatibleVersion, spinner);
46+
});
47+
}
48+
bbup.parse();

‎barretenberg/bbup/bbup.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
import { Command, Option } from "commander";
3+
const program = new Command();
4+
import { installBB } from "./shell.js";
5+
import ora from "ora";
6+
import logSymbols from "log-symbols";
7+
import { getBbVersionForNoir } from "./versions.js";
8+
import { execSync } from "child_process";
9+
10+
const spinner = ora({ color: "blue", discardStdin: false });
11+
12+
const bbup = program
13+
.command("install", { isDefault: true })
14+
.description("Installs Barretenberg.")
15+
.addOption(
16+
new Option(
17+
"-v, --version <version>",
18+
"The Barretenberg version to install"
19+
).implies({ noirVersion: null })
20+
)
21+
.addOption(
22+
new Option(
23+
"-nv, --noir-version <version>",
24+
"The Noir version to match"
25+
).default("current")
26+
)
27+
.action(async ({ version, noirVersion }) => {
28+
let resolvedBBVersion = "";
29+
if (noirVersion) {
30+
let resolvedNoirVersion = noirVersion;
31+
if (noirVersion === "current") {
32+
spinner.start(`Querying noir version from nargo`);
33+
try {
34+
const output = execSync("nargo --version", { encoding: "utf-8" });
35+
resolvedNoirVersion = output.match(
36+
/nargo version = (\d+\.\d+\.\d+)/
37+
)![1];
38+
spinner.stopAndPersist({
39+
text: `Resolved noir version ${resolvedNoirVersion} from nargo`,
40+
symbol: logSymbols.success,
41+
});
42+
} catch (e) {
43+
spinner.stopAndPersist({
44+
text: `Could not get noir version from nargo --version. Please specify a version.`,
45+
symbol: logSymbols.error,
46+
});
47+
process.exit(1);
48+
}
49+
}
50+
51+
spinner.start(
52+
`Getting compatible barretenberg version for noir version ${resolvedNoirVersion}`
53+
);
54+
resolvedBBVersion = await getBbVersionForNoir(
55+
resolvedNoirVersion,
56+
spinner
57+
);
58+
spinner.stopAndPersist({
59+
text: `Resolved to barretenberg version ${resolvedBBVersion}`,
60+
symbol: logSymbols.success,
61+
});
62+
} else if (version) {
63+
resolvedBBVersion = version;
64+
}
65+
66+
spinner.start(`Installing barretenberg`);
67+
68+
await installBB(resolvedBBVersion, spinner);
69+
});
70+
71+
bbup.parse();

‎barretenberg/bbup/install

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Function to check if a command exists
6+
command_exists() {
7+
command -v "$1" >/dev/null 2>&1
8+
}
9+
10+
# Function to install NVM and Node.js
11+
install_nvm_and_node() {
12+
echo "Installing NVM..."
13+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
14+
15+
# Load NVM
16+
export NVM_DIR="$HOME/.nvm"
17+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
18+
19+
# Install the latest LTS version of Node.js
20+
echo "Installing the latest LTS version of Node.js..."
21+
nvm install --lts
22+
23+
# Use the installed version
24+
nvm use --lts
25+
26+
# Verify installation
27+
node --version
28+
npm --version
29+
}
30+
31+
# Check if NPM is installed
32+
if ! command_exists npm; then
33+
install_nvm_and_node
34+
fi
35+
36+
37+
# Install bbup globally
38+
echo "Installing bbup..."
39+
npm install -g bbup
40+
41+
echo "Installation complete. You can now use the 'bbup' command."
42+
echo "Please restart your terminal or run 'source ~/.bashrc' (or your shell's equivalent) to start using bbup."

‎barretenberg/bbup/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "bbup",
3+
"type": "module",
4+
"description": "Barretenberg installation script",
5+
"bin": "bbup.js",
6+
"version": "0.0.7",
7+
"license": "ISC",
8+
"scripts": {
9+
"start": "npx tsx bbup.ts",
10+
"compile": "tsc bbup.ts --esModuleInterop true --module nodenext && chmod +x bbup.js",
11+
"publish": "yarn compile && yarn npm publish --access public"
12+
},
13+
"dependencies": {
14+
"@inquirer/input": "^1.2.16",
15+
"@inquirer/select": "^1.3.3",
16+
"axios": "^1.7.7",
17+
"commander": "^11.1.0",
18+
"log-symbols": "^7.0.0",
19+
"ora": "^8.1.0",
20+
"tar-fs": "^3.0.6",
21+
"tiged": "^2.12.6"
22+
},
23+
"packageManager": "yarn@4.5.0"
24+
}

‎barretenberg/bbup/shell.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { execSync } from "child_process";
2+
import logSymbols from "log-symbols";
3+
import os from "os";
4+
import axios from "axios";
5+
import fs from "fs";
6+
import { createGunzip } from "zlib";
7+
import tar from "tar-fs";
8+
import { promisify } from "util";
9+
import { pipeline } from "stream";
10+
import path from "path";
11+
export function sourceShellConfig() {
12+
const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim();
13+
if (shell.includes("bash")) {
14+
process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim();
15+
}
16+
else if (shell.includes("zsh")) {
17+
process.env.PATH = execSync('zsh -c "echo $PATH"', {
18+
encoding: "utf-8",
19+
}).trim();
20+
}
21+
else if (shell.includes("fish")) {
22+
process.env.PATH = execSync('fish -c "echo $PATH"', {
23+
encoding: "utf-8",
24+
}).trim();
25+
}
26+
}
27+
export function exec(cmd, options = {}) {
28+
return execSync(cmd, {
29+
encoding: "utf-8",
30+
stdio: "pipe",
31+
...options,
32+
});
33+
}
34+
export async function installBB(version, spinner) {
35+
let architecture = os.arch();
36+
if (architecture === "arm64") {
37+
architecture = "aarch64";
38+
}
39+
else if (architecture === "x64") {
40+
architecture = "x86_64";
41+
}
42+
let platform = os.platform();
43+
if (platform === "darwin") {
44+
platform = "apple-darwin";
45+
}
46+
else if (platform === "linux") {
47+
platform = "linux-gnu";
48+
}
49+
const home = os.homedir();
50+
const bbPath = path.join(home, ".bb");
51+
spinner.start(`Installing to ${bbPath}`);
52+
const tempTarPath = path.join(fs.mkdtempSync("bb-"), "temp.tar.gz");
53+
if (!["x86_64", "aarch64"].includes(architecture) ||
54+
!["linux-gnu", "apple-darwin"].includes(platform)) {
55+
throw new Error(`Unsupported architecture ${architecture} and platform ${platform}`);
56+
}
57+
const releaseUrl = `https://github.com/AztecProtocol/aztec-packages/releases/download/aztec-packages-v${version}`;
58+
const binaryUrl = `${releaseUrl}/barretenberg-${architecture}-${platform}.tar.gz`;
59+
const response = await axios.get(binaryUrl, { responseType: "stream" });
60+
const pipelineAsync = promisify(pipeline);
61+
await pipelineAsync(response.data, fs.createWriteStream(tempTarPath));
62+
await pipelineAsync(fs.createReadStream(tempTarPath), createGunzip(), tar.extract(bbPath));
63+
fs.rmSync(path.dirname(tempTarPath), { recursive: true });
64+
spinner.stopAndPersist({
65+
text: `Installed barretenberg to ${bbPath}`,
66+
symbol: logSymbols.success,
67+
});
68+
}

0 commit comments

Comments
 (0)
Please sign in to comment.