blackwinter-rake-compiler 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +8 -0
  3. data/History.txt +308 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +415 -0
  6. data/Rakefile +15 -0
  7. data/bin/rake-compiler +24 -0
  8. data/cucumber.yml +4 -0
  9. data/features/compile.feature +79 -0
  10. data/features/cross-compile.feature +23 -0
  11. data/features/cross-package-multi.feature +15 -0
  12. data/features/cross-package.feature +14 -0
  13. data/features/java-compile.feature +22 -0
  14. data/features/java-no-native-compile.feature +33 -0
  15. data/features/java-package.feature +24 -0
  16. data/features/package.feature +40 -0
  17. data/features/step_definitions/compilation.rb +70 -0
  18. data/features/step_definitions/cross_compilation.rb +27 -0
  19. data/features/step_definitions/execution.rb +52 -0
  20. data/features/step_definitions/folders.rb +32 -0
  21. data/features/step_definitions/gem.rb +46 -0
  22. data/features/step_definitions/java_compilation.rb +7 -0
  23. data/features/support/env.rb +10 -0
  24. data/features/support/file_template_helpers.rb +137 -0
  25. data/features/support/generator_helpers.rb +123 -0
  26. data/features/support/platform_extension_helpers.rb +27 -0
  27. data/lib/rake/baseextensiontask.rb +90 -0
  28. data/lib/rake/extensioncompiler.rb +53 -0
  29. data/lib/rake/extensiontask.rb +513 -0
  30. data/lib/rake/javaextensiontask.rb +226 -0
  31. data/spec/lib/rake/extensiontask_spec.rb +501 -0
  32. data/spec/lib/rake/javaextensiontask_spec.rb +182 -0
  33. data/spec/spec.opts +3 -0
  34. data/spec/spec_helper.rb +15 -0
  35. data/spec/support/capture_output_helper.rb +22 -0
  36. data/tasks/bin/cross-ruby.rake +213 -0
  37. data/tasks/bootstrap.rake +11 -0
  38. data/tasks/common.rake +10 -0
  39. data/tasks/cucumber.rake +23 -0
  40. data/tasks/gem.rake +52 -0
  41. data/tasks/news.rake +39 -0
  42. data/tasks/release.rake +26 -0
  43. data/tasks/rspec.rake +9 -0
  44. metadata +138 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38763b3b7fe07b27a0e9e4c9d87ea2056b8278f9
4
+ data.tar.gz: 50ef7e99b03b3bcabb8cc3b47efe7327d162e519
5
+ SHA512:
6
+ metadata.gz: 204d2a3e19651d45d2a5c693444aae12c6b25a40f0241a9ff4617aeac508e60ef64d70022f578bd7048ddea77dc63507f042d655a875a9572fbfef1d8ec55f68
7
+ data.tar.gz: 8f64a3f44ae3b070ad4aeb90983b30d188429d81f4c6277fe54be6823bc8bb8b8d245d50a3dde585192da7b18edbc0064619b321478e523152cd3e5aba761944
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rake"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.8.0"
7
+ gem "cucumber", "~> 1.1.4"
8
+ end
@@ -0,0 +1,308 @@
1
+ === 0.9.2 / 2013-11-14
2
+
3
+ * Bugfixes:
4
+ * Pre-load resolver to avoid Bundler blow up during cross-compilation
5
+ Pull #83 [larskanis]
6
+
7
+ === 0.9.1 / 2013-08-03
8
+
9
+ * Bugfixes:
10
+ * Restore compatibility with RubyGems platforms for cross-compilation
11
+ (i386-mingw32 and x86-mingw32 are the same and supported)
12
+
13
+ === 0.9.0 / 2013-08-03
14
+
15
+ * Enhancements:
16
+ * Add support for cross-builds and multiple platforms (x86/x64).
17
+ Pull #74 [larskanis]
18
+
19
+ $ rake-compiler cross-ruby VERSION=1.8.7-p371
20
+ $ rake-compiler cross-ruby VERSION=1.9.3-p392
21
+ $ rake-compiler cross-ruby VERSION=2.0.0-p0
22
+ $ rake-compiler cross-ruby VERSION=2.0.0-p0 HOST=x86_64-w64-mingw32
23
+ $ rake cross compile RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0
24
+
25
+ # Rakefile
26
+ ext.cross_platform = %w[i386-mingw32 x64-mingw32]
27
+
28
+ * Support for cross-platform specific options. Pull #74 [larskanis]
29
+
30
+ # Rakefile
31
+ ext.cross_config_options << "--with-common-option"
32
+ ext.cross_config_options << {"x64-mingw32" => "--enable-64bits"}
33
+
34
+ * Bugfixes:
35
+ * Correct fat-gems support caused by RubyGems issues. Pull #76 [knu]
36
+
37
+ * Deprecations:
38
+ * Requires minimum Ruby 1.8.7 and RubyGems 1.8.25
39
+ * Usage of 'i386-mswin32' needs to be changed to 'i386-mswin32-60'
40
+
41
+ === 0.9.0.pre.1 / 2013-05-05
42
+
43
+ See 0.9.0 changes.
44
+
45
+ === 0.8.3 / 2013-02-16
46
+
47
+ * Bugfixes:
48
+ * Support FreeBSD 'mingw32-gcc' cross compiler. Closes #72 [knu]
49
+
50
+ === 0.8.2 / 2013-01-11
51
+
52
+ * Bugfixes:
53
+ * Unset CC, LDFLAGS and CPPFLAGS prior cross-compiling. Closes #55
54
+
55
+ === 0.8.1 / 2012-04-15
56
+
57
+ * Bugfixes:
58
+ * Raise error when either make or gmake could be found. Closes #53, #54
59
+
60
+ === 0.8.0 / 2012-01-08
61
+
62
+ * Enhancements:
63
+ * Invocation from command line now support extra options similar to RubyGems.
64
+ Closes #4 from Pull #47 [jonforums]
65
+
66
+ $ rake compile -- --with-opt-dir=/opt/local
67
+
68
+ * Bugfixes:
69
+ * Only emit cross-compilation warnings for C when `cross` is invoked.
70
+ Closes #16 from Pull #48 [mvz]
71
+ * Only emit warnings when invoking cross-compilation tasks for JRuby.
72
+ Pull #45 [jfirebaugh]
73
+ * Use x86 MinGW cross-compiler. Pull #49 [larskanis]
74
+
75
+ === 0.7.9 / 2011-06-08
76
+
77
+ * Enhancements:
78
+ * Consistently use RubyGems features available since version 1.3.2 and avoid
79
+ deprecation warnings with Rake > 0.8.7.
80
+
81
+ * Bugfixes:
82
+ * Use correct platform in fake.rb. Pull #39 [kou]
83
+ * Workaround Gem::Specification and Gem::PackageTask limitations. Closes #43
84
+
85
+ === 0.7.8 / 2011-04-26
86
+
87
+ * Enhancements:
88
+ * Bump default cross-ruby version to 1.8.7-p334.
89
+ * ExtensionTask now support config_includes to load additional directories.
90
+ [jfinkhaeuser]
91
+
92
+ Rake::ExtensionTask.new("myext", GEM_SPEC) do |ext|
93
+ ext.config_includes << File.expand_path("my", "custom", "dir")
94
+ end
95
+
96
+ * Bugfixes:
97
+ * Warn if compiled files exists in extension's source directory. Closes GH-35
98
+ * Workaround issue with WINE using proper build option. Closes GH-37
99
+ * Use FileUtils#install instead of cp. Closes GH-33 [Eric Wong]
100
+ * Update README instructions for OSX. Closes GH-29 [tmm1]
101
+
102
+ === 0.7.7 / 2011-04-04
103
+
104
+ * Bugfixes:
105
+ * Use Winsock2 as default to match Ruby 1.9.2 library linking.
106
+
107
+ === 0.7.6 / 2011-02-04
108
+
109
+ * Bugfixes:
110
+ * Prefer Psych over Syck for YAML parsing on Ruby 1.9.2. [tenderlove]
111
+
112
+ === 0.7.5 / 2010-11-25
113
+
114
+ * Enhancements:
115
+ * Promoted stable version for cross-compilation to 1.8.6-p398. Closes GH-19
116
+
117
+ * Bugfixes:
118
+ * Generate a fake.rb compatible with Ruby 1.9.2. Closes GH-25
119
+ * fake.rb will not try to mimic Ruby's own fake to the letter. Closes GH-28
120
+ * Expand symlinks for tmp_dir. Closes GH-24
121
+ * Silence make output during rake-compiler invocation.
122
+ * Usage of Gem.ruby instead of RbConfig ruby_install_name
123
+ This solve issues with ruby vs. ruby.exe and jruby.exe
124
+
125
+ * Experimental:
126
+ * Allow setting of HOST during cross-compilation. This enable usage
127
+ of mingw-w64 compiler and not the first one found in the PATH.
128
+
129
+ rake-compiler cross-ruby VERSION=1.9.2-p0 HOST=i686-w64-mingw32
130
+ rake-compiler cross-ruby HOST=i386-mingw32 (OSX mingw32 port)
131
+ rake-compiler cross-ruby HOST=i586-pc-mingw32 (Debian/Ubuntu mingw32)
132
+
133
+ === 0.7.1 / 2010-08-07
134
+
135
+ * Bugfixes:
136
+ * Update gem files to make "gem install -t" works. Closes GH-14
137
+ * Update mocks to work under 1.8.7. Closes GH-15 [luisparravicini]
138
+ * Do not allow cross-ruby be executed under Windows. Closes GH-22
139
+
140
+ * Experimental:
141
+ * Allow JRuby to compile C extensions [timfel].
142
+ It is now possible compile C extensions using latest JRuby. Offered
143
+ in experimental mode since JRuby cext hasn't been officially released.
144
+
145
+ === 0.7.0 / 2009-12-08
146
+
147
+ * Enhancements
148
+ * Allow generation of JRuby extensions. Thanks to Alex Coles (myabc) for the
149
+ contribution.
150
+ This will allow, with proper JDK tools, cross compilation of JRuby gems
151
+ from MRI.
152
+
153
+ Rake::JavaExtensionTask.new('my_java_extension', GEM_SPEC) do |ext|
154
+ # most of ExtensionTask options can be used
155
+ # plus, java_compiling:
156
+ ext.java_compiling do |gem_spec|
157
+ gem_spec.post_install_message = "This is a native JRuby gem!"
158
+ end
159
+ end
160
+
161
+ Please note that cross-compiling JRuby gems requires either JRUBY_HOME or
162
+ JRUBY_PARENT_CLASSPATH environment variables being properly set.
163
+
164
+ * Allow alteration of the Gem Specification when cross compiling. Closes GH-3
165
+ This is useful to indicate a custom requirement message, like DLLs
166
+ installation or similar.
167
+
168
+ Rake::ExtensionTask.new('my_extension', GEM_SPEC) do |ext|
169
+ ext.cross_compile = true
170
+ # ...
171
+ ext.cross_compiling do |gem_spec|
172
+ gem_spec.post_install_message = "You've installed a binary version of this gem"
173
+ end
174
+ end
175
+
176
+ * Bugfixes
177
+ * Detect GNU make independently of distribution based naming.
178
+ Thanks to flori for patches.
179
+ * Usage of #dup to duplicate gemspec instead of YAML dumping.
180
+ * No longer support Ruby older than 1.8.6
181
+ * No longer support RubyGems older than 1.3.5
182
+ * Force definition of binary directory and executables. Closes GH-11
183
+ * Workaround path with spaces issues using relative paths. Closes GH-6
184
+ * Removed gemspec, GitHub gems no more
185
+
186
+ * Known issues
187
+ * Usage of rake-compiler under projects with Jeweler requires some tweaks
188
+ Please read issue GH-73 for Jeweler:
189
+ http://github.com/technicalpickles/jeweler/issues#issue/73
190
+
191
+ For a workaround, look here:
192
+ http://gist.github.com/251663
193
+
194
+ === 0.6.0 / 2009-07-25
195
+
196
+ * Enhancements
197
+ * Implemented 'fat-binaries' generation for cross compiling
198
+ (for now). Thanks to Aaron Patterson for the suggestion and
199
+ original idea.
200
+
201
+ rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1
202
+
203
+ Will package extensions for 1.8 and 1.9 versions of Ruby.
204
+ * Can now cross compile extensions for 1.9 using 1.8.x as base.
205
+ Be warned: works from 1.8 to 1.9, but not if your default ruby is 1.9
206
+
207
+ rake cross compile RUBY_CC_VERSION=1.9.1
208
+
209
+ * Allow simultaneous versions of Ruby to compile extensions.
210
+ This change allow 1.8.x compiles co-exist with 1.9.x ones
211
+ and don't override each other.
212
+
213
+ Please perform <tt>rake clobber</tt> prior compiling again.
214
+ * Allow optional source file URL for cross-compile tasks.
215
+ (Thanks to deepj for the patches)
216
+
217
+ rake-compiler cross-ruby VERSION=1.9.1-p0 SOURCE=http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2
218
+
219
+ * Bugfixes
220
+ * Removed strict versioning for gems since it clash with fat binaries.
221
+ From now on, if your gem only targets a specific version of Ruby, please
222
+ indicate it in the Gem::Specification (<tt>required_ruby_version</tt>)
223
+
224
+ === 0.5.0 / 2009-04-25
225
+
226
+ * Enhancements
227
+ * Allow generation of multiple gems for Windows (EXPERIMENTAL)
228
+ This allows build gems for both VC6 and MinGW builts of Ruby
229
+ (Thanks to Jonathan Stott for the suggestion)
230
+
231
+ Rake::ExtensionTask.new('my_extension', GEM_SPEC) do |ext|
232
+ ext.cross_compile = true
233
+ ext.cross_platform = ['i386-mswin32', 'i386-mingw32']
234
+ end
235
+
236
+ === 0.4.1 / 2009-04-09
237
+
238
+ * Enhancements
239
+ * Target specific versions of Ruby when generating binaries.
240
+ This avoids installing a 1.8.x binary gem in 1.9.x and viceversa.
241
+ (Thanks to Aaron Patterson for the patches)
242
+
243
+ * Bugfixes
244
+ * No longer raises error if rake-compiler configuration is missing.
245
+ Not all users of a project would have it installed.
246
+ (Thanks to Aaron Patterson for the patch)
247
+
248
+ === 0.4.0 / 2009-04-03
249
+
250
+ * Enhancements
251
+ * Bended the convention for extension folder.
252
+ Defining <tt>ext_dir</tt> for custom extension location.
253
+
254
+ Rake::ExtensionTask.new('my_extension') do |ext|
255
+ ext.ext_dir = 'custom/location' # look into custom/location
256
+ end # instead of ext/my_extension
257
+
258
+ * Better detection of mingw target across Linux/OSX.
259
+ Exposed it as Rake::ExtensionCompiler
260
+ * Display list of available tasks when calling rake-compiler script
261
+ * Track Ruby full versioning (x.y.z).
262
+ This will help the compilation of extensions targetting 1.8.6/7 and 1.9.1
263
+
264
+ * Bugfixes
265
+ * Better output of Rake development tasks (Thanks to Luis Parravicini).
266
+ * Proper usage of Gem::Platform for native gems (Thanks to Dirkjan Bussink).
267
+ * Don't use autoload for YAML (present problems with Ruby 1.9.1).
268
+
269
+ === 0.3.1 / 2009-01-09
270
+
271
+ * Enhancements
272
+ * Download cross-ruby source code using HTTP instead of FTP.
273
+ * Disabled Tcl/Tk extension building on cross-ruby (helps with 1.9).
274
+
275
+ * Bugfixes
276
+ * Workaround bug introduced by lack of Gem::Specification cloning. Fixes DM LH #757.
277
+ * Use proper binary extension on OSX (reported by Dirkjan Bussink).
278
+ * Ensure lib/binary task is defined prior clear of requisites.
279
+
280
+ === 0.3.0 / 2008-12-07
281
+
282
+ * New features
283
+ * Let you specify the Ruby version used for cross compilation instead
284
+ of default one.
285
+
286
+ rake cross compile RUBY_CC_VERSION=1.8
287
+
288
+ * Enhancements
289
+ * Properly update rake-compiler configuration when new version is installed.
290
+ * Automated release process to RubyForge, yay!
291
+
292
+ * Bugfixes
293
+ * Corrected documentation to reflect the available options
294
+
295
+ === 0.2.1 / 2008-11-30
296
+
297
+ * New features
298
+
299
+ * Allow cross compilation (cross compile) using mingw32 on Linux or OSX.
300
+ * Allow packaging of gems for Windows on Linux or OSX.
301
+
302
+ * Enhancements
303
+
304
+ * Made generation of extensions safe and target folders per-platform
305
+
306
+ * Bugfixes
307
+
308
+ * Ensure binaries for the specific platform are copied before packaging.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Luis Lavena.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,415 @@
1
+ = What is rake-compiler?
2
+
3
+ rake-compiler is first and foremost a productivity tool for Ruby developers.
4
+ It's goal is to make the busy developer's life easier by simplifying the building
5
+ and packaging of Ruby extensions by simplifying code and reducing duplication.
6
+
7
+ It follows *convention over configuration* by advocating a standardized build and
8
+ package structure for both C and Java based RubyGems.
9
+
10
+ rake-compiler is the result of many hard-won experiences dealing with several
11
+ diverse RubyGems that provided native extensions for different platforms and
12
+ different user configurations in different ways. Details such as differences in
13
+ code portability, differences in code clarity, and differences in project directory
14
+ structure often made it very difficult for newcomers to those RubyGems.
15
+
16
+ From these challenges, rake-compiler was born with the single-minded goal of
17
+ making the busy RubyGem developer's life much less difficult.
18
+
19
+ == Feature Overview
20
+
21
+ Some of the benefits rake-compiler provides include:
22
+
23
+ * No custom rake tasks required. Less code duplication and errors.
24
+
25
+ * Painlessly build extensions on different platforms (Linux, OSX and Windows).
26
+
27
+ * Painlessly build extensions for different Ruby implementations (JRuby,
28
+ Rubinius and MRI).
29
+
30
+ * Allow multiple extensions to be compiled inside the same gem.
31
+
32
+ * Painlessly build "fat" native gems for Windows users (from Linux or OSX).
33
+
34
+ * Mimics RubyGems standard installation process, helping as a test environment.
35
+
36
+ * Simplifies cross platform extension compilation (targeting Windows from Linux).
37
+
38
+ == OK, I'm sold! Show me how to install it!
39
+
40
+ Simple:
41
+
42
+ $ gem install rake-compiler
43
+
44
+ == That's easy. How do I use it?
45
+
46
+ Now that you have installed rake-compiler, it's time to give your project a
47
+ standardized structure.
48
+
49
+ === Using a standardized project structure
50
+
51
+ Let's say you want to compile an extension called 'hello_world'. Organizing
52
+ your project's code tree in the following way will help rake-compiler do
53
+ its job:
54
+
55
+ |-- ext
56
+ | `-- hello_world
57
+ | |-- extconf.rb
58
+ | |-- HelloWorldService.java
59
+ | `-- hello_world.c
60
+ |-- lib
61
+ `-- Rakefile
62
+
63
+ TIP: Having a consistent project directory structure will help developers and
64
+ newcomers find and understand your code, making it easier for them to
65
+ contribute back to your project.
66
+
67
+ === Adding the code to enable rake-compiler
68
+
69
+ Now the fun part. It's time to introduce the code to your projects Rakefile
70
+ to tell it to use rake-compiler to build your extension:
71
+
72
+ # File: extconf.rb
73
+
74
+ # these lines must exist already
75
+ require 'mkmf'
76
+ create_makefile('hello_world')
77
+
78
+
79
+ # File: Rakefile
80
+
81
+ require 'rake/extensiontask'
82
+
83
+ Rake::ExtensionTask.new('hello_world')
84
+
85
+ That's it? Yes, that's it! No other lines of code are needed for
86
+ rake-compiler to work its magic.
87
+
88
+ Though, you need to make sure the parameter to <tt>create_makefile</tt>
89
+ and <tt>ExtensionTask.new</tt> are the same or rake-compiler will not mimic
90
+ the RubyGems standard install process. You can override this standard
91
+ behaviour if needed, see the instructions for "non-standard project structure"
92
+ below for details.
93
+
94
+ If you want to do the same for a JRuby extension written in Java, it's just
95
+ as easy:
96
+
97
+ # File: Rakefile
98
+
99
+ require 'rake/javaextensiontask'
100
+
101
+ Rake::JavaExtensionTask.new('hello_world')
102
+
103
+ === The simple process
104
+
105
+ Those *two* simple lines of code automatically added the Rake tasks needed to
106
+ build your 'hello_world' extension. For example, checking the Rake tasks on
107
+ MRI Ruby 1.8.x/1.9 returns something similar to:
108
+
109
+ $ rake -T
110
+ (in /home/user/my_extension)
111
+ rake compile # Compile the extension(s)
112
+ rake compile:hello_world # Compile just the hello_world extension
113
+
114
+ Simply calling <tt>compile</tt> like
115
+
116
+ $ rake compile
117
+
118
+ performs the entire compile and build process for you and places the resulting
119
+ extension inside the <tt>lib</tt> directory of your project.
120
+
121
+ NOTE: Please be aware that building C extensions requires the proper
122
+ development environment for your Platform, including libraries, headers
123
+ and build tools. Check your distro / vendor documentation on how to install
124
+ these development resources.
125
+
126
+ NOTE: Building Java extensions requires the <tt>javac</tt>, part of the Java
127
+ Development Kit (JDK). This should be included by default on Mac OS X, and
128
+ downloadable from http://java.sun.com for other operating systems.
129
+
130
+ === Generating native RubyGems
131
+
132
+ A common usage scenario for rake-compiler is generating native gems that
133
+ bundle your extensions. As mentioned above, if you have your development
134
+ environment configured correctly, the following examples work even when
135
+ building native gems on Windows systems.
136
+
137
+ Creating native gems is really easy with rake-compiler's <tt>Rake::ExtensionTask</tt>:
138
+
139
+ # somewhere in your Rakefile, define your gem spec
140
+ spec = Gem::Specification.new do |s|
141
+ s.name = "my_gem"
142
+ s.platform = Gem::Platform::RUBY
143
+ s.extensions = FileList["ext/**/extconf.rb"]
144
+ end
145
+
146
+ # add your default gem packing task
147
+ Gem::PackageTask.new(spec) do |pkg|
148
+ end
149
+
150
+ # feed the ExtensionTask with your spec
151
+ Rake::ExtensionTask.new('hello_world', spec)
152
+
153
+ As expected, you can still build your pure-ruby gem in the usual way
154
+ (standard output) by running:
155
+
156
+ $ rake gem
157
+ (in /projects/oss/my_gem.git)
158
+ mkdir -p pkg
159
+ Successfully built RubyGem
160
+ Name: my_gem
161
+ Version: 0.1.0
162
+ File: my_gem-0.1.0.gem
163
+ mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
164
+
165
+ Plus, rake-compiler tasks give you the extra functionality needed to build
166
+ native gems by running:
167
+
168
+ # rake native gem
169
+ (... compilation output ...)
170
+ mkdir -p pkg
171
+ Successfully built RubyGem
172
+ Name: my_gem
173
+ Version: 0.1.0
174
+ File: my_gem-0.1.0.gem
175
+ mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
176
+ Successfully built RubyGem
177
+ Name: my_gem
178
+ Version: 0.1.0
179
+ File: my_gem-0.1.0-x86-mingw32.gem
180
+ mv my_gem-0.1.0-x86-mingw32.gem pkg/my_gem-0.1.0-x86-mingw32.gem
181
+
182
+ Did you notice that you get two gems for the price of one? How's that for a
183
+ time saver?
184
+
185
+ Similarly, it's just as easy to do the same thing for JRuby extensions:
186
+
187
+ # rake java gem
188
+ (... compilation output ...)
189
+ mkdir -p pkg
190
+ Successfully built RubyGem
191
+ Name: my_gem
192
+ Version: 0.1.0
193
+ File: my_gem-0.1.0.gem
194
+ mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
195
+ Successfully built RubyGem
196
+ Name: my_gem
197
+ Version: 0.1.0
198
+ File: my_gem-0.1.0-java.gem
199
+ mv my_gem-0.1.0-java.gem pkg/my_gem-0.1.0-java.gem
200
+
201
+
202
+ === Great, but can I use a non-standard project structure?
203
+
204
+ Yes you can! While the conventional project structure is recommended, you may
205
+ want, or need, to tweak those conventions. Rake-compiler allows you to customize
206
+ several settings for <tt>Rake::ExtensionTask</tt>:
207
+
208
+ Rake::ExtensionTask.new do |ext|
209
+ ext.name = 'hello_world' # indicate the name of the extension.
210
+ ext.ext_dir = 'ext/weird_world' # search for 'hello_world' inside it.
211
+ ext.lib_dir = 'lib/my_lib' # put binaries into this folder.
212
+ ext.config_script = 'custom_extconf.rb' # use instead of the default 'extconf.rb'.
213
+ ext.tmp_dir = 'tmp' # temporary folder used during compilation.
214
+ ext.source_pattern = "*.{c,cpp}" # monitor file changes to allow simple rebuild.
215
+ ext.config_options << '--with-foo' # supply additional options to configure script.
216
+ ext.gem_spec = spec # optionally indicate which gem specification
217
+ # will be used.
218
+ end
219
+
220
+ == Cross compilation - the future is now.
221
+
222
+ Rake-compiler also provides a standardized way to generate, from either Linux
223
+ or OSX, extensions and gem binaries for your Windows users!
224
+
225
+ How can this be you say? Simple, rake-compiler's cross compilation features
226
+ take advantage of GCC's host/target capabilities to build 'target' binaries on
227
+ different 'host' OS's.
228
+
229
+ === How do I do this from Linux or OSX?
230
+
231
+ ==== The Easy Way
232
+
233
+ Use rake-compiler-dev-box, a virtual machine provisioned with all the necessary
234
+ build tools. With one command, you can cross-compile and package your gem into
235
+ native, Java, and Windows fat binaries (with 1.8, 1.9, and 2.0 support). See
236
+ https://github.com/tjschuck/rake-compiler-dev-box for more information.
237
+
238
+ ==== The Manual Way
239
+
240
+ In addition to having the development tool chain installed (GCC), you also need to
241
+ install your platform's <tt>mingw32</tt> cross compilation package.
242
+
243
+ Installation depends upon your operating system/distribution. On Ubuntu and Debian
244
+ host machines, a simple <tt>apt-get install mingw32</tt> will be enough.
245
+
246
+ On Arch, <tt>mingw32</tt> is installed by running <tt>pacman -S mingw32-gcc</tt>
247
+
248
+ On OSX, we no longer recommend the usage of MacPorts <tt>mingw32</tt> package because
249
+ it stagnated in GCC version 3.4.5.
250
+
251
+ Instead we recommend you download mingw-w64 automated build packages available at
252
+ SourceForge:
253
+
254
+ http://sourceforge.net/downloads/mingw-w64/
255
+
256
+ Browse into <em>Toolchains targetting Win32</em> and then <em>Automated Builds</em>.
257
+
258
+ Files will be ordered by recency, find the latest one with version 1.0 in it,
259
+ like this one:
260
+
261
+ mingw-w32-1.0-bin_i686-darwin_20110422.tar.bz2
262
+
263
+ Download and extract. After that, make sure the bin directory is added to the PATH, eg:
264
+
265
+ export PATH=~/mingw-w64/w32/bin:$PATH
266
+
267
+ You can add this to your <tt>.profile</tt> to avoid the repitition.
268
+
269
+ ==== I've got my tool-chain installed, now what?
270
+
271
+ First, you need to build Ruby for Windows on your Linux or OSX system.
272
+
273
+ Relax, no need to freak out! Let rake-compiler do all the heavy lifting for you:
274
+
275
+ rake-compiler cross-ruby
276
+
277
+ And you're done. It will automatically download, configure and compile the latest
278
+ stable version of Ruby for Windows, and place it into your <tt>~/.rake-compiler</tt>
279
+ directory.
280
+
281
+ This will create <tt>~/.rake-compiler/config.yml</tt> file so that rake-compiler
282
+ knows where to find the <tt>rbconfig.rb</tt> file that matches the Ruby version
283
+ on the Windows host system you're cross-compiling for. An example:
284
+
285
+ # File: ~/.rake-compiler/config.yml
286
+
287
+ rbconfig-i386-mingw32-1.8.6: /path/to/ruby-1.8.6/rbconfig.rb
288
+ rbconfig-i386-mingw32-1.8.7: /path/to/ruby-1.8.7/rbconfig.rb
289
+ rbconfig-i386-mingw32-1.9.2: /path/to/ruby-1.9.2/rbconfig.rb
290
+
291
+ If, instead, you want to build a different Ruby version than the default one, please
292
+ supply a <tt>VERSION</tt>:
293
+
294
+ rake-compiler cross-ruby VERSION=1.8.6-p114
295
+
296
+ If you, like me, have multiple versions of MinGW packages installed, you can
297
+ specify the HOST that will be used to cross compile Ruby:
298
+
299
+ rake-compiler cross-ruby HOST=i386-mingw32 # (OSX mingw32 port)
300
+
301
+ The host will vary depending on provider (mingw32 versus mingw-w64 projects).
302
+ Please consult the documentation and website of the MinGW package provider before
303
+ reporting any issues.
304
+
305
+ ==== OK, let's cross compile some gems!
306
+
307
+ Now, you only need specify a few additional options in your extension definition:
308
+
309
+ Rake::ExtensionTask.new('my_extension', gem_spec) do |ext|
310
+ ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
311
+ ext.cross_platform = 'i386-mswin32-60' # forces the Windows platform instead of the default one
312
+ # configure options only for cross compile
313
+ ext.cross_config_options << '--with-something'
314
+
315
+ # perform alterations on the gemspec when cross compiling
316
+ ext.cross_compiling do |gem_spec|
317
+ gem_spec.post_install_message = "You installed the binary version of this gem!"
318
+ end
319
+ end
320
+
321
+ By default, cross compilation targets 'i386-mingw32' which is the default GCC
322
+ platform for Ruby.
323
+
324
+ To target gems for MRI Ruby's current official distribution, please force the
325
+ platform to the one (i386-mswin32-60) previously shown.
326
+
327
+ ==== Warning, magician about to do some tricks, don't blink!
328
+
329
+ Cross compiling is still very simple:
330
+
331
+ rake cross compile
332
+
333
+ And now, building gems for your Windows users is just 5 more letters:
334
+
335
+ rake cross native gem
336
+
337
+ And you're done, yeah.
338
+
339
+ ==== But wait, there's more
340
+
341
+ You can specify which version of Ruby to build the extension against:
342
+
343
+ rake cross compile RUBY_CC_VERSION=1.8.6
344
+
345
+ For example, if you installed <tt>1.9.2</tt>, you can do:
346
+
347
+ rake cross compile RUBY_CC_VERSION=1.9.2
348
+
349
+ Even better, you can target multiple versions (ie. 1.8.6 and 1.9.2) in
350
+ the same gem via:
351
+
352
+ rake cross compile RUBY_CC_VERSION=1.8.6:1.9.2
353
+
354
+ And better yet, you can bundle both binary extensions into one so-called "fat"
355
+ gem via:
356
+
357
+ rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.2
358
+
359
+ That will place binaries for both the 1.8 and 1.9 versions of your Ruby
360
+ extensions inside your project's <tt>lib_dir</tt> directory:
361
+
362
+ lib/1.8/my_extension.so
363
+ lib/1.9/my_extension.so
364
+
365
+ NOTE: building "fat" gems is currently only supported by rake-compiler when
366
+ cross compiling from a Linux or OSX host. Patches are welcome if building
367
+ "fat" gems from Windows hosts is desired, or natively for your platform :-)
368
+
369
+ Now is up to you to make your gem load the proper binary at runtime:
370
+
371
+ begin
372
+ RUBY_VERSION =~ /(\d+.\d+)/
373
+ require "#{$1}/my_extension"
374
+ rescue LoadError
375
+ require "my_extension"
376
+ end
377
+
378
+ The above technique will lookup first for 1.8 or 1.9 version of the extension
379
+ and when not found, will look for the plain extension.
380
+
381
+ This approach catch the cases of provided fat binaries or gems compiled by the
382
+ end user installing the gem. It has also been implemented successfully in
383
+ several projects.
384
+
385
+ == What are you talking about? (Give me examples)
386
+
387
+ I know all the above sounds like a complete foreign language (it does even for me!).
388
+ So, what if I show you some examples?
389
+
390
+ Check our wiki with links to the proper rake files used by many developers and
391
+ projects and how they use rake-compiler.
392
+
393
+ http://github.com/luislavena/rake-compiler/wiki/projects-using-rake-compiler
394
+
395
+ == Future
396
+
397
+ rake-compiler is a work in progress and we appreciate any and all feedback
398
+ during the development of it! (and contributions too!)
399
+
400
+ You can find more information about rake-compiler:
401
+
402
+ * GitHub: https://github.com/luislavena/rake-compiler
403
+ * Issues: https://github.com/luislavena/rake-compiler/issues
404
+ * Blog: http://blog.mmediasys.com
405
+ * Docs: http://rubydoc.info/gems/rake-compiler
406
+ * Wiki: https://github.com/luislavena/rake-compiler/wiki
407
+
408
+ == Disclaimer
409
+
410
+ If you have any trouble, don't hesitate to contact the author. As always,
411
+ I'm not going to say "Use at your own risk" because I don't want this library
412
+ to be risky.
413
+
414
+ If you trip on something, I'll share the liability by repairing things
415
+ as quickly as I can. Your responsibility is to report the inadequacies.