Skip to content

Commit

Permalink
Improve all build related scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAssassin committed Dec 14, 2020
1 parent 6751f31 commit be4b51e
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 156 deletions.
48 changes: 0 additions & 48 deletions build-appdir.sh

This file was deleted.

72 changes: 72 additions & 0 deletions ci/build-appdir.sh
@@ -0,0 +1,72 @@
#!/bin/bash

set -e
set -x
set -o functrace

if [[ "$3" == "" ]]; then
echo "Usage: bash $0 <repo root> <install-prefix> <appimagetool AppDir>"
exit 2
fi

# using shift makes adding/removing parameters easier
repo_root="$1"
shift
install_prefix="$1"
shift
appimagetool_appdir="$1"

if [[ ! -d "$install_prefix" ]]; then
echo "Error: could not find install-prefix directory: $install_prefix"
exit 3
fi

if [[ ! -d "$repo_root" ]]; then
echo "Error: could not find repo root directory: $repo_root"
exit 4
fi

if [[ -d "$appimagetool_appdir" ]]; then
echo "Warning: removing existing appimagetool AppDir: $appimagetool_appdir"
rm -rf "$appimagetool_appdir"
fi

# Run make install only for the appimagetool component to deploy appimagetools files to
# the $appimagetool_appdir
DESTDIR="$appimagetool_appdir" cmake -DCOMPONENT=appimagetool -P cmake_install.cmake

mkdir -p "$appimagetool_appdir"/usr/lib/appimagekit/

# Copy AppDir specific files
cp "$repo_root"/resources/AppRun "$appimagetool_appdir"
cp "$install_prefix"/usr/lib/appimagekit/mksquashfs "$appimagetool_appdir"/usr/lib/appimagekit/

# prefer binaries from /deps, if available
export PATH=/deps/bin:"$PATH"
cp "$(which desktop-file-validate)" "$appimagetool_appdir"/usr/bin/
cp "$(which zsyncmake)" "$appimagetool_appdir"/usr/bin/

cp "$repo_root"/resources/appimagetool.desktop "$appimagetool_appdir"
cp "$repo_root"/resources/appimagetool.png "$appimagetool_appdir"/appimagetool.png
cp "$appimagetool_appdir"/appimagetool.png "$appimagetool_appdir"/.DirIcon

if [ -d /deps/ ]; then

This comment has been minimized.

Copy link
@probonopd

probonopd May 1, 2022

Member

@TheAssassin do you remember what the thinking behind /deps was? Where is it supposed to be coming from? What creates it? Is it still being used?

This comment has been minimized.

Copy link
@TheAssassin

TheAssassin May 1, 2022

Author Member

Yes. AppImageBuild. The scripts in AppImageBuild. Yes.

This comment has been minimized.

Copy link
@probonopd

probonopd May 1, 2022

Member

Uh. I didn't even know AppImageBuild was a thing. This has become complicated.
We now have what I think are pretty neatly built (on Alpine using musl libc) static binaries that we could use, which would save us a lot of headaches:
https://github.com/probonopd/static-tools/releases/tag/continuous

Where would be the best place to put them into /deps?

If we manage to get the AppImage runtime linked statically, then we might even be able to do away with the CentOS stuff... and libffi...

This comment has been minimized.

Copy link
@TheAssassin

TheAssassin May 1, 2022

Author Member

There is no point in putting any of these tools into the AppImageBuild Docker containers. And this is not the right place for a discussion about build system modifications. It's a random comment in a random commit.

This comment has been minimized.

Copy link
@probonopd

probonopd May 1, 2022

Member

True. Let's discuss at #1193.

# deploy GLib
mkdir -p "$appimagetool_appdir"/usr/lib/
cp /deps/lib/lib*.so* "$appimagetool_appdir"/usr/lib/

# libffi is a runtime dynamic dependency
# see this thread for more information on the topic:
# https://mail.gnome.org/archives/gtk-devel-list/2012-July/msg00062.html
if [ "$ARCH" == "x86_64" ]; then
cp "$(ldconfig -p | grep libffi.so.6 | grep x86-64 | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/
elif [ "$ARCH" == "i686" ]; then
cp "$(ldconfig -p | grep libffi.so.6 | grep i386 | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/
elif [ "$ARCH" == "armhf" ]; then
cp "$(ldconfig -p | grep libffi.so.6 | grep arm | grep hf | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/
elif [ "$ARCH" == "aarch64" ]; then
cp "$(ldconfig -p | grep libffi.so.6 | grep aarch64 | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/
else
echo "WARNING: unknown architecture, not bundling libffi"
fi
fi
19 changes: 0 additions & 19 deletions ci/build-appimage.sh

This file was deleted.

97 changes: 97 additions & 0 deletions ci/build-binaries-and-appimage.sh
@@ -0,0 +1,97 @@
#! /bin/bash

set -e
set -x
set -o functrace

# make sure the prebuilt libraries in the container will be found
# (in case we're building in an AppImageBuild container)
export LD_LIBRARY_PATH=/deps/lib:"$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH=/deps/lib/pkgconfig/
export PATH=/deps/bin:"$PATH"

# note: signing is not working at the moment
# see ci-build.sh for more information
echo "$KEY" | md5sum

# we always build in a temporary directory
# use RAM disk if possible
if [ -d /dev/shm ] && mount | grep /dev/shm | grep -v -q noexec; then
TEMP_BASE=/dev/shm
elif [ -d /docker-ramdisk ]; then
TEMP_BASE=/docker-ramdisk
else
TEMP_BASE=/tmp
fi

BUILD_DIR="$(mktemp -d -p "$TEMP_BASE" AppImageKit-build-XXXXXX)"

cleanup () {
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi
}

trap cleanup EXIT

REPO_ROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)"
OLD_CWD="$(readlink -f .)"

pushd "$BUILD_DIR"

# configure build and generate build files
cmake "$REPO_ROOT" \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING=ON \
-DAPPIMAGEKIT_PACKAGE_DEBS=ON

# run build
if [[ "$CI" != "" ]]; then
nproc="$(nproc)"
else
nproc="$(nproc --ignore=1)"
fi

make -j"$nproc"

# install so-far-built binaries into some prefix
# this way, we can test them, use them to build the AppDir later, copy stuff from there into said AppDir, ...
install_prefix="install-prefix"
make install DESTDIR="$install_prefix"

# print first few bytes in runtime
# allows checking whether the magic bytes are in place
xxd src/runtime | head -n1

# strip everything *but* runtime
find "$install_prefix"/usr/bin/ -not -iname runtime -print -exec "$STRIP" "{}" \; 2>/dev/null

# more debugging
ls -lh "$install_prefix"/usr/bin
for FILE in "$install_prefix"/usr/bin/*; do
echo "$FILE"
ldd "$FILE" || true
done

# continue building AppDir
appdir="appimagetool.AppDir"
bash "$REPO_ROOT"/ci/build-appdir.sh "$REPO_ROOT" "$install_prefix" "$appdir"

# list result
ls -lh
find "$install_prefix"

# test built appimagetool
"$REPO_ROOT"/ci/test-appimagetool.sh "$REPO_ROOT" "$install_prefix"/usr/bin/appimagetool

# seems to work -- let's build an AppImage
# we start by putting the rest of the files into the AppDir

"$appdir"/AppRun ./appimagetool.AppDir/ -v \
-u "gh-releases-zsync|AppImage|AppImageKit|continuous|appimagetool-$ARCH.AppImage.zsync" \
appimagetool-"$ARCH".AppImage

mv appimagetool-"$ARCH".AppImage "$OLD_CWD"
mv "$install_prefix"/usr/lib/appimagekit/runtime "$OLD_CWD"
mv "$install_prefix"/usr/bin/* "$OLD_CWD"
13 changes: 0 additions & 13 deletions ci/build-binaries.sh

This file was deleted.

48 changes: 48 additions & 0 deletions ci/build-in-docker.sh
@@ -0,0 +1,48 @@
#! /bin/bash

if [[ "$DIST" == "" ]] || [[ "$ARCH" == "" ]]; then
echo "Usage: env ARCH=... DIST=... bash $0"
exit 1
fi

set -x
set -e

cd "$(readlink -f "$(dirname "$0")")"

# sets variables $image, $dockerfile
source build-docker-image.sh

# figure out which build script to use
if [[ "$BUILD_LITE" == "" ]]; then
build_script=build.sh
else
build_script=build-lite.sh
fi

DOCKER_OPTS=()
# fix for https://stackoverflow.com/questions/51195528/rcc-error-in-resource-qrc-cannot-find-file-png
if [ "$CI" != "" ]; then
DOCKER_OPTS+=("--security-opt" "seccomp:unconfined")
fi

# only if there's more than 3G of free space in RAM, we can build in a RAM disk
if [[ "$GITHUB_ACTIONS" != "" ]]; then
echo "Building on GitHub actions, which does not support --tmpfs flag -> building on regular disk"
elif [[ "$(free -m | grep "Mem:" | awk '{print $4}')" -gt 3072 ]]; then
echo "Host system has enough free memory -> building in RAM disk"
DOCKER_OPTS+=("--tmpfs /docker-ramdisk:exec,mode=777")
else
echo "Host system does not have enough free memory -> building on regular disk"
fi

# run the build with the current user to
# a) make sure root is not required for builds
# b) allow the build scripts to "mv" the binaries into the /out directory
uid="$(id -u)"
# run build
docker run -e DIST -e ARCH -e GITHUB_RUN_NUMBER -e GITHUB_RUN_ID --rm -i --user "$uid" \
"${DOCKER_OPTS[@]}" -v "$(readlink -f ..):/ws" \
"$image" \
bash -xc "export CI=1 && cd /ws && source ci/$build_script"

0 comments on commit be4b51e

Please sign in to comment.