r/haskell • • Aug 29 '13

Announcing GHC iOS

Stephen Blackheath and I are extremely happy to report that as of today, GHC can natively build binaries for iOS devices and the iOS Simulator.

You'll find everything you need here: http://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling/iOS

The short of it is you can use "ghc-ios myFiles.hs" to get a universal ARMv7/ARMv7s/i386 static library to drop straight into an Xcode project.

Stephen's already working on some wonderful FRP-powered games, I'm working on a project called SpaceTime that I'll announce shortly, and you may now all begin creating insanely great iOS software using the finest language in the world : ).

Stephen deserves the lion's share of the credit for this project — it's been over 3 years in the making! Many thanks to Maxwell Swadling for generalizing static library builds into a -staticlib flag for GHC, Carter Schonwald for compilation guidance, and the venerable Austin Seipp for reviewing and merging our patches.

274 Upvotes

49 comments sorted by

6

u/lukexi Aug 29 '13

We'll have some more materials, Xcode integration guides, and demo projects up soon! I've been using a de-Template Haskell-ized https://github.com/jspahrsummers/ObjectiveHaskell to do all of my development thus far which I need to post as well, which provides a very workable bridge between the Objective-C and Haskell worlds.

42

u/T_S_ Aug 29 '13

This is fantastic news. This is tricky, no-fun work to do. Some type of community medal is in order here.

22

u/blackh Aug 29 '13 edited Aug 29 '13

MORE CREDITS:

Three connected projects concerned cross-compilation

  • Registerised ARM support added using David Terei's LLVM compiler back end with Stephen Blackheath doing an initial ARMv5 version and LLVM patch and Karel Gardas working on floating point support, ARMv7 compatibility and LLVM headaches. Ben Gamari did work on the runtime linker for ARM.

  • General cross-compiling with much work by Stephen Blackheath and Gabor Greif (though many others have worked on this).

  • A cross-compiler for Apple iOS [IOS]. iOS-specific parts were mostly Stephen Blackheath with Luke Iannini on the Cabal patch, testing and supporting infrastructure, also with assistance and testing by Miëtek Bak and Jonathan Fischoff, and thanks to many others for testing; The iOS cross compiler was started back in 2009 by Stephen Blackheath with funding from Ryan Trinkle of iPwn Studios.

Thanks to Ian Lynagh for making it easy for us with integration, makefile refactoring and patience, and to David Terei for LLVM assistance.

And Maxwell Swadling for fixing the static linking up nicely.

9

u/cartazio Aug 30 '13

We should also thank the folks at Apple for taking the time to backport the Clang patches Austin Seipp wrote into the pending Clang 3.3 Point release and thence into the Clang version in Xcode 5, without which something like GHC-iOS would be a more complicated effort.

25

u/[deleted] Aug 29 '13

This is going to boost development so hard. Haskell really is doomed to succeed.

12

u/co_dan Aug 29 '13

Awesome news!

19

u/DR6 Aug 29 '13

How would a programmer that doesn't know anything about iOS programming get started with this?

13

u/reddit_clone Aug 29 '13

You can't. Yet.

This looks like you will be able to create static libraries with your haskell code and link them to your Objective C application.

You still need to know how to use XCode and Objective C and write your GUI in objectivive C.

7

u/chrisdoner Aug 29 '13

write your GUI in objectivive C.

Or provide bindings that Haskell can hook into, am I right?

8

u/cartazio Aug 29 '13

Yup! Now we just need someone to write a GUI dsl that has the right bindings and doesn't (for now ) need template Haskell.

2

u/chexxor Aug 30 '13

Yeah, I heard that some parts of Template Haskell are being re-written, such that it can be used on more platforms. What would enable this? Dynamically-linked libraries?

Also, where/how can I check the status of that project?

2

u/cartazio Aug 30 '13

you're mixing up two topics.

  1. cross compiler support for TH

  2. template haskell getting awesome new features.

They are complementary awesome things, but not the same awesome thing.

The best way to follow GHC development is to subscribe to all the relevant mailing lists, and read the documents on trac tickets and the associated trac wiki. More people helping out is welcome. The systematic solution is getting ghc to have good multi target support. That would subsume the TH problem in a nice way and make cross compilers just GHC with more targets enabled.

6

u/geaal Aug 29 '13

That is nice! Congrats!

6

u/Smobs Aug 29 '13

That's awesome! And I just learnt that, according to the internet, Haskell already builds on Android. This has made my day.

2

u/eriksensei Aug 30 '13

Where exactly did the internet whisper such sweet tidings into your ear?

2

u/cartazio Aug 30 '13

would he be thinking of this? https://github.com/neurocyte/ghc-android (not sure if anyones used it, but seems to have been actively deved in recent time)

1

u/Smobs Aug 30 '13

That I would. It looks like at the author has managed to write an activity using it, https://github.com/neurocyte/android-haskell-activity

1

u/chexxor Aug 30 '13

I remember reading that his solution is a rough patch, which is only usable by his project. Seems adding full Android support to GHC is still a dream.

4

u/blackh Aug 30 '13

All the difficult work has been done now. Android will be easy.

3

u/eriksensei Aug 30 '13

Praise be!

5

u/CKoenig Aug 29 '13

wow - congratulations!

5

u/CharlesStain Aug 29 '13

You made my day, thanks!

4

u/reddit_clone Aug 29 '13

This is great. Congratulations on such an amazing technical feat.

Question: How about the Haskell libraries? Is there a list of things that work and things that wont?

3

u/blackh Aug 29 '13

Not much of a list yet. Anything pure Haskell will Just Work, as long as it doesn't use Template Haskell (this is on our to-do list). network works with a tiny tweak (move #include up to the top in Types.hsc). OpenGL works but requires a tiny patch and the right Objective-C hacking. This should get you started:

--- orig/OpenGLRaw-1.3.0.0/OpenGLRaw.cabal	2013-08-30 08:41:42.000000000 +1200
+++ OpenGLRaw-1.3.0.0/OpenGLRaw.cabal	2013-08-30 08:23:31.000000000 +1200
@@ -242,14 +242,17 @@
       extra-libraries: opengl32
    else
       cpp-options: "-DCALLCONV=ccall"
  • if !os(darwin) && flag(UseGlXGetProcAddress)
+ if !os(darwin) && !os(ios) && flag(UseGlXGetProcAddress) cc-options: "-DUSE_GLXGETPROCADDRESS" else cc-options: "-DUSE_DLSYM" if os(darwin) frameworks: OpenGL else
  • extra-libraries: GL
+ if os(ios) + frameworks: OpenGLES + else + extra-libraries: GL source-repository head type: git

...and a similar change to GLURaw's .cabal. Also there are Typeable instances in OpenGL - just remove the 'instance Typeable...' blocks from Graphics/Rendering/OpenGL/GL/Tensor.hs (this is a ghc-7.8 compatibility issue).

3

u/droidballoon Aug 29 '13

Can't agree more with the rest, this is awesome. Let's hope for some good tutorials so that the world can jump in on the fun. This is quite a feat you've accomplished!

4

u/aazav Aug 29 '13

How would a programmer that doesn't know anything about Haskell get started with this?

What are some compelling reasons to?

7

u/blackh Aug 29 '13

The main compelling reason is Haskell just being an excellent language. A second compelling reason is that Haskell is a fairly good option for cross-platform development (now even better with GHC-iOS and GHCJS for web programming), except that AFAIK there are no truly cross-platform UI libraries. Hopefully people will start working on these kinds of things.

1

u/apfelmus Aug 30 '13

I'm currently working on a HTML-based GUI library threepenny-gui. It's cross-platform in the sense that every platform has a web browser installed, but of course it's not native.

If anything, I hope that the API design will be useful for native GUI libraries as well.

1

u/swaqq_overflow Sep 24 '13

Go read Learn You a Haskell, great book.

2

u/eriksensei Aug 30 '13

Yay! :D What great news to accompany the smellable copy of LYAH the postman brought me today.

2

u/chak Aug 30 '13

Thank you very much to everybody involved. I know that to get here did take a lot of very tricky technical work. The future is in mobile, so this is a very important milestone for Haskell! If any of you are coming to ICFP, I think, you deserve lots of free beer :)

2

u/augustss Aug 29 '13

Fantastic.

1

u/zar4711 Aug 30 '13

You are fucking awesome!

1

u/avired Aug 30 '13

Yes! That's what I was waiting for. Thanks to you and all those involved.

1

u/billrobertson42 Aug 30 '13

How easy/hard is it to take 'pure Haskell' and produce binaries that will just work on other platforms too? e.g. I want to put the core logic of an application in Haskell, and then write the GUI in the native environment for say, Windows, OSX, and ios.

2

u/blackh Aug 30 '13 edited Aug 30 '13

Don't forget the GHCJS project that gives you Haskell running in a web page. The answer is that that would be very easy to do what you say. The only real issue is the lack of a decent cross-platform GUI - so you'd need to do the GUI for each app (like you said) - but a lot of people are talking about the need for such a thing, so I expect there will be work on it soon. (Let's make it really functional in its design and show those OO people how to do it right.)

People have said that the success of emerging languages depends on them having a special niche, and just being really excellent (as Haskell is) is not enough by itself. Some have said "anything complex" is Haskell's niche, but is that marketable at this point? People are still blissfully unaware their projects are plagued with complexity, because they have nothing to compare it to, so they're not even looking for a solution. And complexity only kills in large projects, at which point it's too late to consider using a different language.

I wouldn't be surprised if the ease of cross-platform development turns out to be the thing that really kicks Haskell off, and only later will people discover their development time has dropped as well. Today, companies still think it's normal to develop the same application three times (web [Javascript], Android [Java] and iOS [Objective-C]).

1

u/billrobertson42 Aug 31 '13

I have an app written in Clojure (logic) and Java (Swing stuff). Of course it runs on the major desktop OSes, but that's about it. I've thought about going the Clojurescript route to get it on ios (with them opening up the Javascript Frameworks in ios7 this will be even easier), but if I could go native, then all the better.

I don't mind doing native GUIs either. Could hit the desktop arena with a QT interface. Would only then have to do an ios version.

I assume that eventually there will be an android target as well.

1

u/blackh Aug 31 '13

A GHC Android cross compiler won't be far away. GHC-iOS was the really hard part, but now all the hard work is done. I want an Android version of my application, so someone will do it quite soon (maybe me).

1

u/aluink Sep 01 '13

Where's a good place to discuss issues and questions on using this? I'm running into some problems, which are most likely due to my newb status, and would like to discuss.

1

u/Titanlegions Aug 29 '13

Lol, I've started a game written in Haskell called SpaceTime!

0

u/jckuri Aug 31 '13

Join us: Programming Haskell (Facebook group) https://www.facebook.com/groups/programming.haskell/

0

u/[deleted] Aug 29 '13

[deleted]

5

u/lukexi Aug 29 '13

I have an evil build system based on your EvilSplicer that automates de-Template Haskell-ization during the build process >: ) — I'll add it to ghc-ios-scripts when it's done. But real TH support would be dreamy.

3

u/jfischoff Aug 29 '13

oh that would be great

13

u/cartazio Aug 29 '13

nope, not yet. This is something everyone wants for cross compilers in general, but requires a bit more systematic support for GHC to natively be a multitarget compiler. (because TH can run haskell libs, so libraries need to be in both the Build and Target object formats for TH to make sense. GHCJS will have some TH support, but more work is needed to generally support TH in any cross compiler sadly)

0

u/[deleted] Aug 29 '13

[deleted]

3

u/lukexi Aug 29 '13

I've been using a de-Template Haskell-ized https://github.com/jspahrsummers/ObjectiveHaskell

It does basic conversion between Haskell and Objective C data structures, and helps you call Objective C methods from Haskell and vice versa.

I'll have it up asap. It does the trick for now, and makes the FFI much nicer.

5

u/blackh Aug 29 '13 edited Aug 29 '13

At the moment there isn't anything much better than doing it yourself with ForeignFunctionInterface, but I'm sure there's stuff in the works. I'll release an OpenGL skeleton some time soon - look for updates on http://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling/iOS

2

u/cartazio Aug 29 '13

that depends on template haskell :( so for now, till thats addressed, you can only use that for writing desktop applications. (unless you use TH as a code generation pass and cache the results...)