Nu on Linux

Lately I have been working on a version of Nu that I have modified to run on Linux. For now, it’s running on Ubuntu (Server 7.10), but other distributions can be easily supported. As you might imagine, there are several things that make this interesting.

Challenges

1. Apple uses a custom version of GCC to compile its dialect of Objective-C. While many Apple changes have made it into the trunk, many are still out. However, all the source for Apple’s changes appears to be on Apple’s darwinsource web site. But even with that source available, I think that most Linux users would prefer to work with the stock versions of GCC that ship with common distributions.

2. There are two distinctly different Objective-C runtimes. For historical reasons, Apple’s is called the “NeXT” runtime and non-Apple systems use the “GNU” runtime. Apple’s runtime appears to be cleaner and faster (no surprise, since Apple is the largest and most successful corporate user of Objective-C), but GNUstep and most other Objective-C software on non-Apple systems uses the GNU runtime. Both runtimes are open source. The GNU runtime is GPL’ed, the Apple runtime is released under the APSL.

3. There is no obvious replacement for the Foundation framework, which Nu uses for much of its implementation. So far, I’ve looked at three possibilities:

a. the GNUstep “base” library. This may be the most mature, but it is LGPLed, seems a bit heavy, and has a very established style that developers coming from the Apple world may not like (such as using shared libraries instead of framework bundles).

b. Christopher Lloyd’s Cocotron project. This looks promising, but requires a custom runtime and has an infuriating build system that requires you to first build a custom gcc on OS X, copy over a bunch of headers and libraries from your target system, and then set up Xcode to cross-compile. To be fair, Lloyd’s focus is more on Windows application development, but to me it seems silly to set up a cross-compilation system to target a Linux desktop/server installation. So because it requires a non-standard gcc, for now I’ve dropped Cocotron in favor of the most lightweight choice of the three, which is…

libFoundation. It was written by Mirceau Oancea and Ovidiu Predescu and is currently maintained by Helge Hess. It is used in a set of frameworks called sope. libFoundation is BSD licensed and was relatively easy to build. But because its build system requires GNUstep (which I’m avoiding for now), I’m building it with a makefile that I’ve written myself (and I write terrible makefiles).

Progress

I’ve been doing this work in a VMware virtual machine running Ubuntu, and keeping my files outside VMware and NFS-exporting them into my Ubuntu VM. That’s let me continue to use TextMate as my text editor. It has also been handy a few times when I’ve accidentally bricked my VMware images and had to start over from backups.

For the last few years I’ve been completely off of Linux and exclusively working on OS X. But despite that, I managed to get from my first VMware install to a fairly workable Linux version of Nu in a little over a week, and a big part of that time was spent just figuring out how to build debuggable versions of the GNU runtime and libFoundation.

That was faster than I expected. Partly that’s because by now, I have a lot of experience working with Objective-C runtimes. But more importantly, this time my Objective-C runtime and Foundation library are fully open-source and debuggable. Until you’ve experienced it, you have no idea how much easier it is to work on a fully open-source stack.

Next Steps

I hope to get this into shape to share soon, but first I want to clean up and merge my changes back into the main Nu sources. There are a lot of differences between the two runtimes, and I want to try to minimize their effects before going much further. For now I’m staying with the GNU runtime, because even if I manage to compile the Apple runtime on Linux, there are likely to be many problems due to Mach/Linux differences and Apple’s GCC customizations.

There are still many Nu regression failures, but so far they seem to be due to differences between libFoundation and Apple’s Foundation classes.

But wow. It’s possible to run Nu on Linux, and it doesn’t even seem to be that hard. And once Nu goes cross-platform, perhaps RubyCocoa and PyObjC will too. Right, Laurent & Ronald?

7 comments ↓

#1 Colin Barrett on February 02, 2008 at 00:01 GMT

You might also check out http://www.objc-substrate.org/

#2 Colin Barrett on February 02, 2008 at 00:03 GMT

Now with actual linkification: http://www.objc-substrate.org/

#3 charles on February 02, 2008 at 15:25 GMT

Unfortunately, “In development for a number of years, Cocotron has been released, beating Substrate to the punch. Thus, little reason exists to continue development on the Substrate project.” But there might still be bits to use there

#4 Joachim Bengtsson on February 03, 2008 at 03:02 GMT

This is great news! I’ve always wanted to use the objc runtime cross-platform, but it’s highly annoying that the gnu and the apple/next runtimes are different. If only there was one, very simple to install runtime and dev environment that worked across platforms… Maybe you’re laying the foundation for something really big here :)

#5 steve on February 05, 2008 at 18:27 GMT

libFoundation looks like a quick path to get Nu going, but GNUstep has the GUI interface. I would like to use Nu in a cross-platform way to access graphics.

For the time being, I can just pad with Objective C and C stubs, but am looking forwards to a single environment to handle OS X, Linux, Windows and anything else.

Great work, I haven’t seen another project start so well before. It’s not just Nu the language, but also the set of tools like nuke, nubile, nutest…

#6 Christopher Lloyd on February 19, 2008 at 15:29 GMT

The goal of the custom runtime in Cocotron and custom gcc toolchain are to offer compatibility with the Apple runtime API and bundle conventions. -fnext-runtime in the stock gcc basically does not work and -F and -framework are not there, thus the patches. This is also an avenue for incorporating Apple compiler changes we want.

If you don’t want to use Xcode, or have your users use Xcode then I understand why the cross-compiler is not appealing. It does avoid a lot of effort in creating a build system though, especially if you have existing Xcode projects.

If building a multiple projects for multiple platforms with one click is silly, call me silly!

Good luck, Chris

#7 Tim Burks on February 20, 2008 at 11:28 GMT

Chris,

Thanks for your comments! I learned a lot from your blog series on the two runtimes. I agree about the problems with the NeXT runtime in the stock gcc and would like to see better integration of Apple’s changes into the gcc core.

We seem to be trying to reduce the barrier to entry for two different audiences. Cocotron appears aimed at getting Apple/Xcode developers access to other platforms where with Nu/Linux, I hope to make Objective-C more useful for developers in the Linux and free software worlds.

Looking forward to convergence,

Tim

Leave a Comment (sign in with Twitter)