From 99ff6de722b608db7d29727f5201e3c6858bf542 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 02:04:30 +0000 Subject: [PATCH] scripts: resolve a relative CARGO_TARGET_DIR before deriving the .s path Review follow-up to #443. Cargo resolves a relative CARGO_TARGET_DIR against the directory it runs in, while rustc resolves `--emit=asm=` against the package directory, so a relative target dir made the scripts create the assembly directory in one place and ask rustc to write it in another. codegen-witness.sh runs cargo from ROOT, so a relative TD is resolved against ROOT (and exported); neon-asm-rung3.sh runs cargo from the caller's directory, so it is resolved against PWD. Absolute defaults are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ArVbbq3DsToBM7r79zGeEf --- scripts/codegen-witness.sh | 6 ++++++ scripts/neon-asm-rung3.sh | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/scripts/codegen-witness.sh b/scripts/codegen-witness.sh index ce0e0ee4..664f4c6e 100755 --- a/scripts/codegen-witness.sh +++ b/scripts/codegen-witness.sh @@ -30,6 +30,12 @@ EXPECT="${1:?expect: avx512|avx2|neon}" TRIPLE="${2:-$(rustc -vV | sed -n 's/^host: //p')}" ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" TD="${CARGO_TARGET_DIR:-$ROOT/target}" +# Cargo runs from ROOT (the `cd` below), so a relative CARGO_TARGET_DIR +# resolves against ROOT, while rustc resolves `--emit=asm=` against the +# package directory. An absolute TD keeps the .s path, the mkdir and the build +# output on one base wherever the script is started from. +case "$TD" in /*) ;; *) TD="$ROOT/$TD" ;; esac +export CARGO_TARGET_DIR="$TD" # rustc writes the assembly to this exact path (`--emit=asm=`). Cargo's # build directory layout is not a stable interface: from Rust 1.100 an `.s` # emitted without a path lands under `/build///out/` diff --git a/scripts/neon-asm-rung3.sh b/scripts/neon-asm-rung3.sh index cb95c42b..658ad929 100755 --- a/scripts/neon-asm-rung3.sh +++ b/scripts/neon-asm-rung3.sh @@ -21,6 +21,11 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" MANIFEST="$ROOT/crates/neon-simd-parity/Cargo.toml" TARGET="aarch64-unknown-linux-gnu" TD="${CARGO_TARGET_DIR:-$ROOT/target-aarch64}" +# Cargo resolves a relative CARGO_TARGET_DIR against the directory it is run +# from (here, the caller's), while rustc resolves `--emit=asm=` against +# the package directory. An absolute TD keeps the .s path, the mkdir and the +# build output on one base. +case "$TD" in /*) ;; *) TD="$PWD/$TD" ;; esac echo "==> emitting aarch64 assembly of neon-simd-parity (link step skipped)" # Stale-assembly guard: remove any previous .s FIRST and let a build failure