Skip to content

Commit a65a571

Browse files
committed
Fix chroot-based build setup
1 parent 656fed2 commit a65a571

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed

BUILD.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ To specify commands that should be run, use the established `--` to distinguish
6464
# fish
6565
> env ARCH=<arch> scripts/create-build-container.sh -u $(id -u):(id -g) -- bash some-script.sh
6666
```
67+
68+
## chroot-based environment
69+
70+
The chroot-based environment is designed for people who really do not want to use containers and/or run on systems that do not support such an environment (e.g., FreeBSD).
71+
72+
To run a build, use the following command:
73+
74+
```sh
75+
> env ARCHITECTURE=<arch> chroot/chroot_build.sh
76+
```

chroot/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if ! command -v apk; then
88
fi
99

1010
apk update
11-
apk add alpine-sdk util-linux strace file autoconf automake libtool xz
11+
apk add alpine-sdk util-linux strace file autoconf automake libtool xz bash
1212

1313
# Build static libfuse3 with patch for https://github.com/AppImage/type2-runtime/issues/10
1414
apk add eudev-dev gettext-dev linux-headers meson # From https://git.alpinelinux.org/aports/tree/main/fuse3/APKBUILD

chroot/chroot_build.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
#!/bin/sh
1+
#! /bin/bash
22

33
set -ex
44

5+
# build in a temporary directory
6+
# this makes sure that subsequent runs do not influence each other
7+
# also makes cleaning up easier: just dump the entire directory
8+
tempdir="$(mktemp -d)"
9+
10+
# need to memorize the repository root directory's path so that we can copy files from it
11+
repo_root_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"/..
12+
13+
# cleanup takes care of unmounting and removing all downloaded files
14+
cleanup() {
15+
sudo umount "$tempdir"/miniroot/{dev,proc,sys}
16+
sudo rm -rf "$tempdir"
17+
}
18+
trap cleanup EXIT
19+
20+
cd "$tempdir"
21+
522
#############################################
623
# Download and extract minimal Alpine system
724
#############################################
825

926
wget "http://dl-cdn.alpinelinux.org/alpine/v3.17/releases/${ARCHITECTURE}/alpine-minirootfs-3.17.2-${ARCHITECTURE}.tar.gz"
10-
sudo rm -rf ./miniroot true # Clean up from previous runs
1127
mkdir -p ./miniroot
1228
cd ./miniroot
1329
sudo tar xf ../alpine-minirootfs-*-"${ARCHITECTURE}".tar.gz
@@ -17,8 +33,8 @@ cd -
1733
# Prepare chroot
1834
#############################################
1935

20-
sudo cp -r ./src miniroot/src
21-
sudo cp -r ./patches miniroot/patches
36+
sudo cp -r "$repo_root_dir"/src miniroot/src
37+
sudo cp -r "$repo_root_dir"/patches miniroot/patches
2238

2339
sudo mount -o bind /dev miniroot/dev
2440
sudo mount -t proc none miniroot/proc
@@ -31,33 +47,27 @@ sudo cp -p /etc/resolv.conf miniroot/etc/
3147

3248
if [ "$ARCHITECTURE" = "x86" ] || [ "$ARCHITECTURE" = "x86_64" ]; then
3349
echo "Architecture is x86 or x86_64, hence not using qemu-arm-static"
34-
sudo cp build.sh miniroot/build.sh && sudo chroot miniroot /bin/sh -ex /build.sh
50+
sudo cp "$repo_root_dir"/chroot/build.sh miniroot/build.sh && sudo chroot miniroot /bin/sh -ex /build.sh
3551
elif [ "$ARCHITECTURE" = "aarch64" ] ; then
3652
echo "Architecture is aarch64, hence using qemu-aarch64-static"
3753
sudo cp "$(which qemu-aarch64-static)" miniroot/usr/bin
38-
sudo cp build.sh miniroot/build.sh && sudo chroot miniroot qemu-aarch64-static /bin/sh -ex /build.sh
54+
sudo cp "$repo_root_dir"/chroot/build.sh miniroot/build.sh && sudo chroot miniroot qemu-aarch64-static /bin/sh -ex /build.sh
3955
elif [ "$ARCHITECTURE" = "armhf" ] ; then
4056
echo "Architecture is armhf, hence using qemu-arm-static"
4157
sudo cp "$(which qemu-arm-static)" miniroot/usr/bin
42-
sudo cp build.sh miniroot/build.sh && sudo chroot miniroot qemu-arm-static /bin/sh -ex /build.sh
58+
sudo cp "$repo_root_dir"/chroot/build.sh miniroot/build.sh && sudo chroot miniroot qemu-arm-static /bin/sh -ex /build.sh
4359
else
4460
echo "Edit chroot_build.sh to support this architecture as well, it should be easy"
4561
exit 1
4662
fi
4763

48-
#############################################
49-
# Clean up chroot
50-
#############################################
51-
52-
sudo umount miniroot/proc miniroot/sys miniroot/dev
53-
5464
#############################################
5565
# Copy build artefacts out
5666
#############################################
5767

5868
# Use the same architecture names as https://github.com/AppImage/AppImageKit/releases/
5969
if [ "$ARCHITECTURE" = "x86" ] ; then ARCHITECTURE=i686 ; fi
6070

61-
mkdir out/
62-
sudo find miniroot/ -type f -executable -name 'runtime-fuse3' -exec cp {} "out/runtime-${ARCHITECTURE}" \;
63-
sudo rm -rf miniroot/
71+
cd "$repo_root_dir"
72+
mkdir -p ./out/
73+
sudo find "$tempdir"/miniroot/ -type f -executable -name 'runtime-fuse3' -exec cp {} "out/runtime-${ARCHITECTURE}" \;

scripts/install-dependencies.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,33 @@
22

33
set -euo pipefail
44

5+
# use a temporary directory to download the files
6+
tmpdir="$(mktemp -d)"
7+
8+
# clean it up whenever the script exits
9+
cleanup() {
10+
echo "Cleaning up $tmpdir"
11+
rm -rf "$tmpdir"
12+
}
13+
trap cleanup EXIT
14+
15+
# store current file's path
16+
# needed to determine the path of the patches
17+
this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
18+
19+
cd "$tmpdir"
20+
521
wget https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz
622
echo "70589cfd5e1cff7ccd6ac91c86c01be340b227285c5e200baa284e401eea2ca0 fuse-3.15.0.tar.xz" | sha256sum -c -
723
tar xf fuse-3.*.tar.xz
824
pushd fuse-3*/
9-
patch -p1 < /tmp/patches/libfuse/mount.c.diff
25+
patch -p1 < "$this_dir"/../patches/libfuse/mount.c.diff
1026
mkdir build
1127
cd build
1228
meson setup --prefix=/usr ..
1329
meson configure --default-library static
1430
ninja -v install
1531
popd
16-
rm -r fuse-*
1732

1833
# Minimize binary size
1934
export CFLAGS="-ffunction-sections -fdata-sections -Os"
@@ -28,4 +43,3 @@ make -j"$(nproc)"
2843
make install
2944
/usr/bin/install -c -m 644 ./*.h '/usr/local/include/squashfuse'
3045
popd
31-
rm -r e51978c* squashfuse*

0 commit comments

Comments
 (0)