Docker image with Heaps, Haxe, Neko and Hashlink.
810
Haxe, Neko, HashLink and the Heaps game engine, for compiling Heaps games and bundling them with their libraries for GNU/Linux.
Docker Hub · Source · All images
| Base image | debian:13.7 |
| Software | Heaps 2.1.0 (installed from haxelib on the first start) |
| Also included | Haxe, Neko, HashLink (built from source), g++, SDL3, OpenAL, bundle and makesh, ShellCheck |
| User | heaps (uid 1000) with passwordless sudo (sudo apt-get install ...) |
| Tags | latest, 2.1.0, 2.1.0-YYYYMMDD |
Run in an empty directory; the commands work on the files of the current directory, mounted as the home directory of the container. CI runs these commands to check that they work.
# the first start installs Heaps and its libraries with haxelib, into ~/haxelib
docker run --rm -v .:/home/heaps -w /home/heaps aljazmc/heaps-buildforlinux "haxe --version && haxelib list heaps"
# compile the project of the current directory to hello.hl
docker run --rm -v .:/home/heaps -w /home/heaps aljazmc/heaps-buildforlinux "haxe compile.hxml"
# bundle it with HashLink and its libraries: dist/hello and dist/hello.tar.gz
docker run --rm -v .:/home/heaps -w /home/heaps aljazmc/heaps-buildforlinux "bundle hello.hl"
The container user needs the host's render, video and audio groups to use the GPU and the sound card. Without them the game falls back to software rendering. The group ids differ between distributions, so look them up with stat -c %g /dev/dri/renderD128 /dev/dri/card0 /dev/snd/controlC0.
## docker-compose.yml example for GNU/Linux host
services:
heaps:
image: aljazmc/heaps-buildforlinux
working_dir: /home/heaps
user: heaps
environment:
DISPLAY: $DISPLAY
XDG_RUNTIME_DIR: /run/user/1000
volumes:
- .:/home/heaps
- /home/$USER/.Xauthority:/home/heaps/.Xauthority
- $XDG_RUNTIME_DIR:/run/user/1000
- /tmp/.X11-unix:/tmp/.X11-unix
- /var/lib/dbus/machine-id:/var/lib/dbus/machine-id
devices:
- /dev/dri:/dev/dri
- /dev/snd:/dev/snd
group_add:
- "992" # render group: stat -c %g /dev/dri/renderD128
- "44" # video group: stat -c %g /dev/dri/card0
- "29" # audio group: stat -c %g /dev/snd/controlC0
network_mode: host
## the first start installs Heaps and its libraries with haxelib
docker compose run --rm heaps
## run commands in the container:
docker compose run --rm heaps "haxe compile.hxml && hl hello.hl"
The commands expect a Heaps project in the current directory with a compile.hxml that compiles it to hello.hl, like this one, and the sources in src:
-cp src
-lib format
-lib heaps
-lib hlsdl
-hl hello.hl
-main Main
A compiled .hl file needs the HashLink runtime (hl, libhl.so, *.hdll) and the libraries the .hdll files depend on (SDL3, OpenAL, libpng, libturbojpeg, libvorbis, libuv, ...). To run the game on a machine without Haxe and HashLink installed, copy all of them next to the .hl file together with a small launcher script.
## the image contains this script as the `bundle` command ([source](https://github.com/aljazmc/dockerfiles/blob/main/heaps/buildforlinux/bundle)):
#!/bin/bash
set -e
HL_FILE="${1:-hello.hl}"
NAME="$(basename "$HL_FILE" .hl)"
DIST="dist/$NAME"
HDLLS=(fmt heaps openal sdl ui uv)
BUNDLE_LIBS="libSDL3|libopenal|libpng16|libturbojpeg|libvorbis|libogg|libuv|libsndio|libdecor|libmbed|libsqlite3"
rm -rf "$DIST"
mkdir -p "$DIST"
cp "$HL_FILE" "$(command -v hl)" /usr/local/lib/libhl.so "$DIST"/
for HDLL in "${HDLLS[@]}"; do
cp /usr/local/lib/"$HDLL".hdll "$DIST"/
done
if [ -d res ]; then
cp -r res "$DIST"/
fi
ldd "$DIST"/*.hdll \
| awk '/=> \// {print $3}' \
| grep -E "/($BUNDLE_LIBS)[^/]*$" \
| sort -u \
| xargs -r cp -L -t "$DIST"/
cat <<EOF > "$DIST/$NAME"
#!/bin/sh
cd "\$(dirname "\$0")"
export LD_LIBRARY_PATH="\$PWD\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}"
exec ./hl $NAME.hl "\$@"
EOF
chmod +x "$DIST/$NAME"
tar -czf "dist/$NAME.tar.gz" -C dist "$NAME"
## compile and bundle the project:
docker compose run --rm heaps "haxe compile.hxml && bundle hello.hl"
## the result is the `dist/hello` directory and the `dist/hello.tar.gz` archive. To run the game, extract the archive on the target machine and start the launcher:
tar -xzf hello.tar.gz
./hello/hello
HDLLS lists the HashLink libraries that are copied. Add ssl, sqlite or mysql if the project uses them. Their dependencies are picked up automatically. To change the lists, copy the command into the project (cp /usr/local/bin/bundle .), edit it and run ./bundle instead.BUNDLE_LIBS lists the libraries that are copied from the image. Everything else, such as glibc, X11, Wayland, GPU drivers, ALSA, PulseAudio and PipeWire, is expected on the target machine.res directory at runtime (hxd.Res.initLocal()), the directory is copied too. With hxd.Res.initEmbed() the resources are already inside the .hl file.LD_LIBRARY_PATH to its own directory, so the bundled libraries are used instead of the system ones.The .sh file is a small shell script with the game appended as a .tar.gz archive. When it starts, it extracts the game to a temporary directory, runs it with the same arguments, returns its exit code and deletes the directory when the game exits. It only needs sh, tar, gzip and mktemp, which every GNU/Linux distribution has.
## the image contains this script as the `makesh` command ([source](https://github.com/aljazmc/dockerfiles/blob/main/heaps/buildforlinux/makesh)):
#!/bin/bash
set -e
DIR="${1:?usage: makesh <directory> <executable in the directory> <output.sh>}"
RUN="${2:?usage: makesh <directory> <executable in the directory> <output.sh>}"
OUT="${3:?usage: makesh <directory> <executable in the directory> <output.sh>}"
cat <<EOF > "$OUT"
#!/bin/sh
set -e
TMP="\$(mktemp -d)"
trap 'rm -rf "\$TMP"' EXIT
trap 'exit 130' INT TERM HUP
ARCHIVE="\$(awk '/^__ARCHIVE__\$/ { print NR + 1; exit }' "\$0")"
tail -n +"\$ARCHIVE" "\$0" | tar -xz -C "\$TMP"
"\$TMP/$RUN" "\$@"
exit \$?
__ARCHIVE__
EOF
tar -czf - -C "$DIR" . >> "$OUT"
chmod +x "$OUT"
## create the archive:
docker compose run --rm heaps "haxe compile.hxml && bundle hello.hl && makesh dist/hello hello dist/hello.sh"
The result is dist/hello.sh. Copy it to the target machine and start it with ./hello.sh.
makesh <directory> <executable in the directory> <output.sh>. The whole directory is packed and the executable is started from inside it./tmp is mounted with noexec, point TMPDIR to another directory: TMPDIR=~/.cache ./hello.sh..sh archive too.$XDG_DATA_HOME, by default ~/.local/share). hxd.Save writes to the working directory by default.latest: the newest build.2.1.0: the Heaps version in the image, e.g. aljazmc/heaps-buildforlinux:2.1.0. Use it to stay on a known version.2.1.0-YYYYMMDD: the same version, built on that date (UTC), e.g. 2.1.0-20261122. Every build gets its own tag that never moves, so use it where you need exactly the same image again.~/haxelib), pinned with the HEAPS_VERSION environment variable set in the Dockerfile. An existing ~/haxelib directory is kept as it is.The Dockerfile, the scripts and this README are part of aljazmc/dockerfiles, released under the MIT License.
The software in the image keeps its own license:
| Software | License | In the image |
|---|---|---|
| Heaps | MIT | ~/haxelib/heaps/*/LICENSE after the first start |
Every other package keeps its license too: apk info --license <package> shows it on Alpine, /usr/share/doc/<package>/copyright on Debian.
Content type
Image
Digest
sha256:a2a2133a1…
Size
389.5 MB
Last updated
1 day ago
docker pull aljazmc/heaps-buildforlinux