Skip to content

Commit 5178023

Browse files
committed
Step 5
.agents/codebase-insights.txt: appimage-scripts/build_appimage2.sh: nix/packages/default.nix: Signed-off-by: Tzanko Matev <[email protected]>
1 parent 198dd82 commit 5178023

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

.agents/codebase-insights.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
- `ct record` verifies that `codetracer_python_recorder` is importable before launching the db backend and prints actionable guidance if the module is missing or broken.
2525
- Sudoku test-program datasets include intentionally invalid boards (e.g., examples #3 and #6) with duplicate digits inside a sub-grid; solvers should detect and report these gracefully.
2626
- `appimage-scripts/build_appimage.sh` assumes a devshell: it invokes `nix build`/`nix eval` directly and runs `npm install`/`npx yarn`, so it needs host network access and the git worktree metadata that a pure derivation build lacks.
27-
- `appimage-scripts/build_appimage2.sh` now consumes `packages.${system}.appimagePayload`, which layers the Rust binaries atop the dependency tree from `appimageDeps`, so the script just copies one derivation output into the AppDir.
27+
- `appimage-scripts/build_appimage2.sh` now consumes `packages.${system}.appimagePayload`, which layers the Rust binaries atop the dependency tree from `appimageDeps`; both derivations pre-run `patchelf`, so the script only patches the locally built Nim binaries and bundled Ruby while everything else already targets `/lib64/ld-linux…` (or `/lib/ld-linux-aarch64.so.1`) with `\$ORIGIN/../lib` rpaths.

appimage-scripts/build_appimage2.sh

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,42 +158,18 @@ else
158158
INTERPRETER_PATH=/lib64/ld-linux-x86-64.so.2
159159
fi
160160

161-
# Patchelf the executable's interpreter
161+
# Patchelf the executable's interpreter for locally built components
162162
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/ct_unwrapped"
163-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/db-backend"
164163
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/db-backend-record"
165-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/backend-manager"
166-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/nargo"
167-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/wazero"
168-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/ctags"
169-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/curl"
170-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/cargo-stylus"
171-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/node"
172164
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/ruby/bin/ruby"
173165

174166
# Clear up the executable's rpath
175167
patchelf --remove-rpath "${APP_DIR}/bin/ct_unwrapped"
176-
patchelf --remove-rpath "${APP_DIR}/bin/db-backend"
177168
patchelf --remove-rpath "${APP_DIR}/bin/db-backend-record"
178-
patchelf --remove-rpath "${APP_DIR}/bin/backend-manager"
179-
patchelf --remove-rpath "${APP_DIR}/bin/nargo"
180-
patchelf --remove-rpath "${APP_DIR}/bin/wazero"
181-
patchelf --remove-rpath "${APP_DIR}/bin/ctags"
182-
patchelf --remove-rpath "${APP_DIR}/bin/curl"
183-
patchelf --remove-rpath "${APP_DIR}/bin/cargo-stylus"
184-
patchelf --remove-rpath "${APP_DIR}/bin/node"
185169
patchelf --remove-rpath "${APP_DIR}/ruby/bin/ruby"
186170

187-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/node"
188171
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/ct_unwrapped"
189-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/db-backend"
190172
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/db-backend-record"
191-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/backend-manager"
192-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/nargo"
193-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/wazero"
194-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/ctags"
195-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/curl"
196-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/node"
197173
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/ruby/bin/ruby"
198174

199175
APPIMAGE_ARCH=${CURRENT_ARCH}

nix/packages/default.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
pkgs.findutils
135135
pkgs.gnugrep
136136
pkgs.pax-utils
137+
pkgs.file
138+
pkgs.patchelf
137139
];
138140
} ''
139141
set -euo pipefail
@@ -189,12 +191,34 @@
189191
${pkgs.nodejs_20}/bin/node
190192
191193
chmod +x "$out/bin"/*
194+
195+
INTERPRETER_PATH="${
196+
if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
197+
then "/lib/ld-linux-aarch64.so.1"
198+
else "/lib64/ld-linux-x86-64.so.2"
199+
}"
200+
201+
patch_binary() {
202+
local bin=$1
203+
if file "$bin" | grep -q 'ELF'; then
204+
patchelf --remove-rpath "$bin" || true
205+
patchelf --set-interpreter "''${INTERPRETER_PATH}" "$bin"
206+
patchelf --set-rpath '$ORIGIN/../lib' "$bin"
207+
fi
208+
}
209+
210+
for bin in "$out/bin"/*; do
211+
[ -f "$bin" ] || continue
212+
patch_binary "$bin" || true
213+
done
192214
'';
193215

194216
appimagePayload = pkgs.runCommand "codetracer-appimage-payload" {
195217
nativeBuildInputs = [
196218
pkgs.bashInteractive
197219
pkgs.coreutils
220+
pkgs.file
221+
pkgs.patchelf
198222
];
199223
} ''
200224
set -euo pipefail
@@ -204,11 +228,27 @@
204228
chmod -R u+w "$out"
205229
mkdir -p "$out/bin"
206230
231+
INTERPRETER_PATH="${
232+
if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
233+
then "/lib/ld-linux-aarch64.so.1"
234+
else "/lib64/ld-linux-x86-64.so.2"
235+
}"
236+
237+
patch_binary() {
238+
local bin=$1
239+
if file "$bin" | grep -q 'ELF'; then
240+
patchelf --remove-rpath "$bin" || true
241+
patchelf --set-interpreter "''${INTERPRETER_PATH}" "$bin"
242+
patchelf --set-rpath '$ORIGIN/../lib' "$bin"
243+
fi
244+
}
245+
207246
install_bin() {
208247
local src=$1
209248
local dest=$2
210249
cp -L "$src" "$out/bin/$(basename "$dest")"
211250
chmod +x "$out/bin/$(basename "$dest")"
251+
patch_binary "$out/bin/$(basename "$dest")" || true
212252
}
213253
214254
install_bin ${db-backend}/bin/db-backend db-backend

0 commit comments

Comments
 (0)