[Haskell-cafe] Haskell on OpenWRT

Tomas Carnecky tomas.carnecky at gmail.com
Sun Apr 10 20:03:42 UTC 2016

Mac OS X as the host is unbelievably painful. It's easier to have the host
and target be the same OS (linux + linux).

You don't need a full system (gentoo) to use GHC + musl in static linking
mode. Just an appropriate cross-compiler toolchain. crosstools-ng can be
configured so that the compiler always produces a static build (run ct-ng
menuconfig, and look through the options. The UI should be familiar if
you've ever used the Linux kernel menuconfig facility).

On Sun, Apr 10, 2016 at 9:57 PM Patrick Pelletier <code at funwithsoftware.org>

> Thanks!  I'll take a look at building a cross-compiler, since it worked
> out for you.  I'd been a little afraid to try.  (I previously had a bad
> experience building ghc as a cross-compiler, but that was with Android as
> the target and Mac OS X as the host.  The issues I encountered were mostly
> when it tried to link ELF binaries with the Mach-O linker, or vice versa.
> But with both host and target being Linux, the linker issues can probably
> be swept under the rug.)
> The C cross compiler shouldn't be a problem, since OpenWRT's "buildroot"
> builds a cross-compiler automatically.  (Though if for any reason that
> turns out to be a problem, thanks for the tip about crosstool-ng.)
> Ideally, I'd love to integrate ghc into OpenWRT's buildroot so that
> packages written in Haskell could be built as easily and in the same way as
> packages written in C.  But I still have a lot to learn before I attempt
> that.
> My boot device is an SD card, so space for static binaries shouldn't be a
> problem.  I already have several gigabytes, which should be more than
> enough, and if for some reason I needed more space, I could swap in a
> larger SD card, or add more space via USB or mSATA.
> I was aware of Marios Titas's "GHC + musl = easier static linking", but
> wasn't really thrilled at the idea of needing an install of Gentoo-musl to
> host it.  (But I can certainly try that if I have to.)  Or I could just use
> my OpenWRT box to host the GHC-musl, but I'm running into issues with
> getting gcc to run on the target, which I'm currently following up with the
> OpenWRT community.
> Thanks for the ideas!  I'm sure that one way or another I'll be able to
> get it working.
> --Patrick
> On 4/10/16 8:40 AM, Tomas Carnecky wrote:
> I was able to compile Haskell for a mips-linux-musl target (
> https://onion.io/omega). Most problems were due to the different
> architecture (MIPS) than musl. Once you have a C cross-compiler (I used
> <http://crosstool-ng.org/>http://crosstool-ng.org/ to built the
> cross-compiler toolchain), compiling GHC as a cross compiler for that
> target and then a Haskell application shouldn't be a problem.
> If you have enough disk space on the target, I would suggest that you
> compile your Haskell application into a static binary.
> On Sat, Apr 9, 2016 at 10:47 AM Lana Black <lanablack at amok.cc>
> <lanablack at amok.cc> wrote:
>> You will probably have better luck using ghc with musl‎.
>> Check out this thread: ‎
>> https://mail.haskell.org/pipermail/haskell-cafe/2015-May/119843.html
>>   Original Message
>> From: Patrick Pelletier
>> Sent: Saturday, April 9, 2016 7:54 AM
>> To: haskell-cafe
>> Subject: [Haskell-cafe] Haskell on OpenWRT
>> Has anyone had any success running Haskell programs on OpenWRT?
>> Specifically, I'm running OpenWRT on x86_64, so processor architecture
>> shouldn't be an issue. However, by default OpenWRT uses musl as its C
>> library, so binaries from a "normal" Linux system wouldn't be compatible
>> with OpenWRT.
>> I attempted to get around this problem by building an OpenWRT image with
>> glibc as the C library. In theory, that ought to solve the problem. In
>> practice, my program (a simple hello-world type program, which runs fine
>> on Ubuntu) hung, printing nothing, using nearly all of one core, and was
>> unkillable by any signal other than SIGKILL. If left alone to run, it
>> eventually used all available memory and then died.
>> I took a look at ldd, to see if there were any clues there. On my
>> Ubuntu 12.04 machine, where I compiled the program (using ghc 7.4.1), I
>> get:
>> ppelletier at patrick64:~/programming/haskell$ ldd contact
>> linux-vdso.so.1 => (0x00007fff36f50000)
>> libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10
>> (0x00007f8d49cf8000)
>> libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6
>> (0x00007f8d49af0000)
>> libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8d497f3000)
>> librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f8d495eb000)
>> libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8d493e7000)
>> libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8d49028000)
>> libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
>> (0x00007f8d48e0b000)
>> /lib64/ld-linux-x86-64.so.2 (0x00007f8d49f8d000)
>> On my OpenWRT (trunk) box, I get:
>> root at OpenWrt:~# ldd /tmp/contact
>> linux-vdso.so.1 (0x00007ffd2afcc000)
>> libgmp.so.10 => /usr/lib/libgmp.so.10 (0x00007f27a057a000)
>> libffi.so.6 => /usr/lib/libffi.so.6 (0x00007f27a0373000)
>> libm.so.6 => /lib/libm.so.6 (0x00007f27a0080000)
>> librt.so.1 => /lib/librt.so.1 (0x00007f279fe79000)
>> libdl.so.2 => /lib/libdl.so.2 (0x00007f279fc76000)
>> libc.so.6 => /lib/libc.so.6 (0x00007f279f906000)
>> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f279f6f4000)
>> libpthread.so.0 => /lib/libpthread.so.0 (0x00007f279f4d9000)
>> /lib64/ld-linux-x86-64.so.2 (0x00007f27a07dc000)
>> This is almost the same, except it has "libgcc_s.so.1", while on the
>> Ubuntu box it does not.
>> I'd welcome any ideas on how to solve (or at least diagnose) this
>> problem. I'd also be interested in any thoughts on the broader question
>> of running Haskell programs on OpenWRT.
>> Thanks,
>> --Patrick
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160410/b107f5d2/attachment.html>

More information about the Haskell-Cafe mailing list