Skip to content

Commit 5aeea1d

Browse files
committed
Use only static binaries in AppImage
1 parent afc3f7b commit 5aeea1d

File tree

3 files changed

+128
-15
lines changed

3 files changed

+128
-15
lines changed

ci/build-static-binutils.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#! /bin/bash
2+
3+
set -e
4+
set -x
5+
6+
INSTALL_DESTDIR="$1"
7+
8+
if [[ "$INSTALL_DESTDIR" == "" ]]; then
9+
echo "Error: build dir $BUILD_DIR does not exist" 1>&2
10+
exit 1
11+
fi
12+
13+
# support cross-compilation for 32-bit ISAs
14+
case "$ARCH" in
15+
"x86_64"|"amd64")
16+
;;
17+
"i386"|"i586"|"i686")
18+
export CFLAGS="-m32"
19+
export CXXFLAGS="-m32"
20+
;;
21+
*)
22+
echo "Error: unsupported architecture: $ARCH"
23+
exit 1
24+
;;
25+
esac
26+
27+
# use RAM disk if possible
28+
if [ "$CI" == "" ] && [ -d /dev/shm ]; then
29+
TEMP_BASE=/dev/shm
30+
else
31+
TEMP_BASE=/tmp
32+
fi
33+
34+
cleanup () {
35+
if [ -d "$BUILD_DIR" ]; then
36+
rm -rf "$BUILD_DIR"
37+
fi
38+
}
39+
40+
trap cleanup EXIT
41+
42+
BUILD_DIR=$(mktemp -d -p "$TEMP_BASE" linuxdeploy-build-XXXXXX)
43+
44+
pushd "$BUILD_DIR"
45+
46+
# fetch source code
47+
wget https://ftp.gnu.org/gnu/binutils/binutils-2.35.tar.xz -O- | tar xJ --strip-components=1
48+
49+
# configure static build
50+
# inspired by https://github.com/andrew-d/static-binaries/blob/master/binutils/build.sh
51+
./configure --prefix=/usr --disable-nls --enable-static-link --disable-shared-plugins --disable-dynamicplugin --disable-tls --disable-pie
52+
53+
# citing the script linked above: "This strange dance is required to get things to be statically linked."
54+
make -j "$(nproc)"
55+
make clean
56+
make -j "$(nproc)" LDFLAGS="-all-static"
57+
58+
# install into user-specified destdir
59+
make install DESTDIR="$(readlink -f "$INSTALL_DESTDIR")"

ci/build-static-patchelf.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#! /bin/bash
2+
3+
set -e
4+
set -x
5+
6+
INSTALL_DESTDIR="$1"
7+
8+
if [[ "$INSTALL_DESTDIR" == "" ]]; then
9+
echo "Error: build dir $BUILD_DIR does not exist" 1>&2
10+
exit 1
11+
fi
12+
13+
# support cross-compilation for 32-bit ISAs
14+
case "$ARCH" in
15+
"x86_64"|"amd64")
16+
;;
17+
"i386"|"i586"|"i686")
18+
export CFLAGS="-m32"
19+
export CXXFLAGS="-m32"
20+
;;
21+
*)
22+
echo "Error: unsupported architecture: $ARCH"
23+
exit 1
24+
;;
25+
esac
26+
27+
# use RAM disk if possible
28+
if [ "$CI" == "" ] && [ -d /dev/shm ]; then
29+
TEMP_BASE=/dev/shm
30+
else
31+
TEMP_BASE=/tmp
32+
fi
33+
34+
cleanup () {
35+
if [ -d "$BUILD_DIR" ]; then
36+
rm -rf "$BUILD_DIR"
37+
fi
38+
}
39+
40+
trap cleanup EXIT
41+
42+
BUILD_DIR=$(mktemp -d -p "$TEMP_BASE" linuxdeploy-build-XXXXXX)
43+
44+
pushd "$BUILD_DIR"
45+
46+
# fetch source code
47+
git clone https://github.com/NixOS/patchelf.git .
48+
49+
# cannot use -b since it's not supported in really old versions of git
50+
git checkout 0.8
51+
52+
# prepare configure script
53+
./bootstrap.sh
54+
55+
# configure static build
56+
env LDFLAGS="-static -static-libgcc -static-libstdc++" ./configure --prefix=/usr
57+
58+
# build binary
59+
make -j "$(nproc)"
60+
61+
# install into user-specified destdir
62+
make install DESTDIR="$INSTALL_DESTDIR"

ci/build.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,13 @@ ctest -V --no-tests=error
4343

4444
make install DESTDIR=AppDir
4545

46-
strip_path=$(which strip)
46+
# build patchelf
47+
"$REPO_ROOT"/ci/build-static-patchelf.sh "$(readlink -f out/)"
48+
patchelf_path="$(readlink -f out/usr/bin/patchelf)"
4749

48-
if [ "$ARCH" == "i386" ]; then
49-
# download i386 strip for i386 AppImage
50-
# https://github.com/linuxdeploy/linuxdeploy/issues/59
51-
wget http://security.ubuntu.com/ubuntu/pool/main/b/binutils/binutils-multiarch_2.24-5ubuntu14.2_i386.deb
52-
echo "0106f170cebf5800e863a558cad039e4f16a76d3424ae943209c3f6b0cacd511 binutils-multiarch_2.24-5ubuntu14.2_i386.deb" | sha256sum -c
53-
wget http://security.ubuntu.com/ubuntu/pool/main/b/binutils/binutils-multiarch-dev_2.24-5ubuntu14.2_i386.deb
54-
echo "ed9ca4fbbf492233228f79fae6b349a2ed2ee3e0927bdc795425fccf5fae648e binutils-multiarch-dev_2.24-5ubuntu14.2_i386.deb" | sha256sum -c
55-
dpkg -x binutils-multiarch_2.24-5ubuntu14.2_i386.deb out/
56-
dpkg -x binutils-multiarch-dev_2.24-5ubuntu14.2_i386.deb out/
57-
rm binutils-multiarch*.deb
58-
strip_path=$(readlink -f out/usr/bin/strip)
59-
export LD_LIBRARY_PATH=$(readlink -f out/usr/lib)
60-
fi
50+
# build custom strip
51+
"$REPO_ROOT"/ci/build-static-binutils.sh "$(readlink -f out/)"
52+
strip_path="$(readlink -f out/usr/bin/strip)"
6153

6254
export UPD_INFO="gh-releases-zsync|linuxdeploy|linuxdeploy-plugin-qt|continuous|linuxdeploy-plugin-qt-$ARCH.AppImage"
6355

@@ -66,7 +58,7 @@ chmod +x linuxdeploy*.AppImage
6658
./linuxdeploy-"$ARCH".AppImage --appdir AppDir \
6759
-d "$REPO_ROOT"/resources/linuxdeploy-plugin-qt.desktop \
6860
-i "$REPO_ROOT"/resources/linuxdeploy-plugin-qt.svg \
69-
-e $(which patchelf) \
61+
-e "$patchelf_path" \
7062
-e "$strip_path" \
7163
--output appimage
7264

0 commit comments

Comments
 (0)