Skip to content

build: Honor CARGO_TARGET_DIR in client build scripts#679

Open
celikgo wants to merge 2 commits into
signalapp:mainfrom
celikgo:honor-cargo-target-dir
Open

build: Honor CARGO_TARGET_DIR in client build scripts#679
celikgo wants to merge 2 commits into
signalapp:mainfrom
celikgo:honor-cargo-target-dir

Conversation

@celikgo

@celikgo celikgo commented Jun 11, 2026

Copy link
Copy Markdown

Fixes #655.

The Java JNI, Node, and Swift build steps assumed the Cargo target directory was always target (relative to the workspace root). When a user configures a different target directory via CARGO_TARGET_DIR, Cargo builds the libraries there, but these scripts kept looking in target/ and failed to find them.

swift/build_ffi.sh already honored CARGO_TARGET_DIR (${CARGO_TARGET_DIR:-target}); this change makes the rest of the client build scripts consistent with that convention.

Changes

  • java/build_jni.sh — read the desktop/server artifacts from ${CARGO_TARGET_DIR:-target} instead of a hardcoded target. This is the exact line the issue points at. (The Android path already uses cargo build --artifact-dir, so it's unaffected.)
  • node/build_node_bridge.py — default --cargo-build-dir to CARGO_TARGET_DIR when it's set. Previously the script unconditionally set CARGO_BUILD_TARGET_DIR=../target; since Cargo's CARGO_TARGET_DIR env var takes precedence over CARGO_BUILD_TARGET_DIR, a user with CARGO_TARGET_DIR set had Cargo build into their directory while the script looked in ../target and found nothing.
  • swift/Package.swift — derive the link path (-L) from CARGO_TARGET_DIR, falling back to ../target.
  • bin/build_helpers.sh — make copy_built_library fail with a clear error when no built library is found, instead of silently doing nothing. This is what made the original report confusing: a wrong target dir left the native library out of the resources dir, so the failure surfaced later as a jar not found/zip error in the Gradle packaging step rather than at the actual point of breakage. It now reports the directory searched and the library name, so any future path mismatch (e.g. a target dir set only via .cargo/config.toml, see below) fails loudly and actionably.

Notes / scope

  • Honors the CARGO_TARGET_DIR environment variable specifically (the documented, standard way to relocate the target dir, and what build_ffi.sh already keyed off). A target dir set only via .cargo/config.toml's build.target-dir is out of scope here; resolving that reliably would mean shelling out to cargo metadata. With the copy_built_library change above, that case now fails with a clear error rather than a silent miss.
  • Verified: bash -n java/build_jni.sh, bash -n bin/build_helpers.sh, python3 -m py_compile node/build_node_bridge.py, and swift package describe all pass.

🤖 Generated with Claude Code

celikgo and others added 2 commits June 11, 2026 13:48
The Java JNI, Node, and Swift build steps assumed the Cargo target
directory was always `target` (relative to the workspace root), so a
build with a user-defined target directory failed to locate the compiled
libraries.

- java/build_jni.sh: read the desktop/server artifacts from
  `${CARGO_TARGET_DIR:-target}` instead of a hardcoded `target`. (The
  Android path already uses `--artifact-dir` and is unaffected.)
- node/build_node_bridge.py: default `--cargo-build-dir` to
  `CARGO_TARGET_DIR` when set. Previously the script forced
  CARGO_BUILD_TARGET_DIR=../target, which Cargo's CARGO_TARGET_DIR
  overrides, so the build landed somewhere the script never looked.
- swift/Package.swift: derive the link path from CARGO_TARGET_DIR.

This matches the convention swift/build_ffi.sh already used
(`${CARGO_TARGET_DIR:-target}`).

Fixes signalapp#655

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Previously copy_built_library silently did nothing when no matching
library was found in the build directory. A misconfigured target dir
would leave the native library out of the resources dir, surfacing
later as a confusing "jar not found"/zip error in the Gradle packaging
step rather than at the actual point of failure.

Fail loudly with the searched directory and library name instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@celikgo

celikgo commented Jun 14, 2026

Copy link
Copy Markdown
Author

Friendly nudge on this one — it's a small, self-contained build fix for #655 (honoring CARGO_TARGET_DIR in the Java/Node/Swift build scripts), and the issue still has folks hitting it. Happy to rebase or adjust scope if a maintainer has a preference (e.g. resolving the target dir via cargo metadata to also cover .cargo/config.toml's build.target-dir). Thanks for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow user-defined cargo target dir

1 participant