Skip to content
 
 

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Porting GHC to Haiku

This builds on previous work for GHC-7.8.3, but is a clean port on top of GHC-8.6, including cross-compiling.

Currently, we only have GHC for 32-bit Haiku, as there are issues with how GHC creates relocations with PIC on 64-bit Haiku, preventing linking from succeeding.

Building the Haiku Cross-Compiler

I have created a repo to ease the task of building a Haiku cross-compiler and associated sysroot (where build dependencies are unpacked).

git clone https://github.com/jessicah/cross-compiler
cd cross-compiler
export CROSSTOOLS=$(pwd)
./build-rootfs.sh x86_gcc2h

This will result in two cross-compilers, the gcc2 compiler we don't need, and the gcc4+ compiler. Due to Haiku's system layout, we need to build it this way. We'll also have a generated package_extract.sh wrapper script for the package command, which we'll use for unpacking build dependencies.

The page with up-to-date links to packages we'll need is available at: https://eu.hpkg.haiku-os.org/haikuports/master/x86_gcc2/current/packages/

We will need to download the following packages (versions omitted):

  • libiconv_x86.hpkg
  • libiconv_x86_devel.hpkg
  • ncurses6_x86.hpkg
  • ncurses6_x86_devel.hpkg
for file in *.hpkg; do
  $CROSSTOOLS/package_extract.sh $file
done

Also, update PATH to include our needed cross-compiler: export PATH=$CROSSTOOLS/generated/cross-tools-x86/bin:$PATH

Building the GHC Cross-Compiler

I recommend using a Linux machine with GHC-8.6; ghcup is recommended for obtaining a GHC-8.6 install.

Install ghcup from https://www.haskell.org/ghcup/, then install GHC with ghcup install ghc 8.6.5.

You'll also need to install alex and happy with cabal:

  • cabal install happy --constraint 'happy < 1.20'
  • cabal install alex

There are also a couple of patches to apply, in the source directory:

  • patch -Np1 < ../patches/0001-haiku-add-support-for-8.6.patch
  • pushd libraries/directory && patch -Np1 < ../../../patches/0001-haiku-add-platform-app-data-location.patch && popd
  • pushd libraries/Cabal && patch -Np1 < ../../../patches/0001-haiku-add-platform-support.patch && popd

And then we can start building:

perl boot
./configure --target=i586-pc-haiku
make
make binary-dist

You'll end up with a tarball that you can copy to your Haiku install and install:

setarch x86
./configure --prefix=/boot/home/config/non-packaged
make install

Building GHC on Haiku


Now let's build a self-hosted compiler on Haiku...

This requires alex and happy to be installed, so I have used versions alex-3.1.7 and happy-1.19.12, which appear to function okay thus far.

wget https://hackage.haskell.org/package/happy-1.19.12/happy-1.19.12.tar.gz
tar zxf happy-1.19.12.tar.gz
cd happy-1.19.12
runhaskell Setup.hs configure
runhaskell Setup.hs build
runhaskell Setup.hs install

cd ..

wget https://hackage.haskell.org/package/alex-3.1.7/alex-3.1.7.tar.gz
tar zxf alex-3.1.7.tar.gz
cd alex-3.1.7
patch -Np1 < ../../patches/0001-remove-quickcheck.patch
runhaskell Setup.lhs configure
runhaskell Setup.lhs build
runhaskell Setup.lhs install

Then need to install the cross-compiled binary distribution:

# Download the release for your target architecture:
# export ARCH=i386
# export ARCH=x86_64
wget https://github.com/jessicah/haiku-ghc/releases/download/v8.6.5-1/ghc-8.6.5-$ARCH-unknown-haiku.tar.xz
tar xJf ghc-8.6.5-$ARCH-unknown-haiku.tar.xz
cd ghc-8.6.5-unknown-haiku
boot
./configure --prefix=/boot/home/config/non-packaged
make install

And then the rest is similar to cross-compiling with a source tarball...

boot
./configure --prefix=/boot/home/config/non-packaged
make

For x86_64, only an "unregisterised" build currently works, so add the --enable-unregisterised compiler flag when configuring.

The problem with x86_64 is tracked at https://gitlab.haskell.org/ghc/ghc/-/issues/17338

About

Instructions+patches for building GHC for Haiku

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors