Compare commits

...

1 commit

Author SHA1 Message Date
d360cd264e Copy freebsd-build-cross to the repo 2021-02-19 19:51:10 -08:00
3 changed files with 123 additions and 13 deletions

View file

@ -8,6 +8,8 @@ services:
image: docker:20.10.0 image: docker:20.10.0
stage: build stage: build
script: script:
- NAME=${NAME:-${CI_JOB_NAME}}
- DOCKERFILE=${DOCKERFILE:-${CI_JOB_NAME}.Dockerfile}
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}" - docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
- docker build -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" . - docker build -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" .
- docker tag "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}" - docker tag "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}"
@ -31,19 +33,7 @@ signal-server:
allow_failure: true allow_failure: true
freebsd-cross-build: freebsd-cross-build:
image: docker:20.10.0 <<: *build
stage: build
script:
- apk add git
- git clone https://github.com/wezm/freebsd-cross-build.git
- cd freebsd-cross-build
- echo "RUN apt-get update && apt-get install -y git" >> Dockerfile
- VERSION=$(git rev-parse --short=8 HEAD)
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker build -t ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION} .
- docker push ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION}
- if [[ "${CI_COMMIT_REF_SLUG}" == "main" ]]; then docker tag ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION} ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:latest && docker push ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:latest; fi
- echo "docker pull ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION}"
test-helper: test-helper:
<<: *build <<: *build

15
fix-links Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
set -e
cd "$1"
BROKEN_LINKS=$(find . -xtype l)
for link in $BROKEN_LINKS; do
src=$(readlink "$link")
if echo "$src" | grep -q '^\.\./\.\./lib/'; then
# Relink without relative part
new_src=$(echo "$src" | sed 's!^\.\./\.\./lib/!!')
ln -vsf "$new_src" "$link"
fi
done

View file

@ -0,0 +1,105 @@
# This is heavily based on https://github.com/wezm/freebsd-cross-build but has been modified to work well with gitlab-ci
FROM debian:10-slim AS build
# TODO: Add ARG for FreeBSD version/image?
# TODO: Add ARG for parallism?
RUN mkdir /freebsd
WORKDIR /freebsd
RUN apt-get -y update && \
apt-get -y install build-essential m4 bison flex libtool automake autoconf autogen pkg-config curl
RUN curl -OL 'http://ftp.swin.edu.au/freebsd/releases/amd64/12.1-RELEASE/base.txz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/binutils/binutils-2.32.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/gmp/gmp-6.1.2.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/mpfr/mpfr-4.0.2.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/mpc/mpc-1.1.0.tar.gz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.xz'
RUN mkdir -p /src/base /freebsd/x86_64-pc-freebsd12 && \
tar -C /src/base -Jxf base.txz
# Populate the path that gcc will look in for headers and libs
RUN mv /src/base/usr/include /freebsd/x86_64-pc-freebsd12 && \
mv /src/base/usr/lib /freebsd/x86_64-pc-freebsd12 && \
mv /src/base/lib/* /freebsd/x86_64-pc-freebsd12/lib
# These libraries are actually linker scripts (grep -lr ldscript usr)
# https://sourceware.org/binutils/docs/ld/Scripts.html
# Adjust the paths to match their new locations
RUN sed -i'' \
-e 's!/usr/lib/!/freebsd/x86_64-pc-freebsd12/lib/!g' \
-e 's!/lib/libc.so.7!/freebsd/x86_64-pc-freebsd12/lib/libc.so.7!g' \
/freebsd/x86_64-pc-freebsd12/lib/libc.so && \
sed -i'' \
's!/usr/lib/!/freebsd/x86_64-pc-freebsd12/lib/!g' \
/freebsd/x86_64-pc-freebsd12/lib/libc++.so
# Fix symlinks broken by moving libraries
COPY fix-links /src
RUN /src/fix-links /freebsd/x86_64-pc-freebsd12/lib
RUN tar -C /src -Jxf binutils-2.32.tar.xz && \
tar -C /src -Jxf gcc-6.4.0.tar.xz && \
tar -C /src -Jxf gmp-6.1.2.tar.xz && \
tar -C /src -zxf mpc-1.1.0.tar.gz && \
tar -C /src -Jxf mpfr-4.0.2.tar.xz
# Build toolchain
RUN cd /src/binutils-2.32 && \
./configure --enable-libssp --enable-ld --target=x86_64-pc-freebsd12 --prefix=/freebsd && \
make -j7 && \
make install
RUN cd /src/gmp-6.1.2 && \
./configure --prefix=/freebsd --enable-shared --enable-static \
--enable-mpbsd --enable-fft --enable-cxx --host=x86_64-pc-freebsd12 && \
make -j7 && \
make install
RUN cd /src/mpfr-4.0.2 && \
./configure --prefix=/freebsd --with-gnu-ld --enable-static \
--enable-shared --with-gmp=/freebsd --host=x86_64-pc-freebsd12 && \
make -j7 && \
make install
RUN cd /src/mpc-1.1.0/ && \
./configure --prefix=/freebsd --with-gnu-ld \
--enable-static --enable-shared --with-gmp=/freebsd \
--with-mpfr=/freebsd --host=x86_64-pc-freebsd12 &&\
make -j7 && \
make install
RUN mkdir -p /src/gcc-6.4.0/build && \
cd /src/gcc-6.4.0/build && \
../configure --without-headers --with-gnu-as --with-gnu-ld --disable-nls \
--enable-languages=c,c++ --enable-libssp --enable-ld \
--disable-libitm --disable-libquadmath --target=x86_64-pc-freebsd12 \
--prefix=/freebsd --with-gmp=/freebsd \
--with-mpc=/freebsd --with-mpfr=/freebsd --disable-libgomp && \
LD_LIBRARY_PATH=/freebsd/lib make -j7 && \
make install
# Now copy the toolchain to a fresh image
FROM debian:10-slim
COPY --from=build /freebsd /freebsd
env LD_LIBRARY_PATH /freebsd/lib
env PATH /freebsd/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env CC x86_64-pc-freebsd12-gcc
env CPP x86_64-pc-freebsd12-cpp
env AS x86_64-pc-freebsd12-as
env LD x86_64-pc-freebsd12-ld
env AR x86_64-pc-freebsd12-ar
env RANLIB x86_64-pc-freebsd12-ranlib
env HOST x86_64-pc-freebsd12
# A host compiler is needed to link Rust build scripts even when cross compiling:
RUN apt-get update -y && apt-get install -y curl build-essential git
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --target x86_64-unknown-freebsd
RUN mkdir -p /rust/project /rust/target
WORKDIR /rust/project
VOLUME /rust/project
ENV PATH /root/.cargo/bin:/freebsd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Required for the openssl-sys crate:
ENV OPENSSL_DIR /freebsd/x86_64-pc-freebsd12/