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
4 changes: 4 additions & 0 deletions contrib/lockfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ _cleanup_lockfile() {

use_lockfile() {
local src="$1"
# Already in place, from an enclosing script or an earlier run.
if cmp -s "$src" "$LOCKFILE"; then
return 0
fi
Comment on lines +19 to +22

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching contents alone also lets unrelated processes bypass an active .bak lock and skips backup/cleanup for top-level callers. For example, if Cargo.lock already matches recent, contrib/test.sh now leaves it on minimal instead of restoring recent.

One small fix is to require ${PAYJOIN_LOCKFILE_HELD:-} to equal $LOCKFILE as well as the cmp, and export PAYJOIN_LOCKFILE_HELD="$LOCKFILE" after successfully acquiring and copying the lockfile. This preserves nested C# calls while retaining restoration and mutual exclusion. Focused shell checks reproduce both regressions on this PR and pass with that change.

diff --git a/contrib/lockfile.sh b/contrib/lockfile.sh
index eae3fa10..1321a95f 100644
--- a/contrib/lockfile.sh
+++ b/contrib/lockfile.sh
@@ -16,8 +16,8 @@ _cleanup_lockfile() {
 
 use_lockfile() {
     local src="$1"
-    # Already in place, from an enclosing script or an earlier run.
-    if cmp -s "$src" "$LOCKFILE"; then
+    # Only reuse a lock held by this script or inherited from an enclosing script.
+    if [ "${PAYJOIN_LOCKFILE_HELD:-}" = "$LOCKFILE" ] && cmp -s "$src" "$LOCKFILE"; then
         return 0
     fi
     if ! mkdir "$LOCKDIR" 2>/dev/null; then
@@ -29,4 +29,5 @@ use_lockfile() {
         mv "$LOCKFILE" "$LOCKFILE_BAK"
     fi
     cp "$src" "$LOCKFILE"
+    export PAYJOIN_LOCKFILE_HELD="$LOCKFILE"
 }

@DanGould DanGould Sep 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wat why are we depending against an "urelated process" bypassing .bak? This is just local environment that you'd have checked out on a worktree. No?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, a concurrency problem wouldn't be an issue in most cases, but the restoration issue can happen during local development with a single command in an isolated worktree.

If Cargo.lock already matches Cargo-recent.lock, this returns before setting up the backup and cleanup trap. contrib/test.sh then switches to Cargo-minimal.lock and leaves it there on exit, instead of restoring recent.

if ! mkdir "$LOCKDIR" 2>/dev/null; then
echo "Another instance is running. If you're sure it's not, remove $LOCKDIR and try again." >&2
exit 1
Expand Down
6 changes: 6 additions & 0 deletions payjoin-ffi/csharp/scripts/build_nuget_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ rid_to_cross_tool() {

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CSHARP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

REPO_ROOT="$(cd "$CSHARP_DIR/../.." && pwd)"
cd "$REPO_ROOT"
source contrib/lockfile.sh
use_lockfile Cargo-recent.lock

cd "$CSHARP_DIR"

RID=${PAYJOIN_FFI_RID:-$(detect_rid)}
Expand Down
6 changes: 6 additions & 0 deletions payjoin-ffi/csharp/scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ fi

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"
source contrib/lockfile.sh
use_lockfile Cargo-recent.lock

# Navigate to payjoin-ffi directory (parent of csharp, which is parent of scripts)
cd "$SCRIPT_DIR/../.."

Expand Down
4 changes: 2 additions & 2 deletions payjoin-ffi/dart/contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use_lockfile Cargo-recent.lock

cd "$REPO_ROOT/payjoin-ffi/dart"

echo "==> Cleaning nested Cargo.lock..."
rm -f native/Cargo.lock
echo "==> Seeding the nested workspace's Cargo.lock from the maintained lockfile..."
cp "$REPO_ROOT/Cargo-recent.lock" native/Cargo.lock

echo "==> Generating FFI bindings..."
bash ./scripts/generate_bindings.sh
Expand Down
6 changes: 6 additions & 0 deletions payjoin-ffi/dart/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ crate-type = ["staticlib", "cdylib"]
payjoin-ffi = { git = "https://github.com/payjoin/rust-payjoin.git", rev = "60d0adbf4ee8e60090209d55e9864893a4acc30e", features = [
"dart",
] }
# Not used directly. yoke-derive 0.8.3 needs Rust 1.87 but declares no rust-version,
# so consumers' fresh resolution on the toolchain above picks it. Drop once upstream fixes it.
yoke-derive = "=0.8.2"

[package.metadata.cargo-machete]
ignored = ["yoke-derive"]
7 changes: 7 additions & 0 deletions payjoin-ffi/javascript/scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ if command -v rustup >/dev/null 2>&1 &&
rustup target add wasm32-unknown-unknown
fi

# ubrn's generated wasm crate and the test-utils napi addon are workspaces of
# their own; seed both from the maintained lockfile.
JS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
mkdir -p "$JS_DIR/rust_modules/wasm"
cp "$JS_DIR/../../Cargo-recent.lock" "$JS_DIR/rust_modules/wasm/Cargo.lock"
cp "$JS_DIR/../../Cargo-recent.lock" "$JS_DIR/test-utils/Cargo.lock"

npm run build

# The test-utils addon is a dev-only native helper for the integration tests.
Expand Down
Loading