Current Version: 0.6

Check out the tutorial, resources     and examples that are available.

Blog Overview

The MacRuby Blog

2010-04-30
By Laurent Sansonetti

We are pleased to announce the immediate availability of MacRuby 0.6. In the 3 months since the previous release, a number of new features have been added and the overall stability of MacRuby has been substantially improved.

You can download it from here. Please note that this package only runs on Snow Leopard (10.6). Users on Leopard (10.5) can also use MacRuby by building the sources from our repository.

Please give it a try and let us know of any problems you find.

You can read about all the changes from the release notes e-mail on the mailing-list, or keep up with the most visible changes here.

Stable for Cocoa Development

In this release, we believe that MacRuby is now stable enough to consider using it to develop Cocoa applications.

Since 0.5’s release, we have worked closely with a number of early-adopter developers in finding and fixing a great number of bugs, as well as improving the overall process of creating Cocoa apps in MacRuby. We believe that MacRuby is now stable enough to permit the creation of complete and functional Cocoa applications that have access to the full suite of Cocoa APIs.

The “Compile” target in Xcode allows an application to be ahead-of-time compiled to machine code, allowing the developer to avoid including the Ruby source in a shipping application.

Debugging

Experimental support for debugging landed in this release.

The compiler, under debug mode, is now generating special traps inside the code. The debugger connects to these traps and allows not only basic debugging operations but also code evaluation.

The macrubyd command-line executable pilots the debugger. It provides a gdb-like experience. Please note that it is not entirely finished and it also has not been exhaustively tested.

Let’s consider the following broken program:

$ cat t.rb 
def foo(n)
  bar(n)
end
5.times do |i|
  foo(i)
end

And start it inside the debugger.

$ macrubyd t.rb 
Starting program.
1	def foo(n)
t.rb:1> c
/Users/lrz/src/t.rb:2:in `foo:': undefined method `bar' for main:TopLevel (NoMethodError)
	from /Users/lrz/src/t.rb:5:in `block'
	from /Users/lrz/src/t.rb:4:in `<main>'
Program exited.

We immediately get an exception at line 2. We can restart the debugger, break at this line, then examine the argument and the backtrace.

> r
Starting program.
1	def foo(n)
t.rb:1> b t.rb:2
Added breakpoint 1.
1	def foo(n)
t.rb:1> c
2	  bar(n)
t.rb:2> p n
=> 0
2	  bar(n)
t.rb:2> bt
#0	/Users/lrz/src/t.rb:2:in `foo:'
#1	/Users/lrz/src/t.rb:5:in `block'
#2	/Users/lrz/src/t.rb:4:in `<main>'
2	  bar(n)

Then, we can define the missing method on the fly and resume the execution of the program after disabling the breakpoint.

t.rb:2> p def bar(x); puts "-> #{x}"; end
=> nil
2	  bar(n)
t.rb:2> disable 1
Disabled breakpoint 1.
2	  bar(n)
t.rb:2> c
-> 0
-> 1
-> 2
-> 3
-> 4
Program exited.

An interesting feature of the debugger is that it has been abstracted into a simple Objective-C API, of which macrubyd is just one client. In the future we might see other clients.

Higher-Level APIs for Grand Central Dispatch

GCD is a revolutionary approach to multicore computing that is woven throughout the fabric of Mac OS X version 10.6 Snow Leopard. It is supported in MacRuby since version 0.5, through the Dispatch module.

In MacRuby 0.6, we improved the existing native bindings with additional, higher-level abstractions and convenience APIs in the “dispatch” library. We believe these features will help reduce the learning curve for GCD.

The new “dispatch” library exposes the Job class, which is likely the easiest way to perform concurrent work. Say you have a complex, long-running calculation you want to happen in the background. Create a job by passing Dispatch::Job’s initializer the block you want to execute:

$ /usr/local/bin/macirb --simple-prompt
>> require 'dispatch'
=> true
>> job = Dispatch::Job.new { Math.sqrt(10**100) }
=> #<Dispatch::Job:0x40075d1e0 @queue=com.apple.root.default-priority @group=#<Dispatch::Group:0x40073c2c0> @values=[1.0e+50]>

This atomically adds the block to GCD’s default concurrent queue, then returns immediately, so you don’t stall the main thread.

The downside is that you don’t know exactly when your job will execute. The #value method can be used to obtain the result of executing that block.

>> value = job.value
=> 1.0e+50

This will wait until the value has been calculated, allowing it to be used as an explicit Future. However, this may stall the main thread indefinitely, which reduces the benefits of concurrency.

There are much more convenience APIs in the “dispatch” library, such as the Proxy class or concurrent extensions to the builtin Enumerable module. Check out the tutorial for more information.

Solid Foundations

We have rewritten much of the foundation layer of MacRuby in this release, with the goal of increasing the overall robustness of the system and providing a better platform for future enhancements.

The Hash class, which used to be an alias to NSMutableDictionary, is now a new class that inherits from the latter. It can more efficiently handle immediate types (such as fixnums and floats) and honors insertion ordering.

The String class has also been changed. It is now a fresh new implementation that can handle both character and byte strings. It also uses the ICU framework to perform encoding conversions on the fly. This new class inherits from NSMutableString. Symbol was also rewritten to handle multibyte (Unicode) characters.

Finally, the Regexp class has been totally rewritten in this release. It is now using the ICU framework instead of Oniguruma for regular expression compilation and pattern matching. Since ICU is thread-safe, MacRuby 0.6 allows multiple threads to utilize regular expressions in a very efficient way, which was not possible previously.

All these changes were designed and implemented to honor compatibility with previous releases of MacRuby. They should not be directly visible.

Better Ruby Compatibility

Ruby compatibility is still progressing but is now much better than in 0.5.

MacRuby 0.6 provides support for C extensions written for the original implementation of ruby. We were able to successfully use the Nokogiri, SQLite3 and PostgreSQL extensions from MacRuby.

This release also passes about 85% of RubySpecs, is able to run a modified version of Rails 3, and implements better support for Ruby 1.9 encodings.

There are still several problems to address in order to provide a full-fidelity replacement for all Ruby features. We intend to continue working on this by focusing on RubySpecs and Rails.

We hope you enjoy the many improvements in this release!

Development on the next release, 0.7 just started. In that release, we intend to deliver a next generation compiler and virtual machine that provides very good runtime performance for multicore environments. Stay tuned for more updates!

2010-01-31
By Laurent Sansonetti

We are pleased to announce the final release of MacRuby 0.5. After months of hard work and two successful beta releases, we believe 0.5 is good enough to replace the previous stable release, 0.4.

You can download it from here. Please note that this package only runs on Snow Leopard and above. Users on Leopard can also use MacRuby by building the sources from our repository.

Remember that while MacRuby is progressing quickly, it is still not recommended for mainstream development yet. We believe that MacRuby is stable in a lot of areas but others are still a work in progress.

As usual, please give it a try and be sure to report any problems you encounter to us.

If you’re just getting started with MacRuby 0.5, make sure to check out our articles on the previous beta releases: 0.5 beta 1 and 0.5 beta 2.

You can read about all the changes since the last beta in this status report e-mail on the mailing-list, but here are the most visible changes:

HotCocoa Support

HotCocoa is a thin & idiomatic Ruby layer that sits above Cocoa and other frameworks, developed by Rich Kilmer. MacRuby 0.5 now supports HotCocoa.

HotCocoa used to be developed inside the MacRuby project, but we decided that it would have a better life on GitHub, where it is far easier for developers to submit contributions. HotCocoa also has been transformed as a gem and is included in the 0.5 package installer. Be sure to require rubygems before using it.

require 'rubygems'
require 'hotcocoa'
include HotCocoa
application do |app|
  win = window :size => [100,50]
  b = button :title => 'Hello'
  b.on_action { puts 'World!' }
  win << b
end

If you’re interested in HotCocoa, make sure to clone the project and start hacking!

More Elegant Ahead-of-Time Compilation

The macrubyc command-line tool has been improved to support the compilation of multiple Ruby source file into dynamic libraries. This is useful when you have several executables sharing the same Ruby code.

$ cd /tmp
$ echo "def hello(n); puts 'hello ' + n; end" > t1.rb
$ echo "def hello_world; hello 'world'; end" > t2.rb
$ echo "require 't1'; require 't2'; hello_world" > test.rb
$ macrubyc t1.rb t2.rb -o code.dylib --dylib
$ file code.dylib 
code.dylib: Mach-O 64-bit dynamically linked shared library x86_64
$ macrubyc test.rb code.dylib -o test
$ rm t1.rb t2.rb test.rb 
$ ./test
hello world

Also, macrubyc now comes with a man-page which provides more information on how to use it. Check it out!

$ man macrubyc

Grand Central Dispatch Support

In this release, we completed our GCD support. Every C API of Grand Central Dispatch is now available from MacRuby. We also completed documentation (as rdoc comments), covered everything with specs and we now intend to support this API in further releases.

To get you started with GCD, we wrote a separate tutorial. Check it out!

We plan to provide higher-level, Ruby-centric API’s for GCD in future releases.

2009-11-17
By Laurent Sansonetti

After a month of hard work we are pleased to offer the second beta of MacRuby 0.5. We are expecting one more beta before shipping the final 0.5.

You can download it from here. Please note that this package only runs on Snow Leopard and above. Users on Leopard can also use MacRuby by building the sources from our repository.

Remember that this is a development version of MacRuby provided for testing and experimentation purposes only. Even though many features are already quite stable at the time of this writing, some of them are still a work in progress.

Please feel encouraged to give it a try and be sure to report any problems you encounter to us. This will help us to ensure that the final release is of the highest possible quality.

You can read about all the changes since the first beta in this status report e-mail on the mailing-list, but here are the most visible changes:

Better Compatibility

We fixed many compatibility bugs, allowing MacRuby to run rdoc, ri, Rack and Sinatra.

RI files are now generated as part of the project build and readable from the macri command-line tool.

We are also able to run simple Rack and Sinatra web applications on MacRuby, using a simple GCD-based web-server that will be covered in an upcoming blog article.

Additionally, MacRuby 0.5 beta 2 ships with experimental support for the BigDecimal, OpenSSL and JSON extensions.

Better Ahead-of-Time Compiler

Many compiler bugs have been fixed and the macrubyc utility is now able to generate fat binaries, via the —arch argument.

$ macrubyc hello.rb -o hello --arch i386 --arch x86_64

Also, macrubyc will generate by default executables linking against MacRuby.framework dynamically, which greatly reduces the executable size. In order to build a full standalone executable, the —static argument must be passed.

A new utility, called macruby_deploy, is now available to help you deploy your MacRuby applications. It provides options to compile ahead-of-time your application’s Ruby source code as well as relocating the MacRuby framework inside the application bundle. This way your application is ready for deployment, with its source code hidden because it is pre-compiled.

$ macruby_deploy 
Usage: macruby_deploy [options] application-bundle
        --compile                    Compile the bundle source code
        --embed                      Embed MacRuby inside the bundle
        --no-stdlib                  Do not embed the standard library
    -v, --version                    Display the version

These functionalities are also available as Xcode targets, a few mouse clicks away.

DTrace Probes

DTrace static probes have been added to the VM, providing the exact same support as MacRuby 0.4.

DTrace is a powerful tracing facility available since Leopard which allows you to trace the MacRuby runtime of any running application, in development or production.

MacRuby ships with a few DTrace example scripts. Here is one which prints some information regarding objects collected by the GC at a given time.

$ sudo dtrace -qs sample-macruby/DTrace/collected_objects64.d -p 72593
Target pid: 72593

^C

                                             CLASS       COUNT     
--------------------------------------------------------------------------------
                     __NSFastEnumerationEnumerator       100       
                                            Method       101       
                                      CommonLogger       102       
                                        NSCFNumber       200       
                                              Proc       202       
                                        ByteString       203       
                                          CTParser       204       
                                              Time       204       
                                  NSCFCharacterSet       400       
                              NSCheapMutableString       404       
                                      NSPathStore2       606       
                                          NSCFData       612       
                                    NSCFDictionary       1204      
                                         RubyArray       2434      
                                        NSCFString       21240     

« newer | Page 1 of 4 | older »