-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.sh
executable file
·395 lines (323 loc) · 13.1 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
# build.sh - PrusaSlicer ARM build assistant
#
# This script will assist with installing dependencies, building PrusaSlicer
# and generating an AppImage on a compatible Raspberry Pi OS distribution and armhf/aarch64 system.
#
# How to use:
# $ ./build.sh
# Walks through the process to install dependencies, builds PrusaSlicer and packages the AppImage.
# $ ./build.sh automated
# Does not prompt (defaults to the latest PrusaSlicer version) and executes the steps above.
# $./build.sh dependencies
# Installs dependencies required to build PrusaSlicer and generate an AppImage and exits.
#
# Environmental variables
# BUILD_VERSION="version_2.6.0" - Applies only to automated builds, defaults to empty/latest if not set
#
# PrusaSlicer's GitHub API URL
LATEST_RELEASE="https://api.github.com/repos/prusa3d/PrusaSlicer/releases"
# Dependencies for building
DEPS_REQUIRED=(git wget sudo libgl1-mesa-dev libglu1-mesa-dev \
build-essential cmake python3-pip python3-dev python3-setuptools patchelf \
desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace fuse libgtk-3-dev \
m4 zstd screen ninja-build squashfs-tools zsync libboost-nowide-dev)
if [[ -v $STY ]] || [[ -z $STY ]]; then
echo -e '\033[1;36m**** The PrusaSlicer build process can take a long time. Screen or an alternative is advised for long-running terminal sessions. ****\033[0m'
fi
# $0 automated: Run in non-interactive mode. Skips questions and builds latest PrusaSlicer for ARM.
# $0 dependencies: Exit after installing dependencies, intended for container pre-imaging.
if [[ $1 == "automated" ]]; then
AUTO="yes"
elif [[ $1 == "dependencies" ]]; then
AUTO="yes"
DEPS_ONLY="yes"
fi
DPKG_ARCH="$(dpkg --print-architecture)"
echo "Greetings from the PrusaSlicer ARM (${DPKG_ARCH}) AppImage build assistant .."
case ${DPKG_ARCH} in
"armhf")
APPIMAGE_ARCH="armhf"
;;
"arm64")
APPIMAGE_ARCH="aarch64"
;;
"amd64")
APPIMAGE_ARCH="x86_64"
;;
*)
echo "Unknown architecture [arch: ${DPKG_ARCH}]."
echo "Please update the build assistant to add support."
exit 1
;;
esac
echo
echo '**********************************************************************************'
echo '* This utility needs your consent to install the following packages for building *'
echo '**********************************************************************************'
for dep in "${DEPS_REQUIRED[@]}"; do
echo "$dep"
done
echo "---"
if [[ -v AUTO ]]; then
REPLY="y"
else
read -p "May I use 'sudo apt-get install -y' to check for and install these dependencies? [N/y] " -n 1 -r
fi
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "$REPLY"
echo "Ok. Exiting here."
exit 1
fi
if ! sudo apt-get install -y "${DEPS_REQUIRED[@]}"; then
echo "Unable to run 'apt-get install' to install dependencies. Were there any errors displayed above?"
exit 1
fi
echo
echo "Dependencies installed. Proceeding with installation .."
echo
if ! hash appimage-builder >/dev/null; then
echo
if [[ -v AUTO ]]; then
REPLY="y"
else
read -p "appimage-builder and appimage-tool are not installed. They are required for the build process. May I install them? [N/y] " -n 1 -r
fi
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Ok. Exiting here."
exit 1
fi
echo
echo "Thanks, i'll get both installed .. "
if ! sudo wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${APPIMAGE_ARCH}.AppImage -O /usr/local/bin/appimagetool; then
echo "ERROR: Unable to download appimagetool for ${APPIMAGE_ARCH}."
exit 1
fi
sudo chmod +x /usr/local/bin/appimagetool
case "${DPKG_ARCH}" in
"armhf")
# 2023-02-06: Installing an older version to work around upstream issue where interpreter does not get placed into AppImages properly.
echo "Installing older version of appimage-builder to work around upstream issue for armhf .."
if ! pip3 install appimage-builder==0.9.2; then
echo "ERROR: Unable to install appimage-builder v0.9.2 for ${DPKG_ARCH} using pip3 .."
exit 1
fi
;;
"arm64")
if ! pip3 install git+https://github.com/AppImageCrafters/appimage-builder.git; then
echo "WARN: Unable to install appimage-builder using ${DPKG_ARCH} using pip3. Trying pipx method .."
if ! apt-get install -y pipx; then
echo "ERROR: Unable to install pipx for ${DPKG_ARCH} .."
exit 1
fi
if pipx install appimage-builder; then
# 12/15/2024: Downgrade due to segfault in _lief.so 0.16.0
# std::locale::_Impl::_M_remove_reference()
pipx runpip appimage-builder install lief==0.15.1
pipx ensurepath
export PATH="$PATH:/$(whoami)/.local/bin"
sed -i '/^\s*comp:/d'
else
echo "ERROR: Unable to install appimage-builder for ${DPKG_ARCH} using pipx .."
exit 1
fi
fi
;;
"amd64")
if ! apt-get install -y pipx; then
echo "ERROR: Unable to install pipx for ${DPKG_ARCH} .."
exit 1
fi
if pipx install appimage-builder; then
pipx ensurepath
export PATH="$PATH:/$(whoami)/.local/bin"
else
echo "ERROR: Unable to install appimage-builder for ${DPKG_ARCH} using pipx .."
exit 1
fi
;;
*)
echo "ERROR: Unable to install appimage-builder for ${DPKG_ARCH}. Please add support within build.sh."
exit 1
;;
esac
if ! hash appimage-builder >/dev/null; then
echo "ERROR: appimage-builder was installed but could not be found in your PATH: ${PATH}."
echo "ERROR: hint (to find where appimage-builder was installed to): find ~/ -name appimage-builder"
# Showing the user how to modify $PATH temporarily
# shellcheck disable=SC2016
echo 'ERROR: hint (to add the path, $HOME/.local/bin to $PATH temporarily): export PATH="$PATH:$HOME/.local/bin"'
echo "ERROR: Re-run ./$0 if using the above hints"
exit 1
fi
fi
if ! hash jq curl >/dev/null; then
echo
if [[ -v AUTO ]]; then
REPLY="y"
else
read -p "It looks like jq or curl are not installed. To get the latest version of PrusaSlicer, I need to install jq (to parse JSON output) and curl (to get information from GitHub). May I install these? [N/y] " -n 1 -r
fi
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Ok. Exiting here."
exit 1
else
echo
echo "Thanks, i'll get these installed .."
if ! sudo apt-get install -y curl jq; then
echo "Unable to install curl/jq. The error output might have some answers as to what went wrong (above)."
exit 1
fi
fi
fi
if [[ -v DEPS_ONLY ]]; then
echo "Dependencies have completed installation, exiting here."
exit 0
fi
if [[ -v AUTO ]]; then
REPLY="y"
else
read -p "May I use 'curl' and 'jq' to check for the latest PrusaSlicer version name? [N/y] " -n 1 -r
fi
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo
echo "Ok. Exiting here."
exit 1
else
echo
echo "Thanks! I will report back with the version i've found."
echo
fi
# Grab the latest upstream release version number
LATEST_VERSION="version_$(curl -SsL ${LATEST_RELEASE} | jq -r 'first | .tag_name | select(test("^version_[0-9]{1,2}\\.[0-9]{1,2}\\.[0-9]{1,2}\\-{0,1}(\\w+){0,1}$"))' | cut -d_ -f2)"
if [[ -v AUTO ]]; then
if [[ -n "${BUILD_VERSION}" ]]; then
REPLY="${BUILD_VERSION}"
else
REPLY=""
fi
else
read -p "The latest version appears to be: ${LATEST_VERSION} .. Would you like to enter a different version (like a git tag 'version_2.A.B' or commit '22d9fcb')? Or continue (leave blank)? " -r
fi
if [[ "${REPLY}" != "" ]]; then
echo
echo "Version will be set to ${REPLY}"
LATEST_VERSION="${REPLY}"
else
echo
echo "Okay, continuing with the version from the API."
fi
if [[ -z "${LATEST_VERSION}" ]]; then
echo "Could not determine the latest version."
echo
echo "Possible reasons for this error:"
echo "* Has release naming changed from previous conventions?"
echo "* Are curl and jq installed and working as expected?"
echo "${LATEST_VERSION}"
exit 1
else
echo "I'll be building PrusaSlicer using ${LATEST_VERSION}"
fi
echo
if [[ -v AUTO ]]; then
REPLY="y"
else
read -n 1 -p "The builder offers a choice between a minimal and full version (saving around 25MB). Building [a]ll versions is the default, but building with the (f)ull or (m)inimal version only is also possible. Please select a version (a)ll [default], (f)ull or (m)inimal? " -r
fi
case "${REPLY}" in
m|minimal)
APPIMAGE_BUILD_TYPE="minimal"
;;
f|full)
APPIMAGE_BUILD_TYPE="full"
;;
*)
APPIMAGE_BUILD_TYPE="minimal full"
;;
esac
echo
echo "Generating [${APPIMAGE_BUILD_TYPE}] build(s) for ${APPIMAGE_ARCH}"
echo
[[ -d "./PrusaSlicer" ]] || git clone https://github.com/prusa3d/PrusaSlicer --single-branch --branch "${LATEST_VERSION}" --depth 1 PrusaSlicer && \
cd PrusaSlicer && \
[[ -d "../patches/${LATEST_VERSION}" ]]; git apply -v ../patches/"${LATEST_VERSION}"/*; \
cd deps && \
mkdir -p build && \
cd build && \
cmake .. -DDEP_WX_GTK3=ON && \
cmake --build . && \
cd ../.. && \
mkdir -p build && \
cd build && \
rm -rf AppDir && \
cmake .. \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_PREFIX_PATH="$(pwd)/../deps/build/destdir/usr/local" \
-DSLIC3R_GTK=3 \
-DSLIC3R_OPENGL_ES=1 \
-DSLIC3R_PCH=OFF \
-DSLIC3R_STATIC=ON
cd ../..
for build_type in ${APPIMAGE_BUILD_TYPE}; do
cp -f "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}.yml" "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"
sed -i "s#%%VERSION%%#${LATEST_VERSION}#g" "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"
if [[ "${APPIMAGE_ARCH}" == "armhf" ]]; then
# 2023-03-06: Older appimage-builder does not have appdir and finds directory OK
if ! appimage-builder --recipe "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"; then
echo "Failed to generate AppImage. Please check log output."
exit 1;
fi
else
if [[ -e "/$(whoami)/.local/bin/appimage-builder" ]]; then
# detect pipx versions which are more recent and reject the comp: parameter
echo "comp: parameter removed from appimage"
sed -i '/^\s*comp:/d' "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"
fi
if ! appimage-builder --appdir ./PrusaSlicer/build/AppDir --recipe "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"; then
echo "Failed to generate AppImage. Please check log output."
exit 1;
fi
fi
rm -f "AppImageBuilder-${APPIMAGE_ARCH}-${build_type}-${LATEST_VERSION}.yml"
done
echo "Finished build process for PrusaSlicer and arch $(uname -m)."
echo "Here's some information to help with generating and posting a release on GitHub:"
cat <<EOF
${LATEST_VERSION}
PrusaSlicer-${LATEST_VERSION#version_} ARM AppImages
_Prusa Research has released their own [AppImages for ARM](https://github.com/prusa3d/PrusaSlicer/releases/tag/${LATEST_VERSION}). It is advisable to switch to these official builds for the best experience when/if available for your platform._
This release tracks PrusaSlicer's [upstream ${LATEST_VERSION}](https://github.com/prusa3d/PrusaSlicer/releases/tag/${LATEST_VERSION}). AppImages are built using appimage-builder (with PrusaSlicer's dependencies) for broader compatibility at the cost of an increased AppImage size.
### AppImage selection
Run the following in a terminal:
\`\`\`bash
pi@raspberry:~$ uname -m
aarch64
\`\`\`
If the command does not print aarch64 (or arm64), grab an \`armhf\` AppImage.
#### Architectures
##### armhf
armhf distributions are for 32-bit distributions, ex: \`PrusaSlicer-${LATEST_VERSION}-armhf.AppImage\`
##### arm64 / aarch64
These are for 64-bit distributions, ex: \`PrusaSlicer-${LATEST_VERSION}-aarch64.AppImage\`
### How do I run the AppImage?
##### Install dependencies
Raspberry Pi OS **Bookwoorm** users: You may need to set your locale to UTF-8 if an error occurs after launching. On the desktop: \`Preferences > Raspberry Pi Configuration > Localization > Set Locale > Character Set > UTF-8\`. Reboot when prompted.
Bookworm also needs the libfuse2 package:
sudo apt-get install -y libfuse2
For other Raspberry Pi OS distributions, more dependencies on the host may be needed. Run the following in a terminal to install them:
sudo apt-get install -y git cmake libboost-dev libboost-regex-dev libboost-filesystem-dev \\
libboost-thread-dev libboost-log-dev libboost-locale-dev libcurl4-openssl-dev build-essential \\
pkg-config libtbb-dev zlib1g-dev libcereal-dev libeigen3-dev libnlopt-cxx-dev \\
libudev-dev libopenvdb-dev libboost-iostreams-dev libgmpxx4ldbl libnlopt-dev \\
libdbus-1-dev imagemagick libgtk2.0-dev libgtk-3-dev libwxgtk3.0-gtk3-dev fuse libfuse2
After downloading the AppImage and installing dependencies, make the AppImage executable and run the AppImage to launch PrusaSlicer:
32-bit:
$ chmod +x PrusaSlicer-${LATEST_VERSION}-armhf.AppImage
$ ./PrusaSlicer-${LATEST_VERSION}-armhf.AppImage
64-bit:
$ chmod +x PrusaSlicer-${LATEST_VERSION}-aarch64.AppImage
$ ./PrusaSlicer-${LATEST_VERSION}-aarch64.AppImage
**\`Minimal versions\`** These AppImages include fewer dependencies to reduce size but may not be compatible with older distributions.
EOF