Skip to content

Commit

Permalink
ghc-bootstrap: simplify/unify aport, restrict to x86_64 for now, armh…
Browse files Browse the repository at this point in the history
…f here for completeness.

The bootstrap port now sets up needed settings at apk build time instead
of at docker build time. Should be less brittle for changes.
  • Loading branch information
mitchty committed Dec 31, 2016
1 parent 564c895 commit da0e932
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 409 deletions.
43 changes: 21 additions & 22 deletions testing/ghc-bootstrap/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ pkgname=ghc-bootstrap
pkgver=8.0.1
pkgrel=0
pkgdesc="The Glasgow haskell compiler (bootstrapped)"
arch="x86_64 armhf"
arch="x86_64"
license="custom:bsd3"
url="https://haskell.org"
depends="bash libffi musl zlib gcc binutils-gold llvm3.7"
install=""
subpackages=""
makedepends=""
source="
https://mitchty.net/ghc/8.0.1/ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
http://dev.alpinelinux.org/archive/ghc-bootstrap/ghc-$pkgver-arm-unknown-linux-musleabihf.tar.xz
http://dev.alpinelinux.org/archive/ghc-bootstrap/ghc-$pkgver-x86_64.tar.xz
"

# The bootstrap process uses docker to build ghc from a debian glibc host
Expand All @@ -30,30 +29,30 @@ source="
# Note, these docker images are large, ~10G the dockerfiles weren't built
# to be small. Once built the containers should likely be removed.
snapshot() {
local x86_64_tar="ghc-${pkgver}-x86_64-pc-linux-musl.tar.xz"
local arm_tar="ghc-${pkgver}-arm-unknown-linux-musleabihf.tar.xz"

docker build -t alpine-ghc-bootstrap:x86_64 \
-f bootstrap/x86_64/Dockerfile .
docker run -a stdout alpine-ghc-bootstrap:x86_64 \
/bin/cat "/tmp/$x86_64_tar" > $x86_64_tar

docker build -t alpine-ghc-bootstrap:armhf \
-f bootstrap/armhf/Dockerfile .
docker run -a stdout alpine-ghc-bootstrap:armhf \
/bin/cat "/tmp/$arm_tar" > $arm_tar
for x in $(echo ${arch}); do
docker build -t alpine-ghc-bootstrap:${x} \
-f Dockerfile.${x} . || return 1
docker run -a stdout alpine-ghc-bootstrap:${x} \
/bin/cat "/tmp/ghc-${pkgver}-${x}.tar.xz" > ghc-${pkgver}-${x}.tar.xz || return 1
done
}

package() {
cd "$srcdir/$CARCH"
install -d "$pkgdir" || return 1
mv usr "$pkgdir" || return 1
settings=$(find "$pkgdir" -name settings -type f)
local settings="$(find $pkgdir -name settings -type f)"
# Force all the pic/pie hardening off for ghc until this bug:
# https://ghc.haskell.org/trac/ghc/ticket/9007
# is fixed/corrected. Otherwise we end up with TEXT segments
# in places that make no sense.
sed -i 's/.*C compiler flags", "/& -fPIC -fno-PIE -fno-stack-protector/' "$settings"
sed -i 's/.*ld flags", "/& -no-pie /' "$settings"
sed -i 's|/usr/.*-gcc|gcc|' "$settings"
sed -i 's|/usr/.*-ar|ar|' "$settings"
sed -i 's|/usr/.*-ld.gold|ld.gold|' "$settings"
sed -i 's|/usr/.*-ld|ld.gold|' "$settings"
sed -i 's|/usr/.*/llc|llc-3.7|' "$settings"
sed -i 's|/usr/.*/opt|opt-3.7|' "$settings"
}

md5sums="b6bfa68c3579281dba670cf0f36c3c87 ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
b0901df3305b49b6044607b5ccde5f03 ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
sha256sums="8170367964347066162b547f833034b06a09ba0383323364fb742ea07ea7871f ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
54d5e8067b087b1d426e01469162749f1f2c417dc2b8b0f6577acbf0c19aba5e ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
sha512sums="aebc55125e39922ce7a1e0718a602f007da111e0922e757e1b9c06557bc557e6e0e7270c380821e8ea57dd7cd216cd1dbd516fb2365d3deb0672505c5fe2d2dd ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
ab920e198a2c779e8ad3f6e3f9e9485c8742254c5a914875a6cd106957bb6e0720e90707aabe822295535922d55fc66898660bf7cbf8a7c88c231eceafe358e4 ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
from debian:8.0

# Install stock bindist for cross compile
env ghc 7.10.3
env ghc 8.0.1
env arch x86_64
env llvm 3.7.1
env cabal 1.22.9.0
env cabal 1.24.0.0

env destarch armhf
env tardir /tmp/root
env destdir /tmp/root/$destarch
env triple arm-unknown-linux-musleabihf
env target arm-linux-musleabihf
env crosscc $triple-gcc

# add cross toolchain to PATH
env PATH /usr/$triple/bin:$PATH

# all needed packages for compiling
run apt-get clean && \
Expand All @@ -31,8 +41,8 @@ run apt-get clean && \
pixz \
openssl \
bison \
flex \
git
git \
flex

add http://llvm.org/releases/$llvm/llvm-$llvm.src.tar.xz /tmp/
add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/
Expand All @@ -42,48 +52,45 @@ add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/
# "what debian upstream has a current version of llvm" nonsense, takes more
# time to do that than just build the right llvm from source.
workdir /tmp
copy bootstrap/llvm-$llvm.sh /tmp/llvm.sh
copy llvm-$llvm.sh /tmp/llvm.sh
run openssl sha1 llvm-$llvm.src.tar.xz | grep "SHA1(llvm-3.7.1.src.tar.xz)= 5dbdcafac105273dcbff94c68837a66c6dd78cef" && \
openssl sha1 polly-$llvm.src.tar.xz | grep "SHA1(polly-3.7.1.src.tar.xz)= 0e3a461907cde7505fbdb44bf61ff318aa9254f7" && \
tar xJpf /tmp/llvm-$llvm.src.tar.xz && \
tar xJpf /tmp/polly-$llvm.src.tar.xz && \
/tmp/llvm.sh && \
rm -fr /tmp/llvm-$llvm.src
rm -fr /tmp/llvm-$llvm.src /tmp/build

add https://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-$arch-deb8-linux.tar.xz /tmp/

# Install debian ghc binary from upstream.
workdir /tmp
run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-7.10.3-x86_64-deb8-linux.tar.xz)= bab16f95ef4fe6b7cc2fb6b36a02dceeeb53faa4" && \
run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-8.0.1-x86_64-deb8-linux.tar.xz)= 4a313d073982901a1ce8477386a61e4673511006" && \
tar xJpf /tmp/ghc-$ghc-$arch-deb8-linux.tar.xz
workdir /tmp/ghc-$ghc
run ./configure --prefix=/usr && \
make -j1 install && \
rm -fr /tmp/ghc-$ghc

add https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz /tmp/
run curl -kL https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz -o /tmp/cabal-install-$cabal.tar.gz

# Install cabal so we can install alex/happy to pull off of git
# bootstrap cabal and install alex/happy the same way apks are built
# only globally
workdir /tmp
run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.22.9.0.tar.gz)= f1375c928794f45f253b8ec92c2af4732fec597b" && \
run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.24.0.0.tar.gz)= 3a379b17bfa68cabf3ba4728a3000779f4c7ae63" && \
tar xzpf /tmp/cabal-install-$cabal.tar.gz
workdir /tmp/cabal-install-$cabal
run ./bootstrap.sh --global --no-doc && \
cabal update && \
cabal install --global alex happy && \
rm -fr /tmp/cabal-install-$cabal

# First up, install/compile the cross compiler with musl libc
# armv7 hard float cross compiler, we basically rebuild ghc again here with
# the cross compiler, and the llvm we built for x86_64 as well
workdir /tmp
run git clone --depth 1 https://github.com/GregorR/musl-cross.git musl-cross
workdir /tmp/musl-cross
run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \
echo TRIPLE=${triple} >> config.sh && \
echo ARCH=arm >> config.sh && \
echo TRIPLE=arm-linux-musleabihf >> config.sh && \
echo GCC_BOOTSTRAP_CONFFLAGS=\"--with-arch=armv6 --with-float=hard --with-fpu=vfp\" >> config.sh && \
echo GCC_CONFFLAGS=\"--with-arch=armv6 --with-float=hard --with-fpu=vfp\" >> config.sh && \
echo GCC_STAGE1_NOOPT=1 >> config.sh && \
Expand All @@ -93,47 +100,34 @@ run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \
echo "CFLAGS='-g -O2 -fPIC -DPIC'" >> config.sh && \
echo "CPPFLAGS='-fPIC -DPIC'" >> config.sh && \
echo "LDFLAGS='-fPIC -DPIC'" >> config.sh
copy bootstrap/gmpurl.patch gmpurl.patch
copy gmpurl.patch gmpurl.patch
run patch -p1 < gmpurl.patch && \
./build.sh && \
rm -fr /tmp/musl-cross

add http://downloads.haskell.org/~ghc/8.0.1/ghc-8.0.1-src.tar.xz /tmp/

env tardir /tmp/root
env destdir /tmp/root/armhf
env crosscc arm-linux-musleabihf-gcc
env target arm-linux-musleabihf
env triple arm-unknown-linux-musleabihf
env ghc 8.0.1

# add cross toolchain to PATH
env PATH /usr/$target/bin:$PATH

workdir /tmp
run openssl sha1 ghc-$ghc-src.tar.xz | grep "SHA1(ghc-8.0.1-src.tar.xz)= 585a2d34a17ce2452273147f2e3cef1a2efe1aa5" && \
tar xJpf /tmp/ghc-$ghc-src.tar.xz
workdir /tmp/ghc-$ghc
env PATH $PATH:/usr/$triple/bin
copy bootstrap/$arch/bootstrap.patch bootstrap.patch
run patch -p1 < bootstrap.patch
run cp mk/build.mk.sample mk/build.mk && \
./boot && \
echo "BuildFlavour = quick-llvm" >> mk/build.mk && \
echo "INTEGER_LIBRARY = integer-simple" >> mk/build.mk && \
echo "HADDOCK_DOCS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_HTML = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk && \
./configure \
--target=$target \
--prefix=/usr
run make -j$(grep -c processor /proc/cpuinfo) || make -j1
run make -j1 install STRIP_CMD=$target-strip DESTDIR=$destdir

# unlit and hp2ps both build using the stage0, not having luck
# getting the build patched right so for now lets just
# remove and rebuild these c helper programs
copy bootstrap.patch bootstrap.patch
run patch -p1 < bootstrap.patch
run cp mk/build.mk.sample mk/build.mk && \
./boot && \
echo "BuildFlavour = perf-llvm" >> mk/build.mk && \
echo "BeConservative = YES" >> mk/build.mk && \
echo "INTEGER_LIBRARY = integer-simple" >> mk/build.mk && \
echo "HADDOCK_DOCS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_HTML = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk && \
echo "V = 0" >> mk/build.mk && \
./configure \
--target=$triple \
--prefix=/usr
run make -j$(grep -c processor /proc/cpuinfo) || make -j1
run make -j1 install DESTDIR=$destdir STRIP_CMD=$triple-strip
run rm $(find $destdir -name "*-hp2ps")

# remove target prefix from stage2 binaries
Expand All @@ -143,12 +137,10 @@ run $crosscc unlit.c -o $(find $destdir -name unlit)

# remove target prefix from stage2 binaries
workdir $destdir/usr/bin
run (for i in $triple-* ; do ln -s $i ${i#$triple-} || /bin/true ; done )
copy bootstrap/armhf/settings /tmp/settings
run mv /tmp/settings $(find $destdir -name settings -type f)
run rm -fr $destdir/usr/share/doc
run (for i in $triple-* ; do ln -s $i ${i#$triple-} || /bin/true; done ) && \
rm -fr $destdir/usr/share/doc

workdir $tardir
# Compress to xz via pixz because xz is normally too
# old for -TN multithreads
run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$triple.tar.xz .
run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$destarch.tar.xz .
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
from debian:8.0

# Install stock bindist for cross compile
env ghc 7.10.3
env ghc 8.0.1
env arch x86_64
env llvm 3.7.1
env cabal 1.22.9.0
env cabal 1.24.0.0

env destarch x86_64
env tardir /tmp/root
env destdir /tmp/root/$destarch
env triple ${arch}-pc-linux-musl
env target ${arch}-pc-linux-musl
env crosscc $triple-gcc

# add cross toolchain to PATH
env PATH /usr/$triple/bin:$PATH

# all needed packages for compiling
run apt-get clean && \
Expand All @@ -30,8 +40,8 @@ run apt-get clean && \
python \
pixz \
openssl \
git \
bison \
git \
flex

add http://llvm.org/releases/$llvm/llvm-$llvm.src.tar.xz /tmp/
Expand All @@ -42,7 +52,7 @@ add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/
# "what debian upstream has a current version of llvm" nonsense, takes more
# time to do that than just build the right llvm from source.
workdir /tmp
copy bootstrap/llvm-$llvm.sh /tmp/llvm.sh
copy llvm-$llvm.sh /tmp/llvm.sh
run openssl sha1 llvm-$llvm.src.tar.xz | grep "SHA1(llvm-3.7.1.src.tar.xz)= 5dbdcafac105273dcbff94c68837a66c6dd78cef" && \
openssl sha1 polly-$llvm.src.tar.xz | grep "SHA1(polly-3.7.1.src.tar.xz)= 0e3a461907cde7505fbdb44bf61ff318aa9254f7" && \
tar xJpf /tmp/llvm-$llvm.src.tar.xz && \
Expand All @@ -54,69 +64,63 @@ add https://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-$arch-deb8-linux.tar.xz /tm

# Install debian ghc binary from upstream.
workdir /tmp
run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-7.10.3-x86_64-deb8-linux.tar.xz)= bab16f95ef4fe6b7cc2fb6b36a02dceeeb53faa4" && \
run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-8.0.1-x86_64-deb8-linux.tar.xz)= 4a313d073982901a1ce8477386a61e4673511006" && \
tar xJpf /tmp/ghc-$ghc-$arch-deb8-linux.tar.xz
workdir /tmp/ghc-$ghc
run ./configure --prefix=/usr && \
make -j1 install && \
rm -fr /tmp/ghc-$ghc

add https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz /tmp/
run curl -kL https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz -o /tmp/cabal-install-$cabal.tar.gz

# Install cabal so we can install alex/happy to pull off of git
# bootstrap cabal and install alex/happy the same way apks are built
# only globally
workdir /tmp
run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.22.9.0.tar.gz)= f1375c928794f45f253b8ec92c2af4732fec597b" && \
run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.24.0.0.tar.gz)= 3a379b17bfa68cabf3ba4728a3000779f4c7ae63" && \
tar xzpf /tmp/cabal-install-$cabal.tar.gz
workdir /tmp/cabal-install-$cabal
run ./bootstrap.sh --global --no-doc && \
cabal update && \
cabal install --global alex happy && \
rm -fr /tmp/cabal-install-$cabal

# Build our cross compiler with musl libc from the sabotage linux stuff
workdir /tmp
run git clone --depth 1 https://github.com/GregorR/musl-cross.git musl-cross
workdir /tmp/musl-cross
run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \
echo ARCH=x86_64 >> config.sh && \
echo TRIPLE=x86_64-pc-linux-musl >> config.sh && \
echo TRIPLE=${triple} >> config.sh && \
echo ARCH=${destarch} >> config.sh && \
echo GCC_STAGE1_NOOPT=1 >> config.sh && \
echo CC_BASE_PREFIX=/usr >> config.sh && \
echo MAKEFLAGS=-j$(grep -c processor /proc/cpuinfo) >> config.sh && \
echo "BINUTILS_CONFFLAGS='CXXFLAGS=-fpermissive --enable-gold --enable-plugins --disable-werror'" >> config.sh && \
echo "CFLAGS='-g -O2 -fPIC -DPIC'" >> config.sh && \
echo "CPPFLAGS='-fPIC -DPIC'" >> config.sh && \
echo "LDFLAGS='-fPIC -DPIC'" >> config.sh
copy bootstrap/gmpurl.patch gmpurl.patch
echo "CFLAGS='-g -O3 -fno-pie -fno-pic'" >> config.sh
copy gmpurl.patch gmpurl.patch
run patch -p1 < gmpurl.patch && \
./build.sh && \
rm -fr /tmp/musl-cross

add http://downloads.haskell.org/~ghc/8.0.1/ghc-8.0.1-src.tar.xz /tmp/

env tardir /tmp/root
env destdir /tmp/root/x86_64
env triple x86_64-pc-linux-musl
env crosscc $triple-gcc
env ghc 8.0.1

workdir /tmp
run openssl sha1 ghc-$ghc-src.tar.xz | grep "SHA1(ghc-8.0.1-src.tar.xz)= 585a2d34a17ce2452273147f2e3cef1a2efe1aa5" && \
tar xJpf /tmp/ghc-$ghc-src.tar.xz
workdir /tmp/ghc-$ghc
env PATH $PATH:/usr/$triple/bin
copy bootstrap/$arch/bootstrap.patch bootstrap.patch
copy bootstrap.patch bootstrap.patch
run patch -p1 < bootstrap.patch
run cp mk/build.mk.sample mk/build.mk && \
./boot && \
echo "BuildFlavour = quick-llvm" >> mk/build.mk && \
echo "BuildFlavour = perf-llvm" >> mk/build.mk && \
echo "SRC_HC_OPTS += -fllvm" >> mk/build.mk && \
echo "SRC_CC_OPTS += -fno-pie" >> mk/build.mk && \
echo "BeConservative = YES" >> mk/build.mk && \
echo "INTEGER_LIBRARY = integer-simple" >> mk/build.mk && \
echo "HADDOCK_DOCS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_HTML = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PS = NO" >> mk/build.mk && \
echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk && \
echo "V = 0" >> mk/build.mk && \
./configure \
--target=$triple \
--prefix=/usr
Expand All @@ -132,12 +136,10 @@ run $crosscc unlit.c -o $(find $destdir -name unlit)

# remove target prefix from stage2 binaries
workdir $destdir/usr/bin
run (for i in $triple-* ; do ln -s $i ${i#$triple-} ; done )
copy bootstrap/$arch/settings /tmp/settings
run mv /tmp/settings $(find $destdir -name settings -type f)
run rm -fr $destdir/usr/share/doc
run (for i in $triple-* ; do ln -s $i ${i#$triple-} || /bin/true; done ) && \
rm -fr $destdir/usr/share/doc

workdir $tardir
# Compress to xz via pixz because xz is normally too
# old for -TN multithreads
run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$triple.tar.xz .
run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$destarch.tar.xz .
Loading

0 comments on commit da0e932

Please sign in to comment.