Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ avm-transpiler-cross: avm-transpiler-cross-amd64-macos avm-transpiler-cross-arm6
#==============================================================================

# Barretenberg - Aggregate target for all barretenberg sub-projects.
barretenberg: bb-cpp bb-ts bb-avm-sim bb-rs bb-acir bb-docs bb-sol bb-bbup bb-crs
barretenberg: bb-cpp bb-ts bb-avm-sim bb-cdb bb-rs bb-acir bb-docs bb-sol bb-bbup bb-crs

# BB C++ - Main aggregate target.
bb-cpp: bb-cpp-native bb-cpp-wasm bb-cpp-wasm-threads
Expand Down Expand Up @@ -277,6 +277,12 @@ bb-avm-sim: ipc-codegen ipc-runtime bb-cpp-native
bb-avm-sim-cross-copy: bb-avm-sim bb-cpp-cross
$(call build,$@,barretenberg/ts,cross_copy_bb_avm_sim)

# Generated @aztec/cdb server bindings. Ordered after bb-avm-sim rather than run
# alongside it: both regenerate the same barretenberg/ts workspaces and install
# into the same node_modules.
bb-cdb: ipc-codegen ipc-runtime bb-avm-sim
$(call build,$@,barretenberg/ts,build_cdb)

# BB Rust - barretenberg-rs FFI crate
bb-rs: bb-ts bb-cpp-native
$(call build,$@,barretenberg/rust)
Expand Down Expand Up @@ -518,7 +524,7 @@ yarn-project: noir-projects-labs labs-aztec-toolchain
# If we still in the monorepo, we need to additionally depend on everything else explicitly.
# In the labs repo, we will consume them differently.
# TODO(fcarreiro): comment this out when pinning binaries.
yarn-project: bb-ts l1-contracts wsdb bb-avm-sim constants-codegen noir-projects-fnd
yarn-project: bb-ts l1-contracts wsdb bb-avm-sim bb-cdb constants-codegen noir-projects-fnd

yarn-project-tests: yarn-project
$(call test,$@,yarn-project/end-to-end)
Expand Down
1 change: 1 addition & 0 deletions barretenberg/ts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bb.js/build
bb.js/.tsbuildinfo*
bb.js/*.tsbuildinfo
bb-avm-sim/
cdb/
.tsbuildinfo*
*.tsbuildinfo
*.log
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/bb.js/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hash=$(hash_str \
${AVM_TRANSPILER:-1})

function prepare_project {
(cd .. && ./bootstrap.sh generate_bb_avm_sim_package)
(cd .. && ./bootstrap.sh generate_packages)
(cd .. && npm_install_deps)
}

Expand Down
51 changes: 46 additions & 5 deletions barretenberg/ts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source $(git rev-parse --show-toplevel)/ci3/source_bootstrap
ROOT=$(git rev-parse --show-toplevel)
BB_AVM_SIM_BINARY=bb-avm-sim
BB_AVM_SIM_PACKAGE=@aztec/bb-avm-sim
CDB_PACKAGE=@aztec/cdb

hash=$(hash_str \
$(bb.js/bootstrap.sh hash) \
Expand All @@ -29,6 +30,27 @@ function generate_bb_avm_sim_package {
--package-ipc-path-args 'msgpack,run,--input,{path}'
}

# Server binding package for the AVM CDB protocol: generated wire types +
# Handler/dispatch + the schema itself. Pure TS — no binary, no arch packages.
function generate_cdb_package {
node --experimental-strip-types --experimental-transform-types --no-warnings \
"$ROOT/ipc-codegen/src/generate.ts" \
--schema "$ROOT/barretenberg/cpp/src/barretenberg/cdb/cdb_schema.json" \
--lang ts \
--server \
--out "$ROOT/barretenberg/ts/cdb/src/generated" \
--package "$ROOT/barretenberg/ts/cdb" \
--package-name "$CDB_PACKAGE"
}

# Both bb-avm-sim and cdb are gitignored workspaces declared in package.json, so
# `yarn install --immutable` fails against the committed lockfile unless both exist.
# Generate them together before installing, whichever one we're about to build.
function generate_packages {
generate_bb_avm_sim_package
generate_cdb_package
}

function copy_bb_avm_sim_native {
local target_dir="bb-avm-sim/build/$(arch)-$(os)"
mkdir -p "$target_dir"
Expand Down Expand Up @@ -62,16 +84,24 @@ function build_bb_js {

function build_bb_avm_sim {
echo_header "bb-avm-sim package build"
generate_bb_avm_sim_package
generate_packages
copy_bb_avm_sim_native
npm_install_deps
yarn workspace "$BB_AVM_SIM_PACKAGE" build
prepare_bb_avm_sim_arch_packages "$(arch)-$(os)=build/$(arch)-$(os)/$BB_AVM_SIM_BINARY"
}

function build_cdb {
echo_header "cdb package build"
generate_packages
npm_install_deps
yarn workspace "$CDB_PACKAGE" build
}

function build {
build_bb_js
build_bb_avm_sim
build_cdb
}

function test_cmds {
Expand All @@ -91,7 +121,7 @@ function cross_copy_bb_js {
}

function cross_copy_bb_avm_sim {
generate_bb_avm_sim_package
generate_packages
copy_bb_avm_sim_cross "$@"
npm_install_deps
yarn workspace "$BB_AVM_SIM_PACKAGE" build
Expand All @@ -110,10 +140,13 @@ function get_projects {
done
echo "$PWD/bb-avm-sim"
fi
if [ -d cdb ]; then
echo "$PWD/cdb"
fi
}

function release_bb_avm_sim {
generate_bb_avm_sim_package
generate_packages
copy_bb_avm_sim_native
copy_bb_avm_sim_cross
npm_install_deps
Expand All @@ -125,13 +158,21 @@ function release_bb_avm_sim {
(cd bb-avm-sim && retry "deploy_npm ${REF_NAME#v}")
}

function release_cdb {
generate_packages
npm_install_deps
yarn workspace "$CDB_PACKAGE" build
(cd cdb && retry "deploy_npm ${REF_NAME#v}")
}

function release {
(cd bb.js && ./bootstrap.sh release)
release_bb_avm_sim
release_cdb
}

export -f generate_bb_avm_sim_package copy_bb_avm_sim_native copy_bb_avm_sim_cross
export -f build_bb_js build_bb_avm_sim build cross_copy_bb_js cross_copy_bb_avm_sim release
export -f generate_bb_avm_sim_package copy_bb_avm_sim_native copy_bb_avm_sim_cross generate_cdb_package generate_packages
export -f build_bb_js build_bb_avm_sim build_cdb build cross_copy_bb_js cross_copy_bb_avm_sim release release_cdb

case "$cmd" in
"")
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"workspaces": [
"bb.js",
"bb-avm-sim",
"bb-avm-sim/packages/*"
"bb-avm-sim/packages/*",
"cdb"
],
"resolutions": {
"@aztec/ipc-runtime": "portal:../../ipc-runtime/ts"
Expand Down
11 changes: 11 additions & 0 deletions barretenberg/ts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ __metadata:
languageName: unknown
linkType: soft

"@aztec/cdb@workspace:cdb":
version: 0.0.0-use.local
resolution: "@aztec/cdb@workspace:cdb"
dependencies:
"@types/node": "npm:^22.15.17"
msgpackr: "npm:^1.11.2"
tslib: "npm:^2.4.0"
typescript: "npm:^5.3.3"
languageName: unknown
linkType: soft

"@aztec/ipc-runtime@portal:../../ipc-runtime/ts::locator=%40aztec%2Fbarretenberg-ts-packages%40workspace%3A.":
version: 0.0.0-use.local
resolution: "@aztec/ipc-runtime@portal:../../ipc-runtime/ts::locator=%40aztec%2Fbarretenberg-ts-packages%40workspace%3A."
Expand Down
12 changes: 6 additions & 6 deletions ipc-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ node --experimental-strip-types --experimental-transform-types --no-warnings \
|---|---|
| `--server` | Emit server dispatch (matches request name to handler, deserialises, calls handler, serialises response). Pair it with an `ipc::IpcServer` from ipc-runtime. |
| `--client` | Emit a typed client class/struct with one method per command. Pair it with an `ipc::IpcClient` (C++) or the equivalent Rust/Zig/TS binding. |
| `--package <dir>` | TS only. Emit a complete package wrapper around the generated async client. The wrapper launches a native service binary, connects over UDS or SHM, and resolves the binary from an override path, environment variable, installed arch package, or local `build/<platform>/` directory. |
| `--package <dir>` | TS only. Emit a complete package shell. Which of the two shells you get depends on the role flags. With `--client` (or with neither role flag): a wrapper around the generated async client that launches a native service binary, connects over UDS or SHM, and resolves the binary from an override path, environment variable, installed arch package, or local `build/<platform>/` directory. With `--server` and no `--client`: a pure-TS server binding package instead, holding wire types, the `Handler` interface and `handleRequest`/`dispatch`, plus the schema file at the package root, with no binary launcher and no arch packages. The byte transport is then supplied by the consumer, e.g. `UdsIpcServer` from ipc-runtime. Passing `--server --client` selects the client shell. |
| `--uds` | Rust/Zig only. Copies the `Backend` trait template (and `error.rs` for Rust) into `<out>` so consumers can plug ipc-runtime — or any custom transport — behind the generated client. The flag name is historical: the trait is transport-agnostic. |
| `--ffi` | Rust/Zig only. Adds the `ffi_backend` template (a thin wrapper exposing the generated client over a C ABI for embedding in other languages). |

Expand Down Expand Up @@ -131,11 +131,11 @@ flags below are only for legacy positional schemas, which have no `service`.
|---|---|
| `--curve-constants` | TS only. Also emit `curve_constants.ts` with bn254/grumpkin/secp moduli & generators for schemas that need curve constants. |
| `--skeleton <dir>` | One-shot scaffolding: writes a `<service>_handlers.{ts,rs,zig,cpp}` stub, `main`, and a build file into `<dir>` if they don't already exist. Skipped on subsequent runs. |
| `--package-name <name>` | TS package mode only. Package name to write into the generated wrapper `package.json`. |
| `--binary-name <name>` | TS package mode only. Native service binary name to launch. |
| `--binary-env-var <name>` | TS package mode only. Environment variable that can override the binary path. Defaults to `<BINARY_NAME>_PATH`. |
| `--package-transports <uds,shm>` | TS package mode only. Comma-separated transports supported by the generated wrapper. |
| `--ipc-runtime-dependency <spec>` | TS package mode only. Dependency spec for `@aztec/ipc-runtime`, e.g. a release version or local `file:` dependency in examples. |
| `--package-name <name>` | TS package mode only. Package name to write into the generated `package.json`. |
| `--binary-name <name>` | Client package shell only; ignored by the server shell. Native service binary name to launch. |
| `--binary-env-var <name>` | Client package shell only; ignored by the server shell. Environment variable that can override the binary path. Defaults to `<BINARY_NAME>_PATH`. |
| `--package-transports <uds,shm>` | Client package shell only; ignored by the server shell. Comma-separated transports supported by the generated wrapper. |
| `--ipc-runtime-dependency <spec>` | Client package shell only; ignored by the server shell. Dependency spec for `@aztec/ipc-runtime`, e.g. a release version or local `file:` dependency in examples. |

## Worked examples

Expand Down
93 changes: 58 additions & 35 deletions ipc-codegen/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
rmSync,
} from "fs";
import { execSync } from "child_process";
import { dirname, join, resolve } from "path";
import { basename, dirname, join, resolve } from "path";
import { fileURLToPath } from "url";
import {
SchemaVisitor,
Expand All @@ -38,6 +38,7 @@ import { TypeScriptCodegen } from "./typescript_codegen.ts";
import {
defaultBinaryEnvVar,
TypeScriptPackageCodegen,
TypeScriptServerPackageCodegen,
} from "./typescript_package_codegen.ts";
import { RustCodegen } from "./rust_codegen.ts";
import { ZigCodegen } from "./zig_codegen.ts";
Expand Down Expand Up @@ -85,7 +86,10 @@ Required:
Optional:
--server Generate server dispatch
--client Generate client
--package <dir> Generate a TS package shell around a spawned IPC service (ts only)
--package <dir> Generate a TS package shell around a spawned IPC service (ts only).
With --server and no --client, generates a server binding
package instead: wire types + Handler/dispatch + the schema
file, no binary or arch packages
--package-name <name> TS package name for --package
--binary-name <name> Native service binary name for --package
--binary-env-var <name> Env var overriding the binary path for --package
Expand Down Expand Up @@ -357,6 +361,9 @@ function generate(args: Args) {

switch (args.lang) {
case "ts": {
// --package with --server (and no --client) means a server binding
// package: no spawned binary, so no client APIs or arch packages.
const serverPackage = !!args.packageDir && args.server && !args.client;
const gen = new TypeScriptCodegen({
stripMethodPrefix: stripMethodPrefix ? prefix : undefined,
});
Expand All @@ -366,7 +373,7 @@ function generate(args: Args) {
// No transport template copy — consumers import UdsIpcServer from
// '@aztec/ipc-runtime' (or hand a compatible byte-handler in).
}
if (args.client || args.packageDir) {
if (args.client || (args.packageDir && !serverPackage)) {
writeFile("async.ts", gen.generateAsyncApi(compiled));
writeFile("sync.ts", gen.generateSyncApi(compiled));
// No transport template copy — consumers import IpcClient from
Expand All @@ -377,25 +384,8 @@ function generate(args: Args) {
}
if (args.packageDir) {
const packageDir = resolve(args.packageDir);
const binaryName =
args.binaryName || toSnakeCase(prefix).replace(/_/g, "-");
const packageName =
args.packageName || `${toSnakeCase(prefix).replace(/_/g, "-")}-ipc`;
const packageGen = new TypeScriptPackageCodegen({
prefix,
packageName,
binaryName,
binaryEnvVar: args.binaryEnvVar || defaultBinaryEnvVar(binaryName),
ipcRuntimeDependency: args.ipcRuntimeDependency,
transports: args.packageTransports
.split(",")
.map((t) => t.trim())
.filter(Boolean),
ipcPathArgs: args.packageIpcPathArgs
.split(",")
.map((arg) => arg.trim())
.filter(Boolean),
});
const writePackage = (
name: string,
content: string,
Expand All @@ -413,22 +403,55 @@ function generate(args: Args) {
}
console.log(` ${path} (package)`);
};
writePackage("package.json", packageGen.generatePackageJson());
writePackage("tsconfig.json", packageGen.generateTsconfig());
writePackage("README.md", packageGen.generateReadme());
writePackage("src/index.ts", packageGen.generateIndex());
writePackage("src/platform.ts", packageGen.generatePlatform());
if (binaryName) {
writePackage("src/bin.ts", packageGen.generateBin());
}
for (const manifest of packageGen.generateArchPackageManifests()) {
writePackage(manifest.path, manifest.content);
if (serverPackage) {
const schemaFileName = basename(absSchema);
const packageGen = new TypeScriptServerPackageCodegen({
prefix,
packageName,
schemaFileName,
});
writePackage("package.json", packageGen.generatePackageJson());
writePackage("tsconfig.json", packageGen.generateTsconfig());
writePackage("README.md", packageGen.generateReadme());
writePackage("src/index.ts", packageGen.generateIndex());
// Ship the schema itself: it is the wire contract the package was
// generated from, and lets consumers regenerate bindings.
writePackage(schemaFileName, readFileSync(absSchema, "utf-8"));
} else {
const binaryName =
args.binaryName || toSnakeCase(prefix).replace(/_/g, "-");
const packageGen = new TypeScriptPackageCodegen({
prefix,
packageName,
binaryName,
binaryEnvVar: args.binaryEnvVar || defaultBinaryEnvVar(binaryName),
ipcRuntimeDependency: args.ipcRuntimeDependency,
transports: args.packageTransports
.split(",")
.map((t) => t.trim())
.filter(Boolean),
ipcPathArgs: args.packageIpcPathArgs
.split(",")
.map((arg) => arg.trim())
.filter(Boolean),
});
writePackage("package.json", packageGen.generatePackageJson());
writePackage("tsconfig.json", packageGen.generateTsconfig());
writePackage("README.md", packageGen.generateReadme());
writePackage("src/index.ts", packageGen.generateIndex());
writePackage("src/platform.ts", packageGen.generatePlatform());
if (binaryName) {
writePackage("src/bin.ts", packageGen.generateBin());
}
for (const manifest of packageGen.generateArchPackageManifests()) {
writePackage(manifest.path, manifest.content);
}
writePackage(
"scripts/prepare_arch_packages.sh",
packageGen.generatePrepareArchPackagesScript(),
{ executable: true },
);
}
writePackage(
"scripts/prepare_arch_packages.sh",
packageGen.generatePrepareArchPackagesScript(),
{ executable: true },
);
}
break;
}
Expand Down
Loading
Loading