mac ruby deployment

70
Deploying MacRuby How to do it the Apple Way Thilo Utke - RailsWayCon 2010

Upload: thilo-utke

Post on 15-May-2015

2.803 views

Category:

Technology


0 download

DESCRIPTION

The talk focuses on the processes and requirements to ship a software, which was written with MacRuby, to the end user. I present libraries and tools, that are helpful for this purpose and show how to use them.

TRANSCRIPT

Page 1: Mac ruby deployment

Deploying MacRubyHow to do it the Apple Way

Thilo Utke - RailsWayCon 2010

Page 2: Mac ruby deployment

HI, I’M THILO!

Page 3: Mac ruby deployment

Outline

Intro

MacRuby

MacRuby 0.5 - 0.6 The last year

Using MacRuby

Build

Embed

Pack

Updates

Bonus

Page 4: Mac ruby deployment

HI, I’M THILO!

Page 5: Mac ruby deployment

UPSTREAM

Our Company: http://upste.amTwitter: @upstream_agile

Page 6: Mac ruby deployment

Our Coworking Space: http://co-up.de or http://coup.cobot.me Twitter: @co_up

Page 7: Mac ruby deployment

I Love

Page 8: Mac ruby deployment
Page 9: Mac ruby deployment

I like the Software

Page 10: Mac ruby deployment

Don’t Like Obj-C

Page 11: Mac ruby deployment

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"];}

HeaderfilesTypesMany BracetsSemicolon

Page 12: Mac ruby deployment

Thats why I love: MacRuby

Page 13: Mac ruby deployment

First Objective-C Appclass 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)! endend

Ruby => Less Noise

Page 14: Mac ruby deployment

MacRuby?

Ruby’s first class

citizenship on OSX

Page 15: Mac ruby deployment

MacRuby give access to most frameworks on OSX Plattform

Page 16: Mac ruby deployment

MacRuby?

Replaces RubyCocoa which is already gone from XCode

RubyCocoa was included before

Page 17: Mac ruby deployment

MacRuby 0.5

Obj-C Runtime

GCC

LLVMJIT/AOT

Ruby Code

GC

Obj-C

Std LibApp

IO

Frameworks

Page 18: Mac ruby deployment

MacRuby 0.5

Obj-C Runtime

GCC

LLVMJIT/AOT

Ruby Code

GC

Obj-C

Std LibApp

IO

Frameworks

Object => NSObject

Ruby specific extensions

Primitives On Obj-C

Page 19: Mac ruby deployment

MacRuby 0.5

Obj-C Runtime

LLVM

LLVMJIT/AOT

Ruby Code

GC

GCC

Std LibApp

IO

Frameworks

Generate Obj-C calls for Ruby code

Intermediate Representation (IR)

Optimization

JIT compiler to execute code

faster than 1.9

Ahead of Time Compiler

Page 20: Mac ruby deployment

MacRuby 0.5

Obj-C Runtime

GCC

LLVMJIT/AOT

Ruby Code

GC

Obj-C

Std LibApp

IO

Frameworks

One runtime

One object space

Shared infrastructure

Multithreaded

NO GIL!Access to GCD

Page 21: Mac ruby deployment

MacRuby 0.5

This Was basically MacRuby 0.5

Page 22: Mac ruby deployment

MacRuby 0.6

Current 0.6 is considered stable for Cocoa development

Page 23: Mac ruby deployment

MacRuby 0.5 -> 0.6

DEBUGGER:macrubyd

Usable like gnu debugger.

Page 24: Mac ruby deployment

MacRuby 0.5 -> 0.6

XCODE:Integration Improved

New TemplatesTarget to RunTests/Compile/Embed

Page 25: Mac ruby deployment

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.

Page 26: Mac ruby deployment

MacRuby 0.5 -> 0.6

Improved API forGrand Central Dispatch

Job queueProxiesParallelisation extensions on Enumerable

Page 27: Mac ruby deployment

MacRuby 0.5 -> 0.6

Better support for

MRI C-Extensions

<nokogiri/>

eg. NokoGiri and Postgresql

Page 28: Mac ruby deployment

MacRuby 0.5 -> 0.6

ICU for Strings

and RegEx

弦樂加護病房和正則表達式

!"! #$% &'()**+,+ +(-.&'(/0 (.,)$%(*1. 21(/3.*0%

Threadsafe and Multibyte Char handling for your encoding pleasure.

Page 29: Mac ruby deployment

MacRuby 0.5 -> 0.6

Got slower:

Performance will be a focus for the 0.7 release with a new VM and compiler

Page 30: Mac ruby deployment

That was what changed from 0.5 to 0.6

Page 31: Mac ruby deployment

Using MacRuby

short overview over functional and language extensions

Page 32: Mac ruby deployment

Using Frameworks#import <Cocoa/Cocoa.h>

framework 'Cocoa'  

Page 33: Mac ruby deployment

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

dog.makeNoise “wuff”, level:6

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

No Colon -> No parameter

Page 34: Mac ruby deployment

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

Page 35: Mac ruby deployment

Using StructsNSPoint(0,1)

NSpoint.new(0,1) 

Like they are Objects

Page 36: Mac ruby deployment

PointerNSError* error;

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

 

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

Page 37: Mac ruby deployment

alloc & init

[[NSMutableArray alloc] init]

Array.alloc.init

Array.new

Array.arrayWithArray [1]

Page 38: Mac ruby deployment
Page 39: Mac ruby deployment
Page 40: Mac ruby deployment

Build

Embed MacRuby

Packing

Deliver Updates

Tasks ahead

Page 41: Mac ruby deployment

Build

Click in XCode

Page 42: Mac ruby deployment

Build

your_project$ xcodebuild -configuration Release -target IntegrityX

Command line is better.

Page 43: Mac ruby deployment

EASY

Build \^o^/

Page 44: Mac ruby deployment

Embed

- Meaning copying MacRubyFramework inside the application Bundle- Updating file references to point inside the app. Bundle

Page 45: Mac ruby deployment

Embed

your_project$ macruby_deploy --embed build/release/IntegrityX.app

Helpfull script.This is basicly the same what the embed target in XCode does

Page 46: Mac ruby deployment

MacRubyFramework ~ 60MB

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

Only Framework, no Gems, they will be excluded

Page 47: Mac ruby deployment

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

Page 48: Mac ruby deployment

MacRubyFramework without StdLib

~36 MB

Only Framework

Page 49: Mac ruby deployment

Embed without Ruby StdLib

can easily add this options to your embed target in XCode

Page 50: Mac ruby deployment

Embed

Customers don’t require MacRuby

Big Bundle even without StdLib

No Gems yet

0_0

Lets Move on to Packing

Page 51: Mac ruby deployment

Pack

No support from XCode

Page 52: Mac ruby deployment

Pack

your_project$ hdiutil create -srcfolder release/IntegrityX.app IntegrityX.dmg

This skript is a very basic version to create a dmg.

Page 53: Mac ruby deployment

Pack: DMG

Is a:RAW Disk Image

Offers:Compression, Encryption, Meta Data

Used for:Apple Software DistributionFileVault

Page 54: Mac ruby deployment

Pack: DMG Shell Scriptset -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"synchdiutil 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

Page 55: Mac ruby deployment

Packing in Xcode

Page 56: Mac ruby deployment

Pack

DMG

Creation easy scriptable

No initial support from XCode

(@_@)

Page 57: Mac ruby deployment

Ready for distribution ($_$)

and earn you money ;)

Page 58: Mac ruby deployment

Updates

Page 59: Mac ruby deployment

Updates: Sparkle

OpenSource Update Framework

Page 60: Mac ruby deployment

Updates: AppCastPodcasting 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>

Page 61: Mac ruby deployment

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.

Page 63: Mac ruby deployment

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

Page 64: Mac ruby deployment

Updates \0_0/

Add SparkleFramework

Sign App Bundle

Publish with AppCast

Page 65: Mac ruby deployment

Grand Finale

ChocTop

Page 66: Mac ruby deployment

All you need at your command line

ChocTop

rake build # Build Xcode Releaserake dmg # Create the dmg file for appcastingrake feed # Create/update the appcast filerake upload # Upload the appcast and dmg to hostrake 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

Page 67: Mac ruby deployment

ChocTop

Offers Custom DMG with Positioning

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

Page 68: Mac ruby deployment

ChocTop

Page 69: Mac ruby deployment

Thanks

Start: macruby.org

Help: MacRuby-devel on MacOSForge

Twitter: @MacRuby

Page 70: Mac ruby deployment

ResourcesChocTop 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