Deploying MacRuby
How to do it the Apple Way




                             Thilo Utke - RailsWayCon 2010
HI, I’M THILO!
Outline
 Intro

 MacRuby

 MacRuby 0.5 - 0.6 The last year

 Using MacRuby

 Build

 Embed

 Pack

 Updates

 Bonus
HI, I’M THILO!
UPSTREAM

Our Company: http://upste.am
Twitter: @upstream_agile
Our Coworking Space: http://co-up.de or http://coup.cobot.me
Twitter: @co_up
I Love
I like the Software
Don’t Like Obj-C
First Objective-C App
   @interface Foo : NSObject
   {
     IBOutlet NSTextField *textField;
   }

   - (IBAction)gerneate:(id)sender;
   - (IBAction)seed:(id)sender;
   @end

   @impelemtation Foo

   - (IBAction)generate:(id)sender
   {
     int generated = (random() % 100) +1;
     [textField setIntValue:generated];
   }

   - (IBAction)seed:(id)sender
   {
     srandom(time(NULL));
     [textField setStringValue:@"Generator seeded"];
   }




Headerfiles
Types
Many Bracets
Semicolon
Thats why I love: MacRuby
First Objective-C App
   class Foo
   ! attr_writer :text_field
   !
   ! def seed(sender)
   ! ! @text_field.StringValue = "Generator doesn't need to be seeded ;)"
   ! end
   !
   ! def generate(sender)
   ! ! @text_field.StringValue = (rand(100) + 1)
   ! end
   end




Ruby => Less Noise
MacRuby?




 Ruby’s first class
citizenship on OSX
MacRuby give access to most frameworks on OSX Plattform
MacRuby?




          Replaces RubyCocoa which is
            already gone from XCode



RubyCocoa was included before
MacRuby 0.5

  App       Std Lib
                                 Frameworks
     Ruby Code

                                   Obj-C
  LLVM
 JIT/AOT      GC            IO     GCC
                 Obj-C Runtime
MacRuby 0.5
         Object => NSObject
         Ruby specific extensions
  App        Std Lib
                                   Frameworks
     Ruby Code

                                     Obj-C
  LLVM   Primitives On Obj-C
 JIT/AOT       GC           IO       GCC
                 Obj-C Runtime
MacRuby 0.5
           Generate Obj-C calls for Ruby code
           Intermediate Representation (IR)
  App       Std Lib
           Optimization             Frameworks
     Ruby Code
           JIT compiler to execute code
                                      GCC
  LLVM     faster than 1.9
 JIT/AOT      GC             IO       LLVM
           Ahead of Time Compiler
                 Obj-C Runtime
MacRuby 0.5
                       One runtime
           App         One Lib
                       Std object space
                                               Frameworks
                       Shared infrastructure
                Ruby Code
                       Multithreaded             Obj-C
          LLVM
         JIT/AOT          GC           IO        GCC
                           Obj-C Runtime


NO GIL!
Access to GCD
MacRuby 0.5




This Was basically MacRuby 0.5
MacRuby 0.6




Current 0.6 is considered stable for Cocoa development
MacRuby 0.5 -> 0.6



       DEBUGGER:
       macrubyd




Usable like gnu debugger.
MacRuby 0.5 -> 0.6



       XCODE:
       Integration Improved




New Templates
Target to RunTests/Compile/Embed
MacRuby 0.5 -> 0.6



        Primitives:
        Refactoring
                             Hash.ancestors
                             => [Hash, NSMutableDictionary, NSDictionary,
                             Enumerable, NSObject, Kernel]

                             String.ancestors
                             => [String, NSMutableString, NSString,
                             Comparable, NSObject, Kernel]



New Ruby primitives are sub classes instead of aliases plus extensions.
MacRuby 0.5 -> 0.6



        Improved API for
        Grand Central Dispatch




Job queue
Proxies
Parallelisation extensions on Enumerable
MacRuby 0.5 -> 0.6


       Better support for
       MRI C-Extensions

                              <nokogiri/>



eg. NokoGiri and Postgresql
MacRuby 0.5 -> 0.6


       ICU for Strings
       and RegEx
                                           !"! #$% &'()**+,+ +(-.&'(/
                                           0 (.,)$%(*1. 21(/3.*0%




Threadsafe and Multibyte Char handling for your encoding pleasure.
MacRuby 0.5 -> 0.6



        Got slower:




Performance will be a focus for the 0.7 release with a new VM and compiler
That was what changed from 0.5 to 0.6
Using MacRuby




short overview over functional and language extensions
Using Frameworks
    #import <Cocoa/Cocoa.h>

framework 'Cocoa'
 
 
Calling Obj-C Methods
       [dog makeNoise:@”wuff” level:6];

   dog.makeNoise “wuff”, level:6

   dog.makeNoise “wuff”, :level => 6
    
    




No Colon -> No parameter
Defining Methods for Obj-C
   - (id) makeNoise:(NSString)noise
   level:(NSInteger)level;

   def makeNoise(noise, level:level)
    




Obj-C style methods mostly need for Delegates
Using Structs
       NSPoint(0,1)

   NSpoint.new(0,1)
    




Like they are Objects
Pointer
       NSError* error;

   //MacRuby 0.5
   error = Pointer.new(:object)
    




As a means of an output parameter, mostly for error handling
alloc & init

[[NSMutableArray alloc] init]

Array.alloc.init

Array.new

Array.arrayWithArray [1]
Build
       Embed MacRuby
       Packing
       Deliver Updates




Tasks ahead
Build




Click in XCode
Build
   your_project$ xcodebuild -configuration Release
   -target IntegrityX




Command line is better.
Build   ^o^/


EASY
Embed




- Meaning copying MacRubyFramework inside the application Bundle
- Updating file references to point inside the app. Bundle
Embed
   your_project$ macruby_deploy --embed build/
   release/IntegrityX.app




Helpfull script.
This is basicly the same what the embed target in XCode does
MacRubyFramework ~ 60MB




                                 By Sergei Golyshev http://www.flickr.com/photos/29225114@N08/3112939993/ CC


Only Framework, no Gems, they will be excluded
Embed without Ruby StdLib
   your_project$ macruby_deploy --embed --no-stdlib
   build/release/IntegrityX.app
   your_project$ macruby_deploy --embed --stdlib yml
   build/release/IntegrityX.app




--no-stdlib will remove the entire std lib from the framework, eg. FileUtils, Net, openssl, zlib,
yml.
-> Not a big problem we have the Cocoa libs but they aren’t as nice to use as the stdlib ones.
--stlib can embed single stdlibs only
MacRubyFramework
                   without StdLib
                      ~36 MB




Only Framework
Embed without Ruby StdLib




can easily add this options to your embed target in XCode
Embed                                0_0



       Customers don’t require MacRuby
       Big Bundle even without StdLib
       No Gems yet


Lets Move on to Packing
Pack




No support from XCode
Pack
   your_project$ hdiutil create -srcfolder release/
   IntegrityX.app IntegrityX.dmg




This skript is a very basic version to create a dmg.
Pack: DMG

Is a:
RAW Disk Image
Offers:
Compression, Encryption, Meta Data
Used for:
Apple Software Distribution
FileVault
Pack: DMG Shell Script
   set -ex

   dir="$TEMP_FILES_DIR/disk"
   dmg="$BUILT_PRODUCTS_DIR/$PROJECT_NAME.dmg"

   rm -rf "$dir"
   rm -f "$dmg"
   mkdir "$dir"
   cp -R "$BUILT_PRODUCTS_DIR/$PROJECT_NAME.app" "$dir"
   chmod -Rf go-w "$dir"
   ln -s "/Applications" "$dir/Applications"
   sync
   hdiutil create -srcfolder "$dir" -volname "$PROJECT_NAME"
   -imagekey zlib-level=9 -format UDZO "$dmg"
   hdiutil internet-enable -yes "$dmg"
   rm -rf "$dir"


A more throughout script for XCode
Packing in Xcode
Pack                            (@_@)



DMG
Creation easy scriptable
No initial support from XCode
Ready for distribution   ($_$)




and earn you money ;)
Updates
Updates: Sparkle




OpenSource Update Framework
Updates: AppCast
 Podcasting Feed for your App
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="..." xmlns:sparkle="..." version="2.0">
  <channel>
    <title>IntegrityX</title>
    <description>IntegrityX updates</description>
    <link>http://freaklikeme.de/pub/res</link>
    <language>en</language>
    <pubDate>Sun, 02 May 2010 16:18:44 +0200</pubDate>
    <atom:link type="application/rss+xml" href="..." rel="self"/>
    <item>
       <title>IntegrityX 0.1</title>
       <sparkle:releaseNotesLink>...</sparkle:releaseNotesLink>
       <pubDate>Sun, 02 May 2010 16:18:44 +0200</pubDate>
       <guid isPermaLink="false">IntegrityX-0.1</guid>
       <enclosure type="application/dmg" url="http://...IntegrityX-0.1.dmg"
        length="10784979" sparkle:version="0.1" sparkle:dsaSignature="MC0CFQCvYKP
        +elGXrPUEV2Yoxj6OTLKioA="/>
    </item>
  </channel>
</rss>
Adding Sparkle
     1.Add Sparkle Framework to App Bundle
     2.Add Check for Update Option
     3.Generate Key Pair for Signing
     4.Add Info where to find Updates and PubKey




A Video to show it.
In the original presentation was a video here to show
how to setup Sparkle but you can follow the
instructions in this article:
http://foolsworkshop.com/rubycocoa/2008/06/adding-
a-check-updates-feature-for-rubycocoa-and-macruby/
Release with Sparkle
1.Create Signature for your App Bundle
2.Create AppCastFeed with current Signature
3.Add Release Note




Yes there is a script for that:
http://github.com/CraigWilliams/appcastautomation
Updates                0_0/


Add SparkleFramework
Sign App Bundle
Publish with AppCast
Grand Finale


  ChocTop
ChocTop
 All you need at your command line


rake   build                #   Build Xcode Release
rake   dmg                  #   Create the dmg file for appcasting
rake   feed                 #   Create/update the appcast file
rake   upload               #   Upload the appcast and dmg to host
rake   version:bump:major   #   Bump the major version.
rake   version:bump:minor   #   Bump the minor version.
rake   version:bump:patch   #   Bump the patch version.
rake   version:current      #   Display the current version
ChocTop
           Offers Custom DMG with Positioning




Doing this with Apple Script (requiers original apple ruby as it uses ruby cocoa)
ChocTop
Thanks


Start: macruby.org


Help: MacRuby-devel on MacOSForge
Twitter: @MacRuby
Resources
ChocTop and Logo Dr. Nic William http://drnic.github.com/choctop/

Macruby and Logo http://macruby.org

Framework Foto: http://www.flickr.com/photos/29225114@N08/3112939993/

Sparke Instructions: http://foolsworkshop.com/rubycocoa/2008/06/adding-a-check-
updates-feature-for-rubycocoa-and-macruby/

Sparkle Video, Tweetscreen DMG Design, web site screen shoot from Patrick Hüsler:
http://huesler-informatik.ch/

Sparkle Framework: http://github.com/andymatuschak/Sparkle