Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Haskell on the Raspberry Pi

I am trying to compile GHC 7.6.3 on the Raspberry Pi. The 7.4 version of GHC that ships with Raspbian, does not support ghci. I intend to package v 7.6.3 and make it available.

After a looong time, I get this error on the Pi:

HC [stage 0] utils/hp2ps/dist/build/Key.o
HC [stage 0] utils/hp2ps/dist/build/PsFile.o
HC [stage 0] utils/hp2ps/dist/build/Shade.o
HC [stage 0] utils/hp2ps/dist/build/Utilities.o
"inplace/bin/mkdirhier" utils/hp2ps/dist/build/tmp//.
HC [stage 0] utils/hp2ps/dist/build/tmp/hp2ps
Warning: -rtsopts and -with-rtsopts have no effect with -no-hs-main.
Call hs_init_ghc() from your main() function to set these options.
"cp" -p utils/hp2ps/dist/build/tmp/hp2ps inplace/bin/hp2ps
cp driver/ghc-usage.txt inplace/lib/ghc-usage.txt
cp driver/ghci-usage.txt inplace/lib/ghci-usage.txt
HC [stage 0] utils/genapply/dist/build/GenApply.o
"inplace/bin/mkdirhier" utils/genapply/dist/build/tmp//.
HC [stage 0] utils/genapply/dist/build/tmp/genapply
"cp" -p utils/genapply/dist/build/tmp/genapply inplace/bin/genapply
HC [stage 1] libraries/ghc-prim/dist-install/build/GHC/Types.o
Stack dump:
0.  Program arguments: /usr/bin/llc -O3 -relocation-model=static /tmp/ghc467_0/ghc467_0.bc  -o /tmp/ghc467_0/ghc467_0.lm_s --enable-tbaa=true 
1.  Running pass 'Function Pass Manager' on module '/tmp/ghc467_0/ghc467_0.bc'.
2.  Running pass 'ARM Instruction Selection' on function '@ghczmprim_GHCziTypes_Dzh_info'
/tmp/ghc467_0/ghc467_0.lm_s: openBinaryFile: does not exist (No such file or directory)
make[1]: *** [libraries/ghc-prim/dist-install/build/GHC/Types.o] Error 1
make: *** [all] Error 2

real    308m59.437s
user    292m8.320s
sys     10m18.220s

Any idea what is going wrong?

How can I end up with missing intermediate files, that are produced by the build system?

like image 530
Nick Kanellopoulos Avatar asked Jul 20 '13 17:07

Nick Kanellopoulos


1 Answers

I got GHC-7.8.3 compiled with Raspberry PI from upstream sources. It's not very fast, but it gets the job done:

pi@arlanda ~ $ ghci
GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> 1+1
2

Key things are to do the following:

  1. Have enough memory. Plug in an external hard disk and create a 4-gigabyte swap partition. First in fdisk select the partition type to be Linux swap, then do mkswap /dev/sdXX, finally do swapon /dev/sdXX, where XX is the disk id letter and partition number.
  2. Update kernel to the latest version with rpi-update to prevent hangs. I had also smsc95xx.turbo_mode=N slub_debug=FP added to the end of kernel command line in /boot/cmdline.txt file.
  3. Install gold linker with apt-get install binutils-gold, because regular ld.bfd will fail to create the dynamic libraries. The problem is that you can't use gold for linking everything, but need to link the stage 1 with ld.bfd. You need to follow the instructions in this script (original information from here) with the exception that you need to use ld.bfd for running the initial ./configure call too.
  4. Have patience -- the compilation will take days.
like image 118
ipuustin Avatar answered Oct 31 '22 23:10

ipuustin