Docker: update cross-compiler Dockerfile and build script

Updated so that it can build Haiku R1 Beta 4. The intention is to use this to
create repeatable builds for Rust builds. The script has been tweaked to use
the latest stable debian as base image, to include the (now-required)
libzstd-devel package, and the g++-multilib package to support building 32 bit
in a 64 bit host. It also moves to python 3.x.

Additionally, the image now supports specifying custom git tags/branches for
the buildtools and Haiku itself, so that specific hrevs or branches can be
built

Change-Id: Ia43089ff7271256fdb6603bd4400ee3b9228ea1b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5965
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
Niels Sascha Reedijk 2022-12-24 23:19:59 +00:00
parent ad59349e16
commit 52c4471a30
3 changed files with 45 additions and 16 deletions

View File

@ -1,4 +1,4 @@
FROM debian:buster-slim
FROM debian:bullseye-slim
# docker build --no-cache --tag docker.io/haiku/cross-compiler:x86_64 .
# docker push docker.io/haiku/cross-compiler:x86_64
@ -14,20 +14,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
file \
flex \
g++ \
g++-multilib \
gawk \
git \
libcurl4-openssl-dev \
libssl-dev \
libzstd-dev \
make \
nasm \
ninja-build \
python \
python3 \
texinfo \
vim \
wget \
xz-utils \
zlib1g-dev
# source revision to build
ARG BUILDTOOLS_REV=master
ARG HAIKU_REV=master
# architectures to build
ARG ARCHITECTURE=x86_64
ARG SECONDARY_ARCHITECTURE=
@ -36,6 +41,6 @@ ARG SECONDARY_ARCHITECTURE=
WORKDIR /tmp
COPY build-toolchain.sh /tmp/
RUN chmod 755 /tmp/build-toolchain.sh
RUN /tmp/build-toolchain.sh $ARCHITECTURE $SECONDARY_ARCHITECTURE
RUN /tmp/build-toolchain.sh $BUILDTOOLS_REV $HAIKU_REV $ARCHITECTURE $SECONDARY_ARCHITECTURE
WORKDIR /

View File

@ -14,3 +14,22 @@ The docker build of this image prepares the environment by:
You can then use the $ARCH-unknown-haiku compiler (for example
arm-unknown-haiku-gcc) to build your application. All the required files are
installed in /tools/cross-tools-$ARCH.
## Building the image
The Dockerfile accepts four arguments when building the image:
* `BUILDTOOLS_REV` is the branch/tag of buildtools that should be built. It defaults to `master`.
* `HAIKU_REV` is the branch/tag of the haiku repository that should be built. It defaults to `master`.
* `ARCHITECTURE` is the primary architecture to build the tools and library for. It defaults to `x86_64`
* `SECONDARY_ARCHITECTURE` is the secondary architecture. Leave it empty in case it is not necessary.
For example, the r1beta4 images are build with the following commands:
```bash
# r1beta4 on x86 hybrid, with gcc2 as the primary architecture, and modern gcc as the secondary
podman build --build-arg BUILDTOOLS_REV=r1beta4 --build-arg HAIKU_REV=r1beta4 --build-arg ARCHITECTURE=x86_gcc2 --build-arg SECONDARY_ARCHITECTURE=x86 --tag docker.io/haiku/cross-compiler:x86_gcc2h-r1beta4 .
# r1beta4 on x86_64
podman build --build-arg BUILDTOOLS_REV=r1beta4 --build-arg HAIKU_REV=r1beta4 --build-arg ARCHITECTURE=x86_64 --tag docker.io/haiku/cross-compiler:x86_64-r1beta4 .
```

View File

@ -11,8 +11,10 @@
set -ex
ARCH=$1
SECONDARY_ARCH=$2
BUILDTOOLS_REV=$1
HAIKU_REV=$2
ARCH=$3
SECONDARY_ARCH=$4
TOP=$(pwd)
@ -23,14 +25,23 @@ SYSROOT=$OUTPUT/cross-tools-$ARCH/sysroot
SYSROOT_SECONDARY=$OUTPUT/cross-tools-$SECONDARY_ARCH/sysroot
PACKAGE_ROOT=/system
# First up, build a cross-compiler
git clone --depth=1 https://git.haiku-os.org/haiku
git clone --depth=1 https://git.haiku-os.org/buildtools
# Get the source trees
git clone --depth=1 --branch $HAIKU_REV https://review.haiku-os.org/haiku
git clone --depth=1 --branch $BUILDTOOLS_REV https://review.haiku-os.org/buildtools
# The Haiku build requires the ability to find a hrev tag. In case a specific branch is selected
# (like `r1beta4`)`, we will get the entire history just to be sure that the tag will exist.
cd haiku
if ! `git describe --dirty --tags --match=hrev* --abbrev=1`; then
git fetch --unshallow
fi
# Build a cross-compiler
cd $BUILDTOOLS/jam
make && ./jam0 install
mkdir -p $OUTPUT
cd $OUTPUT
configureArgs="--build-cross-tools $ARCH $TOP/buildtools"
configureArgs="--build-cross-tools $ARCH --cross-tools-source $TOP/buildtools"
if [ -n "$SECONDARY_ARCH" ]; then
configureArgs="$configureArgs --build-cross-tools $SECONDARY_ARCH"
fi
@ -42,7 +53,7 @@ mkdir -p $PACKAGE_ROOT
ln -s $PACKAGE_ROOT $SYSROOT/boot/system
if [ -n "$SECONDARY_ARCH" ]; then
mkdir -p $SYSROOT_SECONDARY/boot
ln -s $PACKAGEROOT $SYSROOT_SECONDARY/boot/system
ln -s $PACKAGE_ROOT $SYSROOT_SECONDARY/boot/system
fi
# Build needed packages and tools for the cross-compiler
@ -73,12 +84,6 @@ if [ -n "$SECONDARY_ARCH" ]; then
package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_${SECONDARY_ARCH}_devel.hpkg
fi
find $OUTPUT/download/ -name '*.hpkg' -exec package extract -C $PACKAGE_ROOT {} \;
cd $PACKAGE_ROOT/develop/lib
ln -s ../../lib/libgcc_s.so libgcc_s.so
if [ -n "$SECONDARY_ARCH" ]; then
cd $PACKAGE_ROOT/develop/lib/$SECONDARY_ARCH
ln -s ../../../lib/$SECONDARY_ARCH/libgcc_s.so libgcc_s.so
fi
# Clean up
rm -rf $BUILDTOOLS