OXYGENHUB
# a673804c781c x16-emulator / .flow / image / build-riscv64.sh
2.1 KiB · Bourne Again Shell (bash) · executable · last changed ci: build and test x16emu natively on narvi-1, OxygenHub's RISC-V runner 17 days ago source blame history raw
1
#!/bin/sh
2
# Build the riscv64 image the pipeline's jobs run in on narvi-1, and write it
3
# as a root file system tarball for `flow rootfs import`. There is no Docker
4
# on a RISC-V board, so this is Ubuntu Base 24.04.5 riscv64, checked against
5
# its published SHA-256, with the build's packages installed by apt in a
6
# chroot. Run it on a riscv64 Linux machine (narvi) as root or a user with
7
# sudo, then
8
#
9
#     FLOW_HOME=~/flow ~/flow/bin/flow rootfs import x16emu-riscv64.tar
10
#
11
# and pin the printed hash in .flow/pipeline.kdl. Rebuild, re-import and
12
# re-pin when the packages below change.
13
set -eu
14
here=$(cd "$(dirname "$0")" && pwd)
15
out=${1:-$here/x16emu-riscv64.tar}
16
release=24.04.5
17
base=ubuntu-base-$release-base-riscv64.tar.gz
18
sha256=651c516f291259ec913caa1efd0cfff738cd223adfc6617c884f07af487f08cf
19
# What the Makefile and the conformance suite need, as README.md lists for
20
# riscv64 Linux: C11 and C++17 compilers, make, SDL2 and zlib, Python and
21
# pytest.
22
packages="build-essential make libsdl2-dev zlib1g-dev python3 python3-pytest"
23
24
test "$(uname -m)" = riscv64 || { echo "build-riscv64.sh: run this on a riscv64 machine" >&2; exit 1; }
25
work=$(mktemp -d)
26
root=$work/root
27
cleanup() {
28
	sudo umount "$root/proc" "$root/dev" 2>/dev/null || true
29
	sudo rm -rf "$work"
30
}
31
trap cleanup EXIT
32
33
curl -fsSL -o "$work/$base" "https://cdimage.ubuntu.com/ubuntu-base/releases/$release/release/$base"
34
echo "$sha256  $work/$base" | sha256sum -c - >/dev/null
35
mkdir "$root"
36
sudo tar -C "$root" -xzf "$work/$base"
37
sudo mv "$root/etc/resolv.conf" "$work/resolv.conf.image" 2>/dev/null || true
38
sudo cp /etc/resolv.conf "$root/etc/resolv.conf"
39
sudo mount --bind /dev "$root/dev"
40
sudo mount -t proc proc "$root/proc"
41
sudo chroot "$root" sh -c "
42
	export DEBIAN_FRONTEND=noninteractive
43
	apt-get update -q >/dev/null
44
	apt-get install -y -q --no-install-recommends $packages >/dev/null
45
	apt-get clean
46
	rm -rf /var/lib/apt/lists/*"
47
sudo umount "$root/proc" "$root/dev"
48
sudo rm "$root/etc/resolv.conf"
49
sudo mv "$work/resolv.conf.image" "$root/etc/resolv.conf" 2>/dev/null || true
50
sudo tar -C "$root" -cf "$out" .
51
sudo chown "$(id -u):$(id -g)" "$out"
52
echo "$out"