Skip to content

Commit 52a7063

Browse files
committed
Step 8
.agents/codebase-insights.txt: appimage-scripts/build_appimage2.sh: appimage-scripts/install_electron.sh: nix/packages/default.nix: Signed-off-by: Tzanko Matev <[email protected]>
1 parent da6cf54 commit 52a7063

File tree

4 files changed

+103
-99
lines changed

4 files changed

+103
-99
lines changed

.agents/codebase-insights.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@
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.
2727
- `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. The Nim outputs are provided via dedicated derivations (`appimageCtUnwrapped`, `appimageDbBackendRecord`, etc.) so we can pinpoint issues per artifact.
2828
- `flake.nix` sets `self.submodules = true`, so `nix build` automatically materializes the git submodules under `libs/`, which is required for the Nim derivations to see their dependencies.
29+
- Stylus-based frontend stylesheets now come from the `packages.${system}.appimageCss` derivation; `build_css.sh` simply copies that output, and `appimagePayload` pulls the same artifacts, so the AppDir no longer depends on ad-hoc `node_modules` during assembly.
30+
- `appimagePayload` now stages the launch scripts (`bin/ct`, `bin/ruby`, `AppRun`), config/resources, and the Ruby recorder submodule directly; `build_appimage2.sh` just handles impure steps (installing Ruby/Electron, copying `node_modules`, updating `frontend_bundle.js`, and calling `appimagetool`).
31+
- Third-party frontend assets that were previously symlinks into `node_modules` (`@exuanbo`, `golden-layout/dist`, `monaco-editor/min`, `mousetrap`, `vex-js`, `xterm`) are now materialized from `node-modules-derivation` inside `appimagePayload`, preventing broken symlinks when the payload is copied out of the Nix store.

appimage-scripts/build_appimage2.sh

Lines changed: 27 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
#
88
# AppDir spec: https://github.com/AppImage/AppImageSpec/blob/master/draft.md#appdir
99
# appimagetool: https://github.com/AppImage/appimagetool
10-
10+
echo "============================"
11+
echo "AppImage build start"
12+
echo "============================"
1113
set -euo pipefail
1214

1315
cleanup() {
1416
echo "Performing cleanup..."
15-
rm -rf ./squashfs-root
17+
if [ -d ./squashfs-root ]; then
18+
chmod -R u+rwX ./squashfs-root >/dev/null 2>&1 || true
19+
rm -rf ./squashfs-root
20+
fi
1621
}
1722

1823
trap cleanup EXIT
@@ -24,10 +29,14 @@ APP_DIR="${ROOT_PATH}/squashfs-root"
2429
export APP_DIR
2530

2631
if [ -e "${ROOT_PATH}/CodeTracer.AppImage" ]; then
27-
rm -rf "${ROOT_PATH}/CodeTracer.AppImage"
32+
chmod -f u+rw "${ROOT_PATH}/CodeTracer.AppImage" >/dev/null 2>&1 || true
33+
rm -f "${ROOT_PATH}/CodeTracer.AppImage"
2834
fi
2935

30-
rm -rf "${APP_DIR}"
36+
if [ -d "${APP_DIR}" ]; then
37+
chmod -R u+rwX "${APP_DIR}" >/dev/null 2>&1 || true
38+
rm -rf "${APP_DIR}"
39+
fi
3140
mkdir -p "${APP_DIR}"
3241

3342
# This environment variable controls where build artifacts and static resources end up.
@@ -40,110 +49,27 @@ cp -Lr "${APPIMAGE_PAYLOAD}/." "${APP_DIR}/"
4049

4150
chmod -R u+rwX "${APP_DIR}"
4251

43-
mkdir -p "${APP_DIR}/bin" "${APP_DIR}/src" "${APP_DIR}/views"
44-
4552
# Install Ruby
4653
bash "${ROOT_PATH}/appimage-scripts/install_ruby.sh"
4754

48-
cat <<'EOF' >"${APP_DIR}/bin/ruby"
49-
#!/usr/bin/env bash
50-
51-
HERE="${HERE:-..}"
52-
53-
# TODO: This includes references to x86_64. What about aarch64?
54-
export RUBYLIB="${HERE}/ruby/lib/ruby/3.3.0:${HERE}/ruby/lib/ruby/3.3.0/x86_64-linux:${RUBYLIB}"
55-
56-
"${HERE}/ruby/bin/ruby" "$@"
57-
58-
EOF
59-
60-
# ruby recorder
61-
cp -Lr "${ROOT_PATH}/libs/codetracer-ruby-recorder" "${APP_DIR}/"
62-
6355
# Copy over electron
6456
# bash "${ROOT_PATH}/appimage-scripts/install_electron_nix.sh"
6557
bash "${ROOT_PATH}/appimage-scripts/install_electron.sh"
6658

6759
# Setup node deps
6860
bash "${ROOT_PATH}/appimage-scripts/setup_node_deps.sh"
6961

70-
cat <<'EOF' >"${APP_DIR}/bin/ct"
71-
#!/usr/bin/env bash
72-
73-
HERE=${HERE:-$(dirname "$(readlink -f "${0}")")}
74-
75-
# TODO: This includes references to x86_64. What about aarch64?
76-
77-
exec "${HERE}/bin/ct_unwrapped" "$@"
78-
79-
EOF
80-
81-
# Ensure copied binaries are executable.
82-
chmod +x "${APP_DIR}/bin/"{cargo-stylus,ctags,curl,nargo,node,wazero,db-backend,backend-manager}
83-
84-
chmod -R +x "${APP_DIR}/bin"
85-
chmod -R +x "${APP_DIR}/electron"
86-
87-
chmod -R 777 "${APP_DIR}"
88-
89-
cp "${ROOT_PATH}/src/helpers.js" "${APP_DIR}/src/helpers.js"
90-
cp "${ROOT_PATH}/src/helpers.js" "${APP_DIR}/helpers.js"
91-
92-
cp "${ROOT_PATH}/src/frontend/index.html" "${APP_DIR}/src/index.html"
93-
cp "${ROOT_PATH}/src/frontend/index.html" "${APP_DIR}/index.html"
94-
95-
cp "${ROOT_PATH}/src/frontend/subwindow.html" "${APP_DIR}/subwindow.html"
96-
cp "${ROOT_PATH}/src/frontend/subwindow.html" "${APP_DIR}/src/subwindow.html"
97-
98-
cp "${ROOT_PATH}/views/server_index.ejs" "${APP_DIR}/views/server_index.ejs"
99-
100-
rm -rf "${APP_DIR}/config"
101-
rm -rf "${APP_DIR}/public"
102-
cp -Lr "${ROOT_PATH}/src/config" "${APP_DIR}/config"
103-
104-
# Enable the installation prompt
105-
sed -i "s/skipInstall.*/skipInstall: false/g" "${APP_DIR}/config/default_config.yaml"
106-
10762
cp -Lr "${ROOT_PATH}/src/public" "${APP_DIR}/public"
10863
chmod -R +wr "${APP_DIR}/public"
64+
mkdir -p "${APP_DIR}/public/dist"
65+
cp -Lr "${ROOT_PATH}/src/public/dist/frontend_bundle.js" "${APP_DIR}/frontend_bundle.js"
10966

110-
cp -Lr "${ROOT_PATH}/src/public/dist/frontend_bundle.js" "${APP_DIR}"
111-
112-
# Create AppRun script
113-
cat <<'EOF' >"${APP_DIR}/AppRun"
114-
#!/usr/bin/env bash
115-
116-
export HERE=$(dirname "$(readlink -f "${0}")")
117-
118-
# TODO: This includes references to x86_64. What about aarch64?
119-
export LINKS_PATH_DIR=$HERE
120-
export PATH="${HERE}/bin:${PATH}"
121-
export CODETRACER_RUBY_RECORDER_PATH="${HERE}/codetracer-ruby-recorder/gems/codetracer-pure-ruby-recorder/bin/codetracer-pure-ruby-recorder"
122-
123-
exec ${HERE}/bin/ct "$@"
124-
EOF
12567

126-
chmod +x "${APP_DIR}/AppRun"
127-
128-
# Copy over desktop file
129-
cp "${ROOT_PATH}/resources/codetracer.desktop" "${APP_DIR}/"
130-
131-
# Copy over resources
132-
cp -Lr "${ROOT_PATH}/resources" "${APP_DIR}"
133-
134-
SRC_ICONSET_DIR="${ROOT_PATH}/resources/Icon.iconset"
135-
136-
# TODO: discover these dynamically perhaps
137-
for SIZE in 16 32 128 256 512; do
138-
XSIZE="${SIZE}x${SIZE}"
139-
DST_PATH="${APP_DIR}/usr/share/icons/hicolor/${XSIZE}/apps/"
140-
DOUBLE_SIZE_DST_PATH="${APP_DIR}/usr/share/icons/hicolor/${XSIZE}@2/apps/"
141-
mkdir -p "${DST_PATH}" "${DOUBLE_SIZE_DST_PATH}"
142-
cp "${SRC_ICONSET_DIR}/icon_${XSIZE}.png" "${DST_PATH}/codetracer.png"
143-
cp "${SRC_ICONSET_DIR}/icon_${XSIZE}@2x.png" "${DOUBLE_SIZE_DST_PATH}/codetracer.png"
144-
done
68+
chmod -R +x "${APP_DIR}/electron"
14569

146-
cp "${ROOT_PATH}/resources/Icon.iconset/icon_256x256.png" "${APP_DIR}/codetracer.png"
70+
echo "============================"
71+
echo "AppImage patchelf"
72+
echo "============================"
14773

14874
CURRENT_ARCH=$(uname -m)
14975
if [[ "${CURRENT_ARCH}" == "aarch64" ]]; then
@@ -152,18 +78,16 @@ else
15278
INTERPRETER_PATH=/lib64/ld-linux-x86-64.so.2
15379
fi
15480

81+
82+
chmod -R u+w ${APP_DIR}
15583
# Patchelf the executable's interpreter for locally built components
156-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/ct_unwrapped"
157-
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/bin/db-backend-record"
84+
# Nim binaries have already been patched in appimagePayload; only patch the
85+
# Ruby interpreter that we copy in impurely here.
15886
patchelf --set-interpreter "${INTERPRETER_PATH}" "${APP_DIR}/ruby/bin/ruby"
15987

16088
# Clear up the executable's rpath
161-
patchelf --remove-rpath "${APP_DIR}/bin/ct_unwrapped"
162-
patchelf --remove-rpath "${APP_DIR}/bin/db-backend-record"
16389
patchelf --remove-rpath "${APP_DIR}/ruby/bin/ruby"
16490

165-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/ct_unwrapped"
166-
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/bin/db-backend-record"
16791
patchelf --set-rpath "\$ORIGIN/../lib" "${APP_DIR}/ruby/bin/ruby"
16892

16993
APPIMAGE_ARCH=${CURRENT_ARCH}
@@ -172,6 +96,10 @@ if [[ "${APPIMAGE_ARCH}" == "aarch64" ]]; then
17296
APPIMAGE_ARCH=arm_aarch64
17397
fi
17498

99+
echo "============================"
100+
echo "AppImagetool"
101+
echo "============================"
102+
175103
# Use AppImage tool to create AppImage itself
176104
ARCH=${APPIMAGE_ARCH} appimagetool "${APP_DIR}" CodeTracer.AppImage
177105

appimage-scripts/install_electron.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export LD_LIBRARY_PATH="${HERE}/ruby/lib:${HERE}/lib:/usr/lib/:/usr/lib64/:/usr/
2020
2121
"${ELECTRON_DIR}"/electron --no-sandbox "$@"
2222
EOF
23+
24+
chmod +x "${APP_DIR}/bin/electron"

nix/packages/default.nix

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
pkgs.bashInteractive
430430
pkgs.coreutils
431431
pkgs.file
432+
pkgs.gnused
432433
pkgs.patchelf
433434
];
434435
} ''
@@ -439,8 +440,28 @@
439440
chmod -R u+w "$out"
440441
mkdir -p "$out/bin"
441442
mkdir -p "$out/src"
443+
mkdir -p "$out/views"
442444
443445
cp -Lr ${appimageCss}/frontend "$out/"
446+
cp -Lr ${src}/libs/codetracer-ruby-recorder "$out/codetracer-ruby-recorder"
447+
448+
cp -L ${src}/src/helpers.js "$out/helpers.js"
449+
cp -L ${src}/src/helpers.js "$out/src/helpers.js"
450+
451+
cp -L ${src}/src/frontend/index.html "$out/index.html"
452+
cp -L ${src}/src/frontend/index.html "$out/src/index.html"
453+
454+
cp -L ${src}/src/frontend/subwindow.html "$out/subwindow.html"
455+
cp -L ${src}/src/frontend/subwindow.html "$out/src/subwindow.html"
456+
457+
cp -L ${src}/views/server_index.ejs "$out/views/server_index.ejs"
458+
459+
cp -R ${src}/src/config "$out/config"
460+
chmod -R u+w "$out/config"
461+
sed -i 's/skipInstall.*/skipInstall: false/' "$out/config/default_config.yaml"
462+
463+
cp -R ${src}/resources "$out/resources"
464+
cp -L ${src}/resources/codetracer.desktop "$out/codetracer.desktop"
444465
445466
INTERPRETER_PATH="${
446467
if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
@@ -482,6 +503,56 @@
482503
cp -L ${appimageSubwindowJs}/subwindow.js "$out/subwindow.js"
483504
cp -L ${appimageSubwindowJs}/subwindow.js "$out/src/subwindow.js"
484505
506+
cat <<'EOF' > "$out/bin/ct"
507+
#!/usr/bin/env bash
508+
509+
HERE=''${HERE:-$(dirname "$(readlink -f "$0")")}
510+
511+
# TODO: This includes references to x86_64. What about aarch64?
512+
513+
exec "''${HERE}/bin/ct_unwrapped" "$@"
514+
EOF
515+
chmod +x "$out/bin/ct"
516+
517+
cat <<'EOF' > "$out/bin/ruby"
518+
#!/usr/bin/env bash
519+
520+
HERE="''${HERE:-..}"
521+
522+
# TODO: This includes references to x86_64. What about aarch64?
523+
export RUBYLIB="''${HERE}/ruby/lib/ruby/3.3.0:''${HERE}/ruby/lib/ruby/3.3.0/x86_64-linux:''${RUBYLIB}"
524+
525+
"''${HERE}/ruby/bin/ruby" "$@"
526+
527+
EOF
528+
chmod +x "$out/bin/ruby"
529+
530+
cat <<'EOF' > "$out/AppRun"
531+
#!/usr/bin/env bash
532+
533+
export HERE=$(dirname "$(readlink -f "$0")")
534+
535+
# TODO: This includes references to x86_64. What about aarch64?
536+
export LINKS_PATH_DIR=''${HERE}
537+
export PATH="''${HERE}/bin:''${PATH}"
538+
export CODETRACER_RUBY_RECORDER_PATH="''${HERE}/codetracer-ruby-recorder/gems/codetracer-pure-ruby-recorder/bin/codetracer-pure-ruby-recorder"
539+
540+
exec ''${HERE}/bin/ct "$@"
541+
EOF
542+
chmod +x "$out/AppRun"
543+
544+
SRC_ICONSET_DIR="${src}/resources/Icon.iconset"
545+
for SIZE in 16 32 128 256 512; do
546+
XSIZE="''${SIZE}x''${SIZE}"
547+
DST_PATH="$out/usr/share/icons/hicolor/''${XSIZE}/apps/"
548+
DOUBLE_SIZE_DST_PATH="$out/usr/share/icons/hicolor/''${XSIZE}@2/apps/"
549+
mkdir -p "$DST_PATH" "$DOUBLE_SIZE_DST_PATH"
550+
cp "''${SRC_ICONSET_DIR}/icon_''${XSIZE}.png" "''${DST_PATH}/codetracer.png"
551+
cp "''${SRC_ICONSET_DIR}/icon_''${XSIZE}@2x.png" "''${DOUBLE_SIZE_DST_PATH}/codetracer.png"
552+
done
553+
554+
cp "''${SRC_ICONSET_DIR}/icon_256x256.png" "$out/codetracer.png"
555+
485556
patch_binary "$out/bin/ct_unwrapped" || true
486557
patch_binary "$out/bin/db-backend-record" || true
487558
'';

0 commit comments

Comments
 (0)