33# THIS SCRIPT IS TO BE RUN IN OUR DEV SHELL
44
55# The goal of this script is to prepare an `AppDir` (see the spec below)
6- # and then to launch tha appimagetool to create an AppImage
6+ # and then to launch the appimagetool to create an AppImage.
77#
88# AppDir spec: https://github.com/AppImage/AppImageSpec/blob/master/draft.md#appdir
99# appimagetool: https://github.com/AppImage/appimagetool
10-
11- set -e
10+ echo " ============================"
11+ echo " AppImage build start"
12+ echo " ============================"
13+ set -euo pipefail
1214
1315cleanup () {
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
1823trap cleanup EXIT
@@ -23,282 +28,60 @@ export ROOT_PATH
2328APP_DIR=" ${ROOT_PATH} /squashfs-root"
2429export APP_DIR
2530
26- if [ -e " ${ROOT_PATH} " /CodeTracer.AppImage ]; then
27- rm -rf " ${ROOT_PATH} " /CodeTracer.AppImage
31+ if [ -e " ${ROOT_PATH} /CodeTracer.AppImage" ]; then
32+ chmod -f u+rw " ${ROOT_PATH} /CodeTracer.AppImage" > /dev/null 2>&1 || true
33+ rm -f " ${ROOT_PATH} /CodeTracer.AppImage"
2834fi
2935
30- mkdir " ${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
40+ mkdir -p " ${APP_DIR} "
3141
32- # This is the env var which essentially controls where we'll put our
33- # compiled files/static resources
42+ # This environment variable controls where build artifacts and static resources end up.
3443export NIX_CODETRACER_EXE_DIR=" ${APP_DIR} "
3544
36- mkdir -p " ${APP_DIR} " /bin
37- mkdir -p " ${APP_DIR} " /src
38- mkdir -p " ${APP_DIR} " /lib
39- mkdir -p " ${APP_DIR} " /views
40-
41- # Install Ruby
42- bash " ${ROOT_PATH} " /appimage-scripts/install_ruby.sh
43-
44- cat << 'EOF ' > "${APP_DIR}/bin/ruby"
45- #!/usr/bin/env bash
46-
47- HERE="${HERE:-..}"
48-
49- # TODO: This includes references to x86_64. What about aarch6?
50- export RUBYLIB="${HERE}/ruby/lib/ruby/3.3.0:${HERE}/ruby/lib/ruby/3.3.0/x86_64-linux:${RUBYLIB}"
51-
52- "${HERE}/ruby/bin/ruby" "$@"
53-
54- EOF
55-
56- # ruby recorder
57- cp -Lr " ${ROOT_PATH} /libs/codetracer-ruby-recorder" " ${APP_DIR} /"
58-
5945CURRENT_NIX_SYSTEM=$( nix eval --impure --raw --expr ' builtins.currentSystem' )
60- CURRENT_ARCH=$( uname -m)
61-
62- # Copy over needed Nim libs
63- # cp -r "${ROOT_PATH}"/libs/nim-appimage-deps/libpcre.so.1 "${APP_DIR}/lib"
64-
65- # Try and build dependencies, in case we don't have them in the nix-store
66- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .sqlite"
67-
68- SQLITE=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .sqlite.out" )
69- cp -L " ${SQLITE} " /lib/libsqlite3.so.0 " ${APP_DIR} " /lib
70- cp -L " ${SQLITE} " /lib/libsqlite3.so " ${APP_DIR} " /lib
71-
72- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .pcre"
46+ APPIMAGE_PAYLOAD=$( nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .appimagePayload" --no-link --print-out-paths | tail -n1)
7347
74- PCRE=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .pcre.out" )
75- cp -L " ${PCRE} " /lib/libpcre.so.1 " ${APP_DIR} " /lib
48+ cp -Lr " ${APPIMAGE_PAYLOAD} /." " ${APP_DIR} /"
7649
77- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .libzip"
78-
79- LIBZIP=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .libzip.out" )
80- cp -L " ${LIBZIP} " /lib/libzip.so.5 " ${APP_DIR} " /lib
81-
82- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .curl"
83-
84- OPENSSL=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .openssl.out" )
85- cp -L " ${OPENSSL} " /lib/libssl.so.3 " ${APP_DIR} " /lib
86- cp -L " ${OPENSSL} " /lib/libssl.so " ${APP_DIR} " /lib
87- cp -L " ${OPENSSL} " /lib/libcrypto.so " ${APP_DIR} " /lib
88- cp -L " ${OPENSSL} " /lib/libcrypto.so.3 " ${APP_DIR} " /lib
89-
90- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .libuv"
91- LIBUV=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .libuv.out" )
92- cp -L " ${LIBUV} " /lib/libuv.so.1 " ${APP_DIR} " /lib
50+ chmod -R u+rwX " ${APP_DIR} "
9351
9452# Copy over electron
95- # bash "${ROOT_PATH}" /appimage-scripts/install_electron_nix.sh
96- bash " ${ROOT_PATH} " /appimage-scripts/install_electron.sh
53+ # bash "${ROOT_PATH}/appimage-scripts/install_electron_nix.sh"
54+ bash " ${ROOT_PATH} /appimage-scripts/install_electron.sh"
9755
9856# Setup node deps
99- bash " ${ROOT_PATH} " /appimage-scripts/setup_node_deps.sh
100-
101- # Build our css files
102- bash " ${ROOT_PATH} " /appimage-scripts/build_css.sh
103-
104- # Build/setup nim-based files
105- bash " ${ROOT_PATH} " /appimage-scripts/build_with_nim.sh
106-
107- cat << 'EOF ' > "${APP_DIR}/bin/ct"
108- #!/usr/bin/env bash
109-
110- HERE=${HERE:-$(dirname "$(readlink -f "${0}")")}
111-
112- # TODO: This includes references to x86_64. What about aarch64?
113-
114- exec "${HERE}"/bin/ct_unwrapped "$@"
115-
116- EOF
117-
118- # Build/setup db-backend
119- bash " ${ROOT_PATH} " /appimage-scripts/build_db_backend.sh
120-
121- # Build/setup backend-manager
122- bash " ${ROOT_PATH} " /appimage-scripts/build_backend_manager.sh
123-
124- # Noir
125- cp -Lr " ${ROOT_PATH} /src/links/nargo" " ${APP_DIR} /bin/"
126- chmod +x " ${APP_DIR} /bin/nargo"
127-
128- # Wazero
129- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .wazero"
130-
131- WAZERO=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .wazero.out" )
132- cp -L " ${WAZERO} " /bin/wazero " ${APP_DIR} " /bin
133-
134- # cargo-stylus
135- nix build " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .cargo-stylus"
136-
137- CARGO_STYLUS=$( nix eval --raw " ${ROOT_PATH} #packages.${CURRENT_NIX_SYSTEM} .cargo-stylus.out" )
138- cp -L " ${CARGO_STYLUS} " /bin/cargo-stylus " ${APP_DIR} " /bin
139-
140- # ctags
141- cp -Lr " ${ROOT_PATH} /src/links/ctags" " ${APP_DIR} /bin/"
142- chmod +x " ${APP_DIR} /bin/ctags"
143- # We want splitting
144- # shellcheck disable=SC2046
145- cp -n $( lddtree -l " ${APP_DIR} /bin/ctags" | grep -v glibc | grep /nix) " ${APP_DIR} " /lib
146-
147-
148- # curl
149- cp -Lr " ${ROOT_PATH} /src/links/curl" " ${APP_DIR} /bin/"
150- chmod +x " ${APP_DIR} /bin/curl"
151- # shellcheck disable=SC2046
152- cp -n $( lddtree -l " ${APP_DIR} /bin/curl" | grep -v glibc | grep /nix) " ${APP_DIR} " /lib
153- ls -al " ${APP_DIR} " /lib
154-
155-
156- # node
157- cp -Lr " ${ROOT_PATH} /src/links/node" " ${APP_DIR} /bin/"
158- chmod +x " ${APP_DIR} /bin/node"
159-
160- # shellcheck disable=SC2046
161- cp -n $( lddtree -l " ${APP_DIR} /bin/node" | grep -v glibc | grep /nix) " ${APP_DIR} " /lib
162-
163- # shellcheck disable=SC2046
164- cp -n $( lddtree -l " ${APP_DIR} /bin/cargo-stylus" | grep -v glibc | grep /nix) " ${APP_DIR} " /lib
165-
166- chmod -R +x " ${APP_DIR} /bin"
167- chmod -R +x " ${APP_DIR} /electron"
168-
169- chmod -R 777 " ${APP_DIR} "
170-
171- # cp "${ROOT_PATH}"/libs/codetracer-ruby-recorder/src/*.rb "${APP_DIR}/src/"
172-
173- cp " ${ROOT_PATH} /src/helpers.js" " ${APP_DIR} /src/helpers.js"
174- cp " ${ROOT_PATH} /src/helpers.js" " ${APP_DIR} /helpers.js"
175-
176- cp " ${ROOT_PATH} /src/frontend/index.html" " ${APP_DIR} /src/index.html"
177- cp " ${ROOT_PATH} /src/frontend/index.html" " ${APP_DIR} /index.html"
178-
179- cp " ${ROOT_PATH} /src/frontend/subwindow.html" " ${APP_DIR} /subwindow.html"
180- cp " ${ROOT_PATH} /src/frontend/subwindow.html" " ${APP_DIR} /src/subwindow.html"
181-
182- cp " ${ROOT_PATH} /views/server_index.ejs" " ${APP_DIR} /views/server_index.ejs"
183-
184- rm -rf " ${APP_DIR} /config"
185- rm -rf " ${APP_DIR} /public"
186- cp -Lr " ${ROOT_PATH} /src/config" " ${APP_DIR} /config"
187-
188- # Enable the installation prompt
189- sed -i " s/skipInstall.*/skipInstall: false/g" " ${APP_DIR} /config/default_config.yaml"
57+ bash " ${ROOT_PATH} /appimage-scripts/setup_node_deps.sh"
19058
19159cp -Lr " ${ROOT_PATH} /src/public" " ${APP_DIR} /public"
19260chmod -R +wr " ${APP_DIR} /public"
61+ mkdir -p " ${APP_DIR} /public/dist"
62+ cp -Lr " ${ROOT_PATH} /src/public/dist/frontend_bundle.js" " ${APP_DIR} /frontend_bundle.js"
19363
194- cp -Lr " ${ROOT_PATH} /src/public/dist/frontend_bundle.js" " ${APP_DIR} "
19564
196- # Create AppRun script
197- cat << 'EOF ' > "${APP_DIR}/AppRun"
198- #!/usr/bin/env bash
199-
200- export HERE=$(dirname "$(readlink -f "${0}")")
201-
202- # TODO: This includes references to x86_64. What about aarch64?
203- export LINKS_PATH_DIR=$HERE
204- export PATH="${HERE}/bin:${PATH}"
205- export CODETRACER_RUBY_RECORDER_PATH="${HERE}/codetracer-ruby-recorder/gems/codetracer-pure-ruby-recorder/bin/codetracer-pure-ruby-recorder"
206-
207- exec ${HERE}/bin/ct "$@"
208- EOF
209-
210- chmod +x " ${APP_DIR} /AppRun"
211-
212- # Copy over desktop file
213- cp " ${ROOT_PATH} /resources/codetracer.desktop" " ${APP_DIR} /"
214-
215- # Copy over resources
216- cp -Lr " ${ROOT_PATH} " /resources " ${APP_DIR} "
217-
218- # We need to copy over the CodeTracer icons. Here is what the spec says:
219- #
220- # SHOULD contain icon files below usr/share/icons/hicolor following the Icon
221- # Theme Specification for the icon identifier as set in the Icon= key of the
222- # $APPNAME.desktop file. If present, these icon files SHOULD be given
223- # preference as the icon being used to represent the AppImage.
224-
225- SRC_ICONSET_DIR=" ${ROOT_PATH} /resources/Icon.iconset"
226-
227- # TODO: discover these dinamically perhaps
228- for SIZE in 16 32 128 256 512
229- do
230- XSIZE=" ${SIZE} x${SIZE} "
231- DST_PATH=" ${APP_DIR} /usr/share/icons/hicolor/${XSIZE} /apps/"
232- DOUBLE_SIZE_DST_PATH=" ${APP_DIR} /usr/share/icons/hicolor/${XSIZE} @2/apps/"
233- mkdir -p " ${DST_PATH} " " ${DOUBLE_SIZE_DST_PATH} "
234- cp " ${SRC_ICONSET_DIR} /icon_${XSIZE} .png" " ${DST_PATH} /codetracer.png"
235- cp " ${SRC_ICONSET_DIR} /icon_${XSIZE} @2x.png" " ${DOUBLE_SIZE_DST_PATH} /codetracer.png"
236- done
237-
238- # From the spec:
239- #
240- # MAY contain an $APPICON.svg, $APPICON.svgz or $APPICON.png file in its root
241- # directory with $APPICON being the icon identifier as set in the Icon= key
242- # of the $APPNAME.desktop file. If present and no icon files matching the
243- # icon identifier present below usr/share/icons/hicolor, this icon SHOULD
244- # be given preference as the icon being used to represent the AppImage.
245- # If a PNG file, the icon SHOULD be of size 256x256, 512x512, or 1024x1024 pixels.
246- cp " ${ROOT_PATH} /resources/Icon.iconset/icon_256x256.png" " ${APP_DIR} /codetracer.png"
65+ chmod -R +x " ${APP_DIR} /electron"
24766
248- if [[ " $CURRENT_ARCH " == " aarch64" ]]; then
67+ CURRENT_ARCH=$( uname -m)
68+ if [[ " ${CURRENT_ARCH} " == " aarch64" ]]; then
24969 INTERPRETER_PATH=/lib/ld-linux-aarch64.so.1
25070else
25171 INTERPRETER_PATH=/lib64/ld-linux-x86-64.so.2
25272fi
25373
254- # Patchelf the executable's interpreter
255- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/ct_unwrapped
256- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/db-backend
257- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/db-backend-record
258- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/backend-manager
259- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/nargo
260- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/wazero
261- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/ctags
262- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/curl
263- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/cargo-stylus
264- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /bin/node
265- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${APP_DIR} " /ruby/bin/ruby
266-
267- # Clear up the executable's rpath
268- patchelf --remove-rpath " ${APP_DIR} " /bin/ct_unwrapped
269- patchelf --remove-rpath " ${APP_DIR} " /bin/db-backend
270- patchelf --remove-rpath " ${APP_DIR} " /bin/db-backend-record
271- patchelf --remove-rpath " ${APP_DIR} " /bin/backend-manager
272- patchelf --remove-rpath " ${APP_DIR} " /bin/nargo
273- patchelf --remove-rpath " ${APP_DIR} " /bin/wazero
274- patchelf --remove-rpath " ${APP_DIR} " /bin/ctags
275- patchelf --remove-rpath " ${APP_DIR} " /bin/curl
276- patchelf --remove-rpath " ${APP_DIR} " /bin/node
277- patchelf --remove-rpath " ${APP_DIR} " /ruby/bin/ruby
278-
279- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/node
280- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/ct_unwrapped
281- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/db-backend
282- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/db-backend-record
283- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/backend-manager
284- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/nargo
285- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/wazero
286- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/ctags
287- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/curl
288- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /bin/node
289- patchelf --set-rpath " \$ ORIGIN/../lib" " ${APP_DIR} " /ruby/bin/ruby
290-
291- APPIMAGE_ARCH=$CURRENT_ARCH
292- if [[ " $APPIMAGE_ARCH " == " aarch64" ]]; then
293- # The appimagetool has its own convention for specifying the ARM64 arch
74+ APPIMAGE_ARCH=${CURRENT_ARCH}
75+ if [[ " ${APPIMAGE_ARCH} " == " aarch64" ]]; then
76+ # The appimagetool has its own convention for specifying the ARM64 arch.
29477 APPIMAGE_ARCH=arm_aarch64
29578fi
29679
29780# Use AppImage tool to create AppImage itself
298- ARCH=$APPIMAGE_ARCH appimagetool " ${APP_DIR} " CodeTracer.AppImage
81+ ARCH=${ APPIMAGE_ARCH} appimagetool " ${APP_DIR} " CodeTracer.AppImage
29982
300- patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${ROOT_PATH} " /CodeTracer.AppImage
301- patchelf --remove-rpath " ${ROOT_PATH} " /CodeTracer.AppImage
83+ patchelf --set-interpreter " ${INTERPRETER_PATH} " " ${ROOT_PATH} /CodeTracer.AppImage"
84+ patchelf --remove-rpath " ${ROOT_PATH} /CodeTracer.AppImage"
30285
30386echo " ============================"
30487echo " AppImage successfully built!"
0 commit comments