Skip to content

Commit

Permalink
yarn-project fast build 45s, full build 1m30s
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielye committed Feb 3, 2025
1 parent f18984d commit df8c98a
Show file tree
Hide file tree
Showing 24 changed files with 1,036 additions and 63 deletions.
16 changes: 12 additions & 4 deletions yarn-project/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ node_modules/
dest/
noir-contracts.js/**/*.json
noir-protocol-circuits-types/src/target/*
boxes/*/src/artifacts/*.json
boxes/*/src/artifacts/*.ts
boxes/*/src/contracts/target/*.json
*.md
end-to-end/src/fixtures/dumps/*.json
end-to-end/src/web/main.js
end-to-end/src/web/main.js
l1-artifacts/src
circuit-types/src/test/artifacts/token_contract-Token.json
noir-contracts.js/src
ivc-integration/src/types/index.ts
protocol-contracts/src/protocol_contract_data.ts
noir-protocol-circuits-types/src/types/index.ts
noir-protocol-circuits-types/src/private_kernel_reset_data.ts
noir-protocol-circuits-types/src/private_kernel_reset_types.ts
noir-protocol-circuits-types/src/private_kernel_reset_vks.ts
noir-protocol-circuits-types/src/client_artifacts_helper.ts
circuits.js/src/constants.gen.ts
15 changes: 15 additions & 0 deletions yarn-project/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true
}
},
"module": {
"type": "es6"
}
}
8 changes: 7 additions & 1 deletion yarn-project/aztec.js/src/api/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export { AccountContract, AccountInterface, AuthWitnessProvider, Salt, Wallet } from '../account/index.js';
export {
type AccountContract,
type AccountInterface,
type AuthWitnessProvider,
type Salt,
type Wallet,
} from '../account/index.js';

export { AccountManager } from '../account_manager/index.js';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/api/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { deployL1Contract, deployL1Contracts, DeployL1Contracts } from '@aztec/ethereum/deploy-l1-contracts';
export { deployL1Contract, deployL1Contracts, type DeployL1Contracts } from '@aztec/ethereum/deploy-l1-contracts';
export { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes';
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/api/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export {
AccountWallet,
AccountWalletWithSecretKey as AccountWalletWithSecretKey,
SignerlessWallet,
Wallet,
type Wallet,
getWallet,
} from '../wallet/index.js';
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, type Walle
// // TODO https://github.com/AztecProtocol/aztec-packages/issues/2632 --> FunctionSelector might not need to be exposed
// // here once the issue is resolved.
export {
ContractClassWithId,
ContractInstanceWithAddress,
type ContractClassWithId,
type ContractInstanceWithAddress,
EthAddress,
Fq,
Fr,
GlobalVariables,
GrumpkinScalar,
INITIAL_L2_BLOCK_NUM,
NodeInfo,
type NodeInfo,
Point,
PublicKeys,
getContractClassFromArtifact,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.dest.json',
transpileOnly: true,
},
},
],
Expand Down
64 changes: 54 additions & 10 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
#!/usr/bin/env bash
source $(git rev-parse --show-toplevel)/ci3/source_bootstrap

TEST_FLAKES=${TEST_FLAKES:-0}
cmd=${1:-}

hash=$(cache_content_hash \
../noir/.rebuild_patterns \
../{avm-transpiler,noir-projects,l1-contracts,yarn-project}/.rebuild_patterns \
../barretenberg/*/.rebuild_patterns)

function compile_project {
# TODO: 16 jobs is magic. Was seeing weird errors otherwise.
parallel -j16 --line-buffered --tag 'cd {} && ../node_modules/.bin/swc src -d dest --config-file=../.swcrc --strip-leading-paths' "$@"
}

function build {
echo_header "yarn-project build"

denoise "$0 clean-lite"
denoise "yarn install"

if cache_download yarn-project-$hash.tar.gz; then
return
fi

for project in foundation l1-artifacts circuits.js; do
denoise "cd $project && yarn build"
done
denoise "yarn generate"
denoise "yarn tsc -b"
compile_project ::: foundation circuits.js types builder ethereum l1-artifacts

# This many projects have a generation stage now!?
parallel --joblog joblog.txt --line-buffered --tag 'cd {} && yarn generate' ::: \
accounts \
circuit-types \
circuits.js \
ivc-integration \
kv-store \
l1-artifacts \
native \
noir-contracts.js \
noir-protocol-circuits-types \
protocol-contracts \
pxe \
types
cat joblog.txt

parallel --line-buffered --tag "denoise 'cd {}; yarn build:web'" ::: aztec.js end-to-end
dirname */src l1-artifacts/generated | grep -v scripts | compile_project

cmds=(
'cd aztec.js && yarn build:web'
'cd end-to-end && yarn build:web'
)
[ "${typecheck:-0}" -eq 1 ] && cmds+=('yarn tsc -b --emitDeclarationOnly')
parallel --line-buffered --tag denoise ::: "${cmds[@]}"
# parallel --line-buffered --tag denoise 'cd {} && yarn build:web' ::: aztec.js end-to-end

# Upload common patterns for artifacts: dest, fixtures, build, artifacts, generated
# Then one-off cases. If you've written into src, you need to update this.
Expand All @@ -41,6 +66,15 @@ function build {
echo -e "${green}Yarn project successfully built!${reset}"
}

function format {
find ./*/src -type f -regex '.*\.\(json\|js\|mjs\|cjs\|ts\)$' | \
parallel -N30 ./node_modules/.bin/prettier --loglevel warn --check
}

function lint {
ls -d ./*/src | xargs dirname | parallel 'cd {} && ../node_modules/.bin/eslint --cache ./src'
}

function test_cmds {
# TODO: This takes way longer than it probably should.
echo "$hash cd yarn-project && yarn formatting"
Expand Down Expand Up @@ -71,18 +105,21 @@ function test {

case "$cmd" in
"clean")
[ -n "${2:-}" ] && cd $2
git clean -fdx
;;
"clean-lite")
git clean -fdx --exclude=node_modules --exclude=.yarn
;;
"ci")
build
typecheck=1 build
test
;;
""|"fast")
build
;;
"full")
git clean -fdx --exclude=node_modules --exclude=.yarn
build
typecheck=1 build
;;
"test")
test
Expand All @@ -96,6 +133,13 @@ case "$cmd" in
"release")
release
;;
"compile")
shift
compile_project ::: "$@"
;;
"format")
format
;;
*)
echo "Unknown command: $cmd"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
"generate": "./scripts/copy-test-artifacts.sh && run -T prettier -w ./src/test/artifacts --loglevel warn"
"generate": "./scripts/copy-test-artifacts.sh"
},
"inherits": [
"../package.common.json",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/package.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build": "yarn clean && yarn generate && tsc -b",
"generate": "./scripts/copy-test-artifacts.sh && run -T prettier -w ./src/test/artifacts --loglevel warn",
"generate": "./scripts/copy-test-artifacts.sh",
"clean": "rm -rf ./dest .tsbuildinfo ./src/test/artifacts"
},
"files": ["dest", "src", "!*.test.*"]
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"remake-constants": "node --loader ts-node/esm src/scripts/constants.in.ts && prettier -w src/constants.gen.ts && cd ../../l1-contracts && forge fmt",
"remake-constants": "node --loader @swc-node/register src/scripts/constants.in.ts && cd ../../l1-contracts && forge fmt",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.web.json',
transpileOnly: true,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/ivc-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"formatting:fix:types": "NODE_OPTIONS='--max-old-space-size=8096' run -T eslint --fix ./src/types && run -T prettier -w ./src/types",
"generate": "yarn generate:noir-circuits",
"generate:noir-circuits": "mkdir -p ./artifacts && cp -r ../../noir-projects/mock-protocol-circuits/target/* ./artifacts && node --no-warnings --loader ts-node/esm src/scripts/generate_declaration_files.ts && node --no-warnings --loader ts-node/esm src/scripts/generate_ts_from_abi.ts && run -T prettier -w ./src/types",
"generate:noir-circuits": "mkdir -p ./artifacts && cp -r ../../noir-projects/mock-protocol-circuits/target/* ./artifacts && node --no-warnings --loader @swc-node/register/esm src/scripts/generate_declaration_files.ts && node --no-warnings --loader @swc-node/register/esm src/scripts/generate_ts_from_abi.ts",
"test:non-browser": "RAYON_NUM_THREADS=4 NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testPathIgnorePatterns=browser --passWithNoTests ",
"test:browser": "./run_browser_tests.sh",
"test": "yarn test:non-browser",
Expand Down
1 change: 1 addition & 0 deletions yarn-project/l1-artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
18 changes: 9 additions & 9 deletions yarn-project/l1-artifacts/scripts/generate-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd $(git rev-parse --show-toplevel)/yarn-project/l1-artifacts

# Contracts name list (all assumed to be in l1-contracts).
# This script writes into the generated/ folder:
# This script writes into the src/ folder:
# - index.ts: entrypoint
# - {name}Abi.ts: contains the ABI
# - {name}Bytecode.ts: contains the bytecode and link references
Expand Down Expand Up @@ -50,9 +50,9 @@ combined_errors_abi=$(
)

# Start from clean.
rm -rf generated && mkdir generated
rm -rf src && mkdir src

echo "// Auto-generated module" >"generated/index.ts"
echo "// Auto-generated module" >"src/index.ts"

# Generate ErrorsAbi.ts
(
Expand All @@ -62,10 +62,10 @@ echo "// Auto-generated module" >"generated/index.ts"
echo -n "export const ErrorsAbi = "
echo -n "$combined_errors_abi"
echo " as const;"
) >"generated/ErrorsAbi.ts"
) >"src/ErrorsAbi.ts"

# Add Errors export to index.ts
echo "export * from './ErrorsAbi.js';" >>"generated/index.ts"
echo "export * from './ErrorsAbi.js';" >>"src/index.ts"

for contract_name in "${contracts[@]}"; do
# Generate <ContractName>Abi.ts
Expand All @@ -82,7 +82,7 @@ for contract_name in "${contracts[@]}"; do
' \
"../../l1-contracts/out/${contract_name}.sol/${contract_name}.json"
echo " as const;"
) >"generated/${contract_name}Abi.ts"
) >"src/${contract_name}Abi.ts"

# Generate <ContractName>Bytecode.ts
(
Expand All @@ -101,11 +101,11 @@ for contract_name in "${contracts[@]}"; do
jq -j '.bytecode.linkReferences' \
"../../l1-contracts/out/${contract_name}.sol/${contract_name}.json"
echo " as const;"
) >"generated/${contract_name}Bytecode.ts"
) >"src/${contract_name}Bytecode.ts"

# Update index.ts exports
echo "export * from './${contract_name}Abi.js';" >>"generated/index.ts"
echo "export * from './${contract_name}Bytecode.js';" >>"generated/index.ts"
echo "export * from './${contract_name}Abi.js';" >>"src/index.ts"
echo "export * from './${contract_name}Bytecode.js';" >>"src/index.ts"
done

echo "Successfully generated TS artifacts!"
4 changes: 2 additions & 2 deletions yarn-project/l1-artifacts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"extends": "..",
"compilerOptions": {
"outDir": "dest",
"rootDir": "generated",
"rootDir": "src",
"tsBuildInfoFile": ".tsbuildinfo"
},
"include": ["generated"],
"include": ["src"],
"references": []
}
2 changes: 1 addition & 1 deletion yarn-project/noir-bb-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"clean": "rm -rf ./dest .tsbuildinfo src/types artifacts",
"generate": "yarn generate:artifacts && yarn generate:code",
"generate:artifacts": "mkdir -p artifacts/keys && ls circuits | xargs -n 1 ./generate_artifacts.sh",
"generate:code": "node --no-warnings --loader ts-node/esm src/scripts/generate_declaration_files.ts && node --no-warnings --loader ts-node/esm src/scripts/generate_ts_from_abi.ts && run -T prettier -w ./src/types",
"generate:code": "node --no-warnings --loader @swc-node/register/esm src/scripts/generate_declaration_files.ts && node --no-warnings --loader @swc-node/register/esm src/scripts/generate_ts_from_abi.ts",
"build:ts": "tsc -b",
"build:app": "tsc -b && rm -rf dest && webpack && cp ../../barretenberg/favicon.ico dest",
"build:dev": "tsc -b --watch",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/noir-contracts.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
"generate": "yarn generate:noir-contracts",
"generate:noir-contracts": "./scripts/generate-types.sh && run -T prettier -w ./src --loglevel warn"
"generate:noir-contracts": "./scripts/generate-types.sh"
},
"inherits": [
"../package.common.json",
Expand Down
11 changes: 3 additions & 8 deletions yarn-project/noir-contracts.js/package.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
"scripts": {
"build": "yarn clean && yarn generate",
"generate": "yarn generate:noir-contracts",
"generate:noir-contracts": "./scripts/generate-types.sh && run -T prettier -w ./src --loglevel warn",
"generate:noir-contracts": "./scripts/generate-types.sh",
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts ./src ./codegenCache.json"
},
"files": [
"dest",
"src",
"artifacts",
"!*.test.*"
]
}
"files": ["dest", "src", "artifacts", "!*.test.*"]
}
9 changes: 2 additions & 7 deletions yarn-project/noir-protocol-circuits-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"formatting:fix:types": "NODE_OPTIONS='--max-old-space-size=8096' run -T eslint --fix ./src/types && run -T prettier -w ./src/types",
"generate": "yarn generate:copy-artifacts && yarn generate:vk-hashes && yarn generate:noir-circuits && yarn generate:reset-data && yarn generate:client-artifacts-helper",
"generate:copy-artifacts": "mkdir -p ./artifacts && cp -r ../../noir-projects/noir-protocol-circuits/target/* ./artifacts && node --no-warnings --loader ts-node/esm src/scripts/generate_declaration_files.ts ",
"generate:cleanup-artifacts": "node --no-warnings --loader ts-node/esm src/scripts/cleanup_artifacts.ts",
"generate:vk-hashes": "node --no-warnings --loader ts-node/esm src/scripts/generate_vk_hashes.ts",
"generate:noir-circuits": "node --no-warnings --loader ts-node/esm src/scripts/generate_ts_from_abi.ts && run -T prettier -w ./src/types",
"generate:reset-data": "node --no-warnings --loader ts-node/esm src/scripts/generate_private_kernel_reset_data.ts && run -T prettier -w src/private_kernel_reset_*.ts",
"generate:client-artifacts-helper": "node --no-warnings --loader ts-node/esm src/scripts/generate_client_artifacts_helper.ts && run -T prettier -w src/client_artifacts_helper.ts",
"generate": "./scripts/generate.sh",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
"codegen": "yarn noir-codegen",
"build:dev": "tsc -b --watch"
Expand Down Expand Up @@ -80,6 +74,7 @@
"@aztec/kv-store": "workspace:^",
"@aztec/merkle-tree": "workspace:^",
"@jest/globals": "^29.5.0",
"@swc/helpers": "^0.5.15",
"@types/jest": "^29.5.0",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
Expand Down
Loading

0 comments on commit df8c98a

Please sign in to comment.