From b3224bf4fc5cf2b5cae246d3d9df2df87ec27f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Wed, 20 Nov 2024 19:34:53 +0700 Subject: [PATCH 1/3] making bbup add bb to path --- barretenberg/bbup/.gitignore | 1 + barretenberg/bbup/package.json | 1 + barretenberg/bbup/shell.ts | 22 +++++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/barretenberg/bbup/.gitignore b/barretenberg/bbup/.gitignore index 96f4d2d1d9f2..21114ccaaac3 100644 --- a/barretenberg/bbup/.gitignore +++ b/barretenberg/bbup/.gitignore @@ -2,3 +2,4 @@ node_modules yarn.lock *.js .yarn +bun.lockb diff --git a/barretenberg/bbup/package.json b/barretenberg/bbup/package.json index 935b3b06e1c6..ea2e52919c59 100644 --- a/barretenberg/bbup/package.json +++ b/barretenberg/bbup/package.json @@ -13,6 +13,7 @@ "dependencies": { "@inquirer/input": "^1.2.16", "@inquirer/select": "^1.3.3", + "@types/node": "^22.9.1", "axios": "^1.7.7", "commander": "^11.1.0", "log-symbols": "^7.0.0", diff --git a/barretenberg/bbup/shell.ts b/barretenberg/bbup/shell.ts index 5ab408778c73..a5da51a9d8c7 100644 --- a/barretenberg/bbup/shell.ts +++ b/barretenberg/bbup/shell.ts @@ -11,20 +11,27 @@ import { promisify } from "util"; import { pipeline } from "stream"; import path from "path"; +import { appendFileSync } from "fs"; + export function sourceShellConfig() { const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim(); + const home = os.homedir(); + const bbBinPath = path.join(home, ".bb", "bb"); + const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`; if (shell.includes("bash")) { - process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim(); + const bashrcPath = path.join(home, ".bashrc"); + appendFileSync(bashrcPath, pathEntry); } else if (shell.includes("zsh")) { - process.env.PATH = execSync('zsh -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + const zshrcPath = path.join(home, ".zshrc"); + appendFileSync(zshrcPath, pathEntry); } else if (shell.includes("fish")) { - process.env.PATH = execSync('fish -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + const fishConfigPath = path.join(home, ".config", "fish", "config.fish"); + appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`); } + + // Update the current session's PATH + process.env.PATH = `${bbBinPath}:${process.env.PATH}`; } export function exec(cmd: string, options = {}) { @@ -82,4 +89,5 @@ export async function installBB(version: string, spinner: Ora) { text: `Installed barretenberg to ${bbPath}`, symbol: logSymbols.success, }); + sourceShellConfig(); } From 09675b710cbdd4bf6a73a75b9b12dfb89a047902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Wed, 20 Nov 2024 19:57:17 +0700 Subject: [PATCH 2/3] adding bb to all shells --- barretenberg/bbup/bbup.js | 38 ++++++++++++++++++---------------- barretenberg/bbup/package.json | 2 +- barretenberg/bbup/shell.js | 27 ++++++++++++++---------- barretenberg/bbup/shell.ts | 13 ++++++------ barretenberg/bbup/versions.js | 14 +++++++------ 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/barretenberg/bbup/bbup.js b/barretenberg/bbup/bbup.js index 13eb873dc20e..6b6fac09db8f 100755 --- a/barretenberg/bbup/bbup.js +++ b/barretenberg/bbup/bbup.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { Command } from "commander"; +import { Command, Option } from "commander"; const program = new Command(); import { installBB } from "./shell.js"; import ora from "ora"; @@ -10,20 +10,19 @@ 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 ", "The Noir version to match", "current") - .action(async ({ version }) => { - let resolvedVersion = version; - if (version === "current") { + .addOption(new Option("-v, --version ", "The Barretenberg version to install").implies({ noirVersion: null })) + .addOption(new Option("-nv, --noir-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" }); - resolvedVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1]; + resolvedNoirVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1]; spinner.stopAndPersist({ - text: `Resolved noir version ${resolvedVersion} from nargo`, + text: `Resolved noir version ${resolvedNoirVersion} from nargo`, symbol: logSymbols.success, }); } @@ -35,14 +34,17 @@ if (options.frontend === "noir") { process.exit(1); } } - spinner.start(`Getting compatible barretenberg version for noir version ${resolvedVersion}`); - const compatibleVersion = await getBbVersionForNoir(resolvedVersion, spinner); + spinner.start(`Getting compatible barretenberg version for noir version ${resolvedNoirVersion}`); + resolvedBBVersion = await getBbVersionForNoir(resolvedNoirVersion, spinner); spinner.stopAndPersist({ - text: `Resolved to barretenberg version ${compatibleVersion}`, + text: `Resolved to barretenberg version ${resolvedBBVersion}`, symbol: logSymbols.success, }); - spinner.start(`Installing barretenberg`); - await installBB(compatibleVersion, spinner); - }); -} + } + else if (version) { + resolvedBBVersion = version; + } + spinner.start(`Installing barretenberg`); + await installBB(resolvedBBVersion, spinner); +}); bbup.parse(); diff --git a/barretenberg/bbup/package.json b/barretenberg/bbup/package.json index ea2e52919c59..7283db443e5d 100644 --- a/barretenberg/bbup/package.json +++ b/barretenberg/bbup/package.json @@ -3,7 +3,7 @@ "type": "module", "description": "Barretenberg installation script", "bin": "bbup.js", - "version": "0.0.7", + "version": "0.0.12", "license": "ISC", "scripts": { "start": "npx tsx bbup.ts", diff --git a/barretenberg/bbup/shell.js b/barretenberg/bbup/shell.js index 512c2ddb9cf1..b8fd1418cb9d 100644 --- a/barretenberg/bbup/shell.js +++ b/barretenberg/bbup/shell.js @@ -8,21 +8,25 @@ import tar from "tar-fs"; import { promisify } from "util"; import { pipeline } from "stream"; import path from "path"; +import { appendFileSync, existsSync } from "fs"; 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(); + const home = os.homedir(); + const bbBinPath = path.join(home, ".bb"); + const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`; + if (existsSync(path.join(home, ".bashrc"))) { + const bashrcPath = path.join(home, ".bashrc"); + appendFileSync(bashrcPath, pathEntry); } - else if (shell.includes("zsh")) { - process.env.PATH = execSync('zsh -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + if (existsSync(path.join(home, ".zshrc"))) { + const zshrcPath = path.join(home, ".zshrc"); + appendFileSync(zshrcPath, pathEntry); } - else if (shell.includes("fish")) { - process.env.PATH = execSync('fish -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + if (existsSync(path.join(home, ".config", "fish", "config.fish"))) { + const fishConfigPath = path.join(home, ".config", "fish", "config.fish"); + appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`); } + // Update the current session's PATH + process.env.PATH = `${bbBinPath}:${process.env.PATH}`; } export function exec(cmd, options = {}) { return execSync(cmd, { @@ -65,4 +69,5 @@ export async function installBB(version, spinner) { text: `Installed barretenberg to ${bbPath}`, symbol: logSymbols.success, }); + sourceShellConfig(); } diff --git a/barretenberg/bbup/shell.ts b/barretenberg/bbup/shell.ts index a5da51a9d8c7..c2e8a6945f3a 100644 --- a/barretenberg/bbup/shell.ts +++ b/barretenberg/bbup/shell.ts @@ -11,21 +11,22 @@ import { promisify } from "util"; import { pipeline } from "stream"; import path from "path"; -import { appendFileSync } from "fs"; +import { appendFileSync, existsSync } from "fs"; export function sourceShellConfig() { - const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim(); const home = os.homedir(); - const bbBinPath = path.join(home, ".bb", "bb"); + const bbBinPath = path.join(home, ".bb"); const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`; - if (shell.includes("bash")) { + if (existsSync(path.join(home, ".bashrc"))) { const bashrcPath = path.join(home, ".bashrc"); appendFileSync(bashrcPath, pathEntry); - } else if (shell.includes("zsh")) { + } + if (existsSync(path.join(home, ".zshrc"))) { const zshrcPath = path.join(home, ".zshrc"); appendFileSync(zshrcPath, pathEntry); - } else if (shell.includes("fish")) { + } + if (existsSync(path.join(home, ".config", "fish", "config.fish"))) { const fishConfigPath = path.join(home, ".config", "fish", "config.fish"); appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`); } diff --git a/barretenberg/bbup/versions.js b/barretenberg/bbup/versions.js index 795107f3f134..5f6dee81f7f0 100644 --- a/barretenberg/bbup/versions.js +++ b/barretenberg/bbup/versions.js @@ -1,5 +1,5 @@ -import axios from 'axios'; -import logSymbols from 'log-symbols'; +import axios from "axios"; +import logSymbols from "log-symbols"; async function getNamedVersions(githubToken) { const fetchOpts = { // eslint-disable-next-line camelcase @@ -9,16 +9,18 @@ async function getNamedVersions(githubToken) { 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) => !release.tag_name.includes('aztec') && !release.tag_name.includes('nightly') && !release.prerelease)[0].tag_name; - const nightly = data.filter((release) => release.tag_name.startsWith('nightly'))[0].tag_name; + const stable = data.filter((release) => !release.tag_name.includes("aztec") && + !release.tag_name.includes("nightly") && + !release.prerelease)[0].tag_name; + const nightly = data.filter((release) => release.tag_name.startsWith("nightly"))[0].tag_name; return { stable, nightly, }; } export async function getBbVersionForNoir(noirVersion, spinner, githubToken) { - let url = ''; - if (noirVersion === 'stable' || noirVersion === 'nightly') { + let url = ""; + if (noirVersion === "stable" || noirVersion === "nightly") { spinner.start(`Resolving noir version ${noirVersion}...`); const resolvedVersions = await getNamedVersions(githubToken); spinner.stopAndPersist({ From 4b351fd6ea201d1c6afa8b5af6778c8c1f0d5c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Tue, 26 Nov 2024 13:27:47 +0000 Subject: [PATCH 3/3] fix: fixing bb lookup for noir 1.0 beta versions --- barretenberg/bbup/bbup.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/bbup/bbup.ts b/barretenberg/bbup/bbup.ts index d885715a0dcb..98608ae50399 100755 --- a/barretenberg/bbup/bbup.ts +++ b/barretenberg/bbup/bbup.ts @@ -33,8 +33,9 @@ const bbup = program try { const output = execSync("nargo --version", { encoding: "utf-8" }); resolvedNoirVersion = output.match( - /nargo version = (\d+\.\d+\.\d+)/ + /nargo version = (\d+\.\d+\.\d+(-\w+\.\d+)?)/ )![1]; + console.log(resolvedNoirVersion); spinner.stopAndPersist({ text: `Resolved noir version ${resolvedNoirVersion} from nargo`, symbol: logSymbols.success,