MacRuby Roundup: 0.7 Released, GCD-based Web Server, BridgeSupport
MacRuby 0.7 (actually 0.7.1) is out and contains many bug fixes and improvements to the Ruby compatibility:
MacRuby 0.7 is the first release of MacRuby that targets the 1.9.2 version of Ruby, and therefore a number of new features have been re-implemented or backported.
This release passes an average of 90% of total RubySpecs, from about 82% for the previous release.
MacRuby 0.7.1, together with the BridgeSupport tool, completes the scripting support for Cocoa, Objective-C and C constructs. Previous versions of MacRuby still had gaps in certain areas, eg. for the blocks feature Apple has added to it's C-based languages. Now it's possible to hand a Ruby Proc to APIs that expect C blocks, and vice versa.
The reason for these features weren't supported was missing metadata; BridgeSupport is the solution. Built on top of LLVM's Clang parsers, it looks at the library sources and generates metadata that MacRuby can use to understand what the library expects, ie. blocks, symbols, etc. The source for BridgeSupport shows how Clang is used to determine and generate the metadata.
MacRuby supports parallel Ruby threads (ie. no GIL), which is very useful when used with Mac OS X Snow Leopard's system wide thread pool system Grand Central Dispatch (GCD).
A demonstration of the MacRuby integration with GCD is the new web server ControlTower, written in MacRuby. Built on Rack, it handles it's requests by delegating them to a GCD queue, which can process the requests serially or in parallel. The release notes for ControlTower give an overview of the architecture, as well as some performance numbers compared with the Thin server.
While ControlTower supports Rack, Rails users shouldn't get their hopes up just yet - MacRuby 0.7.1 doesn't support Rails 3. The team expects the next MacRuby release to support Rails.
Another Mac OS X feature that's expoѕed in MacRuby 0.7 is the Sandbox, which allows to limit the privileges of an OS process. The Sandbox can be set to deny network access, filesystem access, etc. It's not quite exclusive to MacRuby - other Ruby implementations can use the Mac OS X Sandbox feature too with the Playpen extensions.
Finally, an interesting nugget from the MacRuby release notes shows some of the work necessary to get all kinds of Ruby code to run fast:
A basic interpreter has been implemented and is now used to evaluate cold paths, determined at compilation time using simple heuristics. As an example, simple #eval statements creating code, a common pattern in Ruby libraries, now run significantly faster.
Developers who want to get started with MacRuby should take a look at "MacRuby: The Definitive Guide", a book that's currently being written by Matt Aimonetti for O'Reilly, and that's available online for free.