Blog Overview
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 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!
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
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.
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:
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.
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 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
After several months of development we are very glad to announce the first beta release of MacRuby 0.5. As this release has very ambitious goals we will go through a few intermediate releases before shipping the final 0.5.
You can download it from here. Please note that this package is for Intel machines running Mac OS X v10.6 or higher.
Remember that this is a development version of MacRuby provided for testing and experimentation purposes only. Even if a few things are quite stable, others are still under development. Please give it a try and report us any problem you find, to make sure the final release will be great.
A lot of progress has been made in this version. Here is a summary of what’s new.
MacRuby was based on YARV, the original Ruby 1.9 virtual machine. Two things worried us about YARV: the lack of machine code compilation and the global interpreter lock (GIL) preventing true concurrency. Since concurrency and machine code compilation are so critical to performance, we decided to write a replacement, a very ambitious target.
The new MacRuby 0.5 runtime is built upon LLVM, a compiler infrastructure also sponsored by Apple. Thanks to LLVM, MacRuby is able to transform the Ruby abstract syntax tree (AST) from the parser directly into highly optimized machine code. MacRuby supports both Just in Time (JIT) and Ahead of Time (AOT) compilation. The JIT mode will compile down the code at runtime, and the AOT mode will allow you to save on disk the compilation result. AOT compilation makes MacRuby a true Ruby compiler.
MacRuby ships with the macrubyc command line utility, which is an interface to the AOT compiler. It can produce a Mach-O compatible object file (.o) out of a given Ruby source file. You can also assemble multiple files to get a standalone executable binary ready for deployment. This can be used to compile a MacRuby Cocoa application, dramatically improving its startup time while making sure the original Ruby source code is not readable.
$ echo "p ARGV.map { |x| x.to_i }.inject(0) { |x, y| x + y }" > t.rb
$ macrubyc t.rb -o t
$ file t
t: Mach-O 64-bit executable x86_64
$ ./t 1 2 3 4 5
15
We also introduced a mode that generates a dynamic shared library out of a Ruby source file, using the new .rbo extension. MacRuby at runtime will #require these .rbo files in priority. We pre-compiled parts of the standard library using this technique.
The new MacRuby 0.5 runtime is designed to support concurrent execution, allowing a MacRuby program to use more than one CPU core at a time and multiple threads to call into MacRuby at the same time. This new design is critical as we enter the multicore age.
MacRuby uses native POSIX threads to represent the Thread class. Every native thread has its own VM instance, which allows multiple threads to dispatch code without interrupting others. The MacRuby garbage collector is now able to finalize objects on separate threads, preventing pauses in execution during GC.
MacRuby ships with an API for Grand Central Dispatch (GCD), a multicore computing functionality present in Mac OS 10.6, Snow Leopard. The significant advantage of GCD is not having to deal with threading directly. With our new GCD API you set up queues and dispatch Ruby blocks to them. GCD will handle executing those blocks on system threads, ensuring all your CPU cores are used.
waiting_chairs = Dispatch::Queue.new('com.apple.waiting_chairs')
semaphore = Dispatch::Semaphore.new(3)
index = -1
while true
index += 1
if semaphore.wait(Dispatch::TIME_NOW) != 0
puts "Customer turned away #{index}"
next
end
waiting_chairs.dispatch do
semaphore.signal
puts "Shave and a haircut #{index}"
end
end
MacRuby 0.5 includes significant runtime-level optimizations, such as a much faster method dispatcher, cheap local variables, fast instance variable access, zero-cost DWARF exceptions, immediate floating point types, and many more.
At the core classes level, we introduced a ByteString class to properly handle raw data, rewrote the IO layer for better stability and performance, and introduced a new implementation of Array, optimized for handling Ruby immediate types.
Most of these optimizations were implemented after profiling a large MacRuby application.
We re-implemented the C and Objective-C support of 0.4 in this new release. An application written for 0.4 should continue to work on 0.5, but you should see it execute faster.
In 0.4 we used to use the libffi library to call C and Objective-C functions and to create closures. RubyCocoa is also based on libffi. While libffi is a great library to use for external dispatch, it has definite performance limitations. In 0.5 MacRuby generates stubs using LLVM at runtime, enabling much better performance (from 3 to 4 times faster).
We want MacRuby to be as compatible as possible with existing Ruby programs. We have been working hard on MacRuby to make sure it behaves like MRI 1.9.×.
Like most other Ruby implementations, we are now using the RubySpec project to check our compatibility. RubySpec is a set of executable specifications about the Ruby language and is maintained by the community.
At the time of this writing, MacRuby passes about 91% of the language specs, 80% of the core specs and 72% of the library specs. Our objective is to pass as many RubySpecs as possible.
Thanks to a better compatibility, MacRuby is able to run complex Ruby programs like irb, rake, rubygems, and more. Full compatibility is still a work in progress, but we expect MacRuby to run many more Ruby programs in the near future as we fix bugs and implement missing features.
« newer | Page 1 of 4 | older »