From ffa517e713a0313ce9c8d6dc5f9869395eaff7c9 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Fri, 6 Mar 2026 19:25:12 +0000 Subject: [PATCH] fix: shared flock guard for rustup to prevent parallel build races --- avm-transpiler/bootstrap.sh | 10 +++++----- bootstrap.sh | 12 ++++++++---- noir/bootstrap.sh | 22 +++++++++++++--------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/avm-transpiler/bootstrap.sh b/avm-transpiler/bootstrap.sh index 768ce11eb08c..dc062d1e5cf2 100755 --- a/avm-transpiler/bootstrap.sh +++ b/avm-transpiler/bootstrap.sh @@ -13,13 +13,13 @@ function build_native { echo_header "avm-transpiler build_native" artifact=avm-transpiler-$hash.tar.gz if ! cache_download $artifact; then - # Serialize cargo/rustup operations to avoid race conditions when running parallel builds - # Cargo may trigger rustup to install components (rust-src, etc.) in shared directories + # Serialize cargo/rustup operations to avoid race conditions with noir build + # which may run in parallel and share the same RUSTUP_HOME/CARGO_HOME. ( flock -x 200 denoise "cargo build --release --locked --bin avm-transpiler" denoise "cargo build --release --locked --lib" - ) 200>/tmp/rustup-avm-transpiler.lock + ) 200>/tmp/rustup.lock denoise "cargo fmt --check" denoise "cargo clippy" @@ -54,7 +54,7 @@ function build_cross { ;; esac - # Serialize rustup operations to avoid race conditions when running parallel builds + # Serialize rustup operations to avoid race conditions with noir build ( flock -x 200 if ! command -v cargo-zigbuild >/dev/null 2>&1; then @@ -65,7 +65,7 @@ function build_cross { echo "Installing Rust target: $rust_target" rustup target add "$rust_target" fi - ) 200>/tmp/rustup-avm-transpiler.lock + ) 200>/tmp/rustup.lock cargo zigbuild --release --target "$rust_target" --lib diff --git a/bootstrap.sh b/bootstrap.sh index cdd88480cebb..3363f48fb81a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -102,10 +102,14 @@ function check_toolchains { fi if ! rustup show | grep $rust_version > /dev/null; then if [ "${CI:-0}" -eq 1 ]; then - echo "Attempting install of required Rust version $rust_version" - rustup self update 2>/dev/null || true - rustup toolchain install $rust_version - rustup default $rust_version + # Serialize rustup operations to avoid race conditions with parallel builds. + ( + flock -x 200 + echo "Attempting install of required Rust version $rust_version" + rustup self update 2>/dev/null || true + rustup toolchain install $rust_version + rustup default $rust_version + ) 200>/tmp/rustup.lock else # Cargo will download necessary version of rust at runtime but warn to alert that an update to the build-image # is desirable. diff --git a/noir/bootstrap.sh b/noir/bootstrap.sh index 91515a2005e4..4fd19781f16a 100755 --- a/noir/bootstrap.sh +++ b/noir/bootstrap.sh @@ -77,15 +77,19 @@ function build_packages { function install_deps { set -euo pipefail - # TODO: Move to build image? - if ! command -v cargo-binstall &>/dev/null; then - curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - fi - if ! command -v just &>/dev/null; then - cargo-binstall just --version 1.42.4 -y --secure - fi - just --justfile ./noir-repo/justfile install-rust-tools - just --justfile ./noir-repo/justfile install-js-tools + # Serialize rustup/cargo-binstall operations to avoid race conditions with avm-transpiler + # which may run in parallel and share the same RUSTUP_HOME/CARGO_HOME. + ( + flock -x 200 + if ! command -v cargo-binstall &>/dev/null; then + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + fi + if ! command -v just &>/dev/null; then + cargo-binstall just --version 1.42.4 -y --secure + fi + just --justfile ./noir-repo/justfile install-rust-tools + just --justfile ./noir-repo/justfile install-js-tools + ) 200>/tmp/rustup.lock } export -f build_native build_packages install_deps