rake-compiler 1.0.8 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +510 -0
- data/{README.rdoc → README.md} +144 -117
- data/lib/rake/extensioncompiler.rb +1 -1
- data/lib/rake/extensiontask.rb +31 -18
- data/lib/rake/javaextensiontask.rb +51 -21
- data/spec/lib/rake/javaextensiontask_spec.rb +30 -0
- data/tasks/bin/cross-ruby.rake +79 -103
- metadata +8 -9
- data/History.txt +0 -443
data/{README.rdoc → README.md}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
# What is rake-compiler?
|
2
2
|
|
3
3
|
rake-compiler is first and foremost a productivity tool for Ruby developers.
|
4
4
|
Its goal is to make the busy developer's life easier by simplifying the building
|
5
5
|
and packaging of Ruby extensions by simplifying code and reducing duplication.
|
6
6
|
|
7
|
-
It follows
|
7
|
+
It follows **convention over configuration** by advocating a standardized build and
|
8
8
|
package structure for both C and Java based RubyGems.
|
9
9
|
|
10
10
|
rake-compiler is the result of many hard-won experiences dealing with several
|
@@ -16,7 +16,7 @@ structure often made it very difficult for newcomers to those RubyGems.
|
|
16
16
|
From these challenges, rake-compiler was born with the single-minded goal of
|
17
17
|
making the busy RubyGem developer's life much less difficult.
|
18
18
|
|
19
|
-
|
19
|
+
## Feature Overview
|
20
20
|
|
21
21
|
Some of the benefits rake-compiler provides include:
|
22
22
|
|
@@ -35,18 +35,18 @@ Some of the benefits rake-compiler provides include:
|
|
35
35
|
|
36
36
|
* Simplifies cross platform extension compilation (targeting Windows from Linux).
|
37
37
|
|
38
|
-
|
38
|
+
## OK, I'm sold! Show me how to install it!
|
39
39
|
|
40
40
|
Simple:
|
41
41
|
|
42
|
-
|
42
|
+
$ gem install rake-compiler
|
43
43
|
|
44
|
-
|
44
|
+
## That's easy. How do I use it?
|
45
45
|
|
46
46
|
Now that you have installed rake-compiler, it's time to give your project a
|
47
47
|
standardized structure.
|
48
48
|
|
49
|
-
|
49
|
+
### Using a standardized project structure
|
50
50
|
|
51
51
|
Let's say you want to compile an extension called 'hello_world'. Organizing
|
52
52
|
your project's code tree in the following way will help rake-compiler do
|
@@ -64,7 +64,7 @@ TIP: Having a consistent project directory structure will help developers and
|
|
64
64
|
newcomers find and understand your code, making it easier for them to
|
65
65
|
contribute back to your project.
|
66
66
|
|
67
|
-
|
67
|
+
### Adding the code to enable rake-compiler
|
68
68
|
|
69
69
|
Now the fun part. It's time to introduce the code to your projects Rakefile
|
70
70
|
to tell it to use rake-compiler to build your extension:
|
@@ -75,7 +75,6 @@ to tell it to use rake-compiler to build your extension:
|
|
75
75
|
require 'mkmf'
|
76
76
|
create_makefile('hello_world')
|
77
77
|
|
78
|
-
|
79
78
|
# File: Rakefile
|
80
79
|
|
81
80
|
require 'rake/extensiontask'
|
@@ -85,8 +84,8 @@ to tell it to use rake-compiler to build your extension:
|
|
85
84
|
That's it? Yes, that's it! No other lines of code are needed for
|
86
85
|
rake-compiler to work its magic.
|
87
86
|
|
88
|
-
Though, you need to make sure the parameter to
|
89
|
-
and
|
87
|
+
Though, you need to make sure the parameter to `create_makefile`
|
88
|
+
and `ExtensionTask.new` are the same or rake-compiler will not mimic
|
90
89
|
the RubyGems standard install process. You can override this standard
|
91
90
|
behaviour if needed, see the instructions for "non-standard project structure"
|
92
91
|
below for details.
|
@@ -100,45 +99,46 @@ as easy:
|
|
100
99
|
|
101
100
|
Rake::JavaExtensionTask.new('hello_world')
|
102
101
|
|
103
|
-
|
102
|
+
### The simple process
|
104
103
|
|
105
|
-
Those
|
104
|
+
Those **two** simple lines of code automatically added the Rake tasks needed to
|
106
105
|
build your 'hello_world' extension. For example, checking the Rake tasks on
|
107
106
|
MRI Ruby 1.8.x/1.9 returns something similar to:
|
108
107
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
$ rake -T
|
109
|
+
(in /home/user/my_extension)
|
110
|
+
rake compile # Compile the extension(s)
|
111
|
+
rake compile:hello_world # Compile just the hello_world extension
|
113
112
|
|
114
|
-
Simply calling
|
113
|
+
Simply calling `compile` like
|
115
114
|
|
116
|
-
|
115
|
+
$ rake compile
|
117
116
|
|
118
117
|
performs the entire compile and build process for you and places the resulting
|
119
|
-
extension inside the
|
118
|
+
extension inside the `lib` directory of your project.
|
120
119
|
|
121
|
-
To pass
|
120
|
+
To pass `dir_config` options to the compilation, add to the command line:
|
122
121
|
|
123
|
-
|
122
|
+
$ rake compile -- --with-foo-[dir|lib|bin|...]=/path/to/foo
|
124
123
|
|
125
124
|
NOTE: Please be aware that building C extensions requires the proper
|
126
125
|
development environment for your Platform, including libraries, headers
|
127
126
|
and build tools. Check your distro / vendor documentation on how to install
|
128
127
|
these development resources.
|
129
128
|
|
130
|
-
NOTE: Building Java extensions requires the
|
129
|
+
NOTE: Building Java extensions requires the `javac`, part of the Java
|
131
130
|
Development Kit (JDK). This should be included by default on Mac OS X, and
|
132
131
|
downloadable from http://java.sun.com for other operating systems.
|
133
132
|
|
134
|
-
|
133
|
+
### Generating native RubyGems
|
135
134
|
|
136
135
|
A common usage scenario for rake-compiler is generating native gems that
|
137
136
|
bundle your extensions. As mentioned above, if you have your development
|
138
137
|
environment configured correctly, the following examples work even when
|
139
138
|
building native gems on Windows systems.
|
140
139
|
|
141
|
-
Creating native gems is really easy with rake-compiler's
|
140
|
+
Creating native gems is really easy with rake-compiler's
|
141
|
+
`Rake::ExtensionTask`:
|
142
142
|
|
143
143
|
# somewhere in your Rakefile, define your gem spec
|
144
144
|
spec = Gem::Specification.new do |s|
|
@@ -157,57 +157,57 @@ Creating native gems is really easy with rake-compiler's <tt>Rake::ExtensionTask
|
|
157
157
|
As expected, you can still build your pure-ruby gem in the usual way
|
158
158
|
(standard output) by running:
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
160
|
+
$ rake gem
|
161
|
+
(in /projects/oss/my_gem.git)
|
162
|
+
mkdir -p pkg
|
163
|
+
Successfully built RubyGem
|
164
|
+
Name: my_gem
|
165
|
+
Version: 0.1.0
|
166
|
+
File: my_gem-0.1.0.gem
|
167
|
+
mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
|
168
168
|
|
169
169
|
Plus, rake-compiler tasks give you the extra functionality needed to build
|
170
170
|
native gems by running:
|
171
171
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
172
|
+
# rake native gem
|
173
|
+
(... compilation output ...)
|
174
|
+
mkdir -p pkg
|
175
|
+
Successfully built RubyGem
|
176
|
+
Name: my_gem
|
177
|
+
Version: 0.1.0
|
178
|
+
File: my_gem-0.1.0.gem
|
179
|
+
mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
|
180
|
+
Successfully built RubyGem
|
181
|
+
Name: my_gem
|
182
|
+
Version: 0.1.0
|
183
|
+
File: my_gem-0.1.0-x86-mingw32.gem
|
184
|
+
mv my_gem-0.1.0-x86-mingw32.gem pkg/my_gem-0.1.0-x86-mingw32.gem
|
185
185
|
|
186
186
|
Did you notice that you get two gems for the price of one? How's that for a
|
187
187
|
time saver?
|
188
188
|
|
189
189
|
Similarly, it's just as easy to do the same thing for JRuby extensions:
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
191
|
+
# rake java gem
|
192
|
+
(... compilation output ...)
|
193
|
+
mkdir -p pkg
|
194
|
+
Successfully built RubyGem
|
195
|
+
Name: my_gem
|
196
|
+
Version: 0.1.0
|
197
|
+
File: my_gem-0.1.0.gem
|
198
|
+
mv my_gem-0.1.0.gem pkg/my_gem-0.1.0.gem
|
199
|
+
Successfully built RubyGem
|
200
|
+
Name: my_gem
|
201
|
+
Version: 0.1.0
|
202
|
+
File: my_gem-0.1.0-java.gem
|
203
|
+
mv my_gem-0.1.0-java.gem pkg/my_gem-0.1.0-java.gem
|
204
204
|
|
205
205
|
|
206
|
-
|
206
|
+
### Great, but can I use a non-standard project structure?
|
207
207
|
|
208
208
|
Yes you can! While the conventional project structure is recommended, you may
|
209
209
|
want, or need, to tweak those conventions. Rake-compiler allows you to customize
|
210
|
-
several settings for
|
210
|
+
several settings for `Rake::ExtensionTask`:
|
211
211
|
|
212
212
|
Rake::ExtensionTask.new do |ext|
|
213
213
|
ext.name = 'hello_world' # indicate the name of the extension.
|
@@ -221,7 +221,34 @@ several settings for <tt>Rake::ExtensionTask</tt>:
|
|
221
221
|
# will be used.
|
222
222
|
end
|
223
223
|
|
224
|
-
|
224
|
+
|
225
|
+
### Show me all of the supported configuration options
|
226
|
+
|
227
|
+
| Option | Supported By | Description |
|
228
|
+
| -------------------- | --------------------- | ---------------------------------------- |
|
229
|
+
| name | Both | Required. Give the target binary a name. |
|
230
|
+
| gem_spec | Both | [Optional] Indicate which gem specification will be used. |
|
231
|
+
| tmp_dir | Both | [Optional] Temporary folder used during compilation. |
|
232
|
+
| ext_dir | Both | [Optional] Where to search for `name`. Default: `ext/#{@name}`. |
|
233
|
+
| lib_dir | Both | [Optional] Put binaries into this folder. Default: `lib`. |
|
234
|
+
| config_options | Both | [Optional] Supply additional options to configure script. |
|
235
|
+
| source_pattern | Both | [Optional] Monitor file changes to allow simple rebuild. Default for CRuby: `*.{c,cc,cpp}`. Default for Java: `**/*.java`. |
|
236
|
+
| _extra_options_ | ExtensionTask (CRuby) | [Optional] _Any options you add to ARGV on the command line are passed on as complilation flags if they begin with a dash (-)._ |
|
237
|
+
| config_script | ExtensionTask (CRuby) | [Optional] Specify alternate configuration file name when [Adding the code to enable rake-compiler](#adding-the-code-to-enable-rake-compiler). Default: `extconf.rb`. |
|
238
|
+
| cross_compile | ExtensionTask (CRuby) | [Optional] See [Cross compilation - the future is now.](#cross-compilation---the-future-is-now) Default: `false`. |
|
239
|
+
| cross_platform | ExtensionTask (CRuby) | [Optional] See [Cross compilation - the future is now.](#cross-compilation---the-future-is-now) Default: `i386-mingw32`. |
|
240
|
+
| cross_config_options | ExtensionTask (CRuby) | [Optional] See [Cross compilation - the future is now.](#cross-compilation---the-future-is-now) Default: `[]`. |
|
241
|
+
| no_native | ExtensionTask (CRuby) | [Optional] Set to true to prevent non-CRuby platforms from defining native tasks. Default: `false`. |
|
242
|
+
| config_includes | ExtensionTask (CRuby) | [Optional] Specify an Array of paths to include as `-I...:...` includes during compilation. Default: `['.']`. |
|
243
|
+
| classpath | JavaExtensionTask | [Optional] Specify additional classpath paths as an Array. Default: _Uses the current CLASSPATH._ |
|
244
|
+
| debug | JavaExtensionTask | [Optional] Whether to set the debug flag during complication. Default: `false`. |
|
245
|
+
| source_version | JavaExtensionTask | [Optional] The JRE version that your source code requires to compile. Default: `1.6`. |
|
246
|
+
| target_version | JavaExtensionTask | [Optional] The oldest JRE version you want to support. Default: `1.6`. |
|
247
|
+
| encoding | JavaExtensionTask | [Optional] Specify an -encoding option to provide to the compiler. Default: `nil`. |
|
248
|
+
| lint_option | JavaExtensionTask | [Optional] Specify a `-Xlint:___` linting option such as `deprecation`, `all`, `none`, etc. (Run `javac -help -X` to see all available options.) <br> Default: _Simply `-Xlint` is run, which enables recommended warnings._ |
|
249
|
+
|
250
|
+
|
251
|
+
## Cross compilation - the future is now.
|
225
252
|
|
226
253
|
Rake-compiler also provides a standardized way to generate, from either Linux
|
227
254
|
or OSX, extensions and gem binaries for your Windows users!
|
@@ -230,9 +257,9 @@ How can this be you say? Simple, rake-compiler's cross compilation features
|
|
230
257
|
take advantage of GCC's host/target capabilities to build 'target' binaries on
|
231
258
|
different 'host' OS's.
|
232
259
|
|
233
|
-
|
260
|
+
### How do I do this from Linux or OSX?
|
234
261
|
|
235
|
-
|
262
|
+
#### The Easy Way
|
236
263
|
|
237
264
|
Use rake-compiler-dock, a gem that makes use of a virtual machine provisioned with
|
238
265
|
all the necessary build tools. You can add a task to your Rakefile, that
|
@@ -240,17 +267,17 @@ cross-compiles and packages your gem into Windows fat binaries (with 1.8 to 2.2
|
|
240
267
|
and x86/x64 support). See https://github.com/rake-compiler/rake-compiler-dock for more
|
241
268
|
information.
|
242
269
|
|
243
|
-
|
270
|
+
#### The Manual Way
|
244
271
|
|
245
272
|
In addition to having the development tool chain installed (GCC), you also need to
|
246
|
-
install your platform's
|
273
|
+
install your platform's `mingw32` cross compilation package.
|
247
274
|
|
248
275
|
Installation depends upon your operating system/distribution. On Ubuntu and Debian
|
249
|
-
host machines, a simple
|
276
|
+
host machines, a simple `apt-get install mingw32` will be enough.
|
250
277
|
|
251
|
-
On Arch,
|
278
|
+
On Arch, `mingw32` is installed by running `pacman -S mingw32-gcc`
|
252
279
|
|
253
|
-
On OSX, we no longer recommend the usage of MacPorts
|
280
|
+
On OSX, we no longer recommend the usage of MacPorts `mingw32` package because
|
254
281
|
it stagnated in GCC version 3.4.5.
|
255
282
|
|
256
283
|
Instead we recommend you download mingw-w64 automated build packages available at
|
@@ -258,56 +285,56 @@ SourceForge:
|
|
258
285
|
|
259
286
|
http://sourceforge.net/downloads/mingw-w64/
|
260
287
|
|
261
|
-
Browse into
|
288
|
+
Browse into *Toolchains targetting Win32* and then *Automated Builds*.
|
262
289
|
|
263
290
|
Files will be ordered by recency, find the latest one with version 1.0 in it,
|
264
291
|
like this one:
|
265
292
|
|
266
|
-
|
293
|
+
mingw-w32-1.0-bin_i686-darwin_20110422.tar.bz2
|
267
294
|
|
268
295
|
Download and extract. After that, make sure the bin directory is added to the PATH, eg:
|
269
296
|
|
270
|
-
|
297
|
+
export PATH=~/mingw-w64/w32/bin:$PATH
|
271
298
|
|
272
|
-
You can add this to your
|
299
|
+
You can add this to your `.profile` to avoid the repitition.
|
273
300
|
|
274
|
-
|
301
|
+
#### I've got my tool-chain installed, now what?
|
275
302
|
|
276
303
|
First, you need to build Ruby for Windows on your Linux or OSX system.
|
277
304
|
|
278
305
|
Relax, no need to freak out! Let rake-compiler do all the heavy lifting for you:
|
279
306
|
|
280
|
-
|
307
|
+
rake-compiler cross-ruby
|
281
308
|
|
282
309
|
And you're done. It will automatically download, configure and compile the latest
|
283
|
-
stable version of Ruby for Windows, and place it into your
|
310
|
+
stable version of Ruby for Windows, and place it into your `~/.rake-compiler`
|
284
311
|
directory.
|
285
312
|
|
286
|
-
This will create
|
287
|
-
knows where to find the
|
313
|
+
This will create `~/.rake-compiler/config.yml` file so that rake-compiler
|
314
|
+
knows where to find the `rbconfig.rb` file that matches the Ruby version
|
288
315
|
on the Windows host system you're cross-compiling for. An example:
|
289
316
|
|
290
|
-
|
317
|
+
# File: ~/.rake-compiler/config.yml
|
291
318
|
|
292
|
-
|
293
|
-
|
294
|
-
|
319
|
+
rbconfig-x86-mingw32-1.8.6: /path/to/ruby-1.8.6/rbconfig.rb
|
320
|
+
rbconfig-x86-mingw32-1.8.7: /path/to/ruby-1.8.7/rbconfig.rb
|
321
|
+
rbconfig-x86-mingw32-1.9.2: /path/to/ruby-1.9.2/rbconfig.rb
|
295
322
|
|
296
323
|
If, instead, you want to build a different Ruby version than the default one, please
|
297
|
-
supply a
|
324
|
+
supply a `VERSION`:
|
298
325
|
|
299
|
-
|
326
|
+
rake-compiler cross-ruby VERSION=1.8.6-p114
|
300
327
|
|
301
328
|
If you, like me, have multiple versions of MinGW packages installed, you can
|
302
329
|
specify the HOST that will be used to cross compile Ruby:
|
303
330
|
|
304
|
-
|
331
|
+
rake-compiler cross-ruby HOST=x86-mingw32 # (OSX mingw32 port)
|
305
332
|
|
306
333
|
The host will vary depending on provider (mingw32 versus mingw-w64 projects).
|
307
334
|
Please consult the documentation and website of the MinGW package provider before
|
308
335
|
reporting any issues.
|
309
336
|
|
310
|
-
|
337
|
+
#### OK, let's cross compile some gems!
|
311
338
|
|
312
339
|
Now, you only need specify a few additional options in your extension definition:
|
313
340
|
|
@@ -338,53 +365,53 @@ Now, you only need specify a few additional options in your extension definition
|
|
338
365
|
|
339
366
|
By default, cross compilation targets 'i386-mingw32' which is the default
|
340
367
|
GCC platform for Ruby. MRI Ruby's current official distribution uses
|
341
|
-
|
342
|
-
|
343
|
-
Windows targets, respectively. Note that
|
344
|
-
are synonymous here;
|
368
|
+
`i386-mswin32-60`. The RubyInstaller distribution uses
|
369
|
+
`x86-mingw32` and `x64-mingw32` for 32-bit and 64-bit
|
370
|
+
Windows targets, respectively. Note that `i386` and `x86`
|
371
|
+
are synonymous here; `x86` is preferred going forward.
|
345
372
|
|
346
|
-
The format for
|
347
|
-
hashes. Hashes will be fetched for each value of
|
373
|
+
The format for `cross_config_options` is an array of strings and
|
374
|
+
hashes. Hashes will be fetched for each value of `cross_platform`
|
348
375
|
as the build iterates, or ignored if there is no value for that platform.
|
349
376
|
You can mix-and-match strings and hashes to get desired option ordering.
|
350
377
|
|
351
|
-
|
378
|
+
#### Warning, magician about to do some tricks, don't blink!
|
352
379
|
|
353
380
|
Cross compiling is still very simple:
|
354
381
|
|
355
|
-
|
382
|
+
rake cross compile
|
356
383
|
|
357
384
|
And now, building gems for your Windows users is just 6 more letters:
|
358
385
|
|
359
|
-
|
386
|
+
rake cross native gem
|
360
387
|
|
361
388
|
And you're done, yeah.
|
362
389
|
|
363
|
-
|
390
|
+
#### But wait, there's more
|
364
391
|
|
365
392
|
You can specify which version of Ruby to build the extension against:
|
366
393
|
|
367
|
-
|
394
|
+
rake cross compile RUBY_CC_VERSION=1.8.6
|
368
395
|
|
369
|
-
For example, if you installed
|
396
|
+
For example, if you installed `1.9.2`, you can do:
|
370
397
|
|
371
|
-
|
398
|
+
rake cross compile RUBY_CC_VERSION=1.9.2
|
372
399
|
|
373
400
|
Even better, you can target multiple versions (ie. 1.8.6 and 1.9.2) in
|
374
401
|
the same gem via:
|
375
402
|
|
376
|
-
|
403
|
+
rake cross compile RUBY_CC_VERSION=1.8.6:1.9.2
|
377
404
|
|
378
405
|
And better yet, you can bundle both binary extensions into one so-called "fat"
|
379
406
|
gem via:
|
380
407
|
|
381
|
-
|
408
|
+
rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.2
|
382
409
|
|
383
410
|
That will place binaries for both the 1.8 and 1.9 versions of your Ruby
|
384
|
-
extensions inside your project's
|
411
|
+
extensions inside your project's `lib_dir` directory:
|
385
412
|
|
386
|
-
|
387
|
-
|
413
|
+
lib/1.8/my_extension.so
|
414
|
+
lib/1.9/my_extension.so
|
388
415
|
|
389
416
|
NOTE: building "fat" gems is currently only supported by rake-compiler when
|
390
417
|
cross compiling from a Linux or OSX host. Patches are welcome if building
|
@@ -392,12 +419,12 @@ cross compiling from a Linux or OSX host. Patches are welcome if building
|
|
392
419
|
|
393
420
|
Now it's up to you to make your gem load the proper binary at runtime:
|
394
421
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
422
|
+
begin
|
423
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
424
|
+
require "#{$1}/my_extension"
|
425
|
+
rescue LoadError
|
426
|
+
require "my_extension"
|
427
|
+
end
|
401
428
|
|
402
429
|
The above technique will lookup first for 1.8 or 1.9 version of the extension
|
403
430
|
and when not found, will look for the plain extension.
|
@@ -406,7 +433,7 @@ This approach catch the cases of provided fat binaries or gems compiled by the
|
|
406
433
|
end user installing the gem. It has also been implemented successfully in
|
407
434
|
several projects.
|
408
435
|
|
409
|
-
|
436
|
+
## What are you talking about? (Give me examples)
|
410
437
|
|
411
438
|
I know all the above sounds like a complete foreign language (it does even for me!).
|
412
439
|
So, what if I show you some examples?
|
@@ -416,19 +443,19 @@ projects and how they use rake-compiler.
|
|
416
443
|
|
417
444
|
http://github.com/rake-compiler/rake-compiler/wiki/projects-using-rake-compiler
|
418
445
|
|
419
|
-
|
446
|
+
## Future
|
420
447
|
|
421
448
|
rake-compiler is a work in progress and we appreciate any and all feedback
|
422
449
|
during the development of it! (and contributions too!)
|
423
450
|
|
424
451
|
You can find more information about rake-compiler:
|
425
452
|
|
426
|
-
*
|
427
|
-
*
|
428
|
-
*
|
429
|
-
*
|
453
|
+
* GitHub: https://github.com/rake-compiler/rake-compiler
|
454
|
+
* Issues: https://github.com/rake-compiler/rake-compiler/issues
|
455
|
+
* Docs: http://rubydoc.info/gems/rake-compiler
|
456
|
+
* Wiki: https://github.com/rake-compiler/rake-compiler/wiki
|
430
457
|
|
431
|
-
|
458
|
+
## Disclaimer
|
432
459
|
|
433
460
|
If you have any trouble, don't hesitate to contact the author. As always,
|
434
461
|
I'm not going to say "Use at your own risk" because I don't want this library
|
@@ -37,7 +37,7 @@ module Rake
|
|
37
37
|
paths = ENV['PATH'].split(File::PATH_SEPARATOR)
|
38
38
|
|
39
39
|
# the pattern to look into (captures *nix and windows executables)
|
40
|
-
pattern = "{mingw32-,i?86*mingw*}gcc{,.*}"
|
40
|
+
pattern = "{mingw32-,i?86*mingw*,x86*mingw*}gcc{,.*}"
|
41
41
|
|
42
42
|
@mingw_gcc_executable = paths.find do |path|
|
43
43
|
# cleanup paths before globbing
|
data/lib/rake/extensiontask.rb
CHANGED
@@ -23,9 +23,11 @@ module Rake
|
|
23
23
|
@cross_compile = false
|
24
24
|
@cross_config_options = []
|
25
25
|
@cross_compiling = nil
|
26
|
-
@no_native =
|
26
|
+
@no_native = (ENV["RAKE_EXTENSION_TASK_NO_NATIVE"] == "true")
|
27
27
|
@config_includes = []
|
28
|
-
|
28
|
+
# Default to an empty list of ruby versions for each platform
|
29
|
+
@ruby_versions_per_platform = Hash.new { |h, k| h[k] = [] }
|
30
|
+
@make = nil
|
29
31
|
end
|
30
32
|
|
31
33
|
def cross_platform
|
@@ -45,15 +47,6 @@ module Rake
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def define
|
48
|
-
if (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby')
|
49
|
-
warn_once <<-EOF
|
50
|
-
WARNING: You're attempting to (cross-)compile C extensions from a platform
|
51
|
-
(#{RUBY_ENGINE}) that does not support native extensions or mkmf.rb.
|
52
|
-
Rerun `rake` under MRI Ruby 1.8.x/1.9.x to cross/native compile.
|
53
|
-
EOF
|
54
|
-
return
|
55
|
-
end
|
56
|
-
|
57
50
|
super
|
58
51
|
|
59
52
|
unless compiled_files.empty?
|
@@ -123,6 +116,7 @@ Rerun `rake` under MRI Ruby 1.8.x/1.9.x to cross/native compile.
|
|
123
116
|
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}/#{ruby_ver}"
|
124
117
|
stage_path = "#{@tmp_dir}/#{platf}/stage"
|
125
118
|
|
119
|
+
siteconf_path = "#{tmp_path}/.rake-compiler-siteconf.rb"
|
126
120
|
tmp_binary_path = "#{tmp_path}/#{binary_path}"
|
127
121
|
tmp_binary_dir_path = File.dirname(tmp_binary_path)
|
128
122
|
stage_binary_path = "#{stage_path}/#{lib_path}/#{binary_path}"
|
@@ -140,10 +134,27 @@ Rerun `rake` under MRI Ruby 1.8.x/1.9.x to cross/native compile.
|
|
140
134
|
directory lib_binary_dir_path
|
141
135
|
directory stage_binary_dir_path
|
142
136
|
|
137
|
+
directory File.dirname(siteconf_path)
|
138
|
+
# Set paths for "make install" destinations
|
139
|
+
file siteconf_path => File.dirname(siteconf_path) do
|
140
|
+
File.open(siteconf_path, "w") do |siteconf|
|
141
|
+
siteconf.puts "require 'rbconfig'"
|
142
|
+
siteconf.puts "require 'mkmf'"
|
143
|
+
siteconf.puts "dest_path = mkintpath(#{File.expand_path(lib_path).dump})"
|
144
|
+
%w[sitearchdir sitelibdir].each do |dir|
|
145
|
+
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
146
|
+
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
143
151
|
# copy binary from temporary location to final lib
|
144
152
|
# tmp/extension_name/extension_name.{so,bundle} => lib/
|
145
|
-
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_binary_dir_path, tmp_binary_path] do
|
146
|
-
install
|
153
|
+
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_binary_dir_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
|
154
|
+
# install in lib for native platform only
|
155
|
+
unless for_platform
|
156
|
+
sh "#{make} install", chdir: tmp_path
|
157
|
+
end
|
147
158
|
end
|
148
159
|
# copy binary from temporary location to staging directory
|
149
160
|
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [stage_binary_dir_path, tmp_binary_path] do
|
@@ -172,12 +183,12 @@ Java extension should be preferred.
|
|
172
183
|
|
173
184
|
# makefile depends of tmp_dir and config_script
|
174
185
|
# tmp/extension_name/Makefile
|
175
|
-
file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
|
186
|
+
file "#{tmp_path}/Makefile" => [tmp_path, extconf, siteconf_path] do |t|
|
176
187
|
options = @config_options.dup
|
177
188
|
|
178
189
|
# include current directory
|
179
190
|
include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
|
180
|
-
cmd = [Gem.ruby, "-I#{include_dirs}"]
|
191
|
+
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}"]
|
181
192
|
|
182
193
|
# build a relative path to extconf script
|
183
194
|
abs_tmp_path = (Pathname.new(Dir.pwd) + tmp_path).realpath
|
@@ -242,6 +253,9 @@ Java extension should be preferred.
|
|
242
253
|
# lib_path
|
243
254
|
lib_path = lib_dir
|
244
255
|
|
256
|
+
# Update compiled platform/version combinations
|
257
|
+
@ruby_versions_per_platform[platf] << ruby_ver
|
258
|
+
|
245
259
|
# create 'native:gem_name' and chain it to 'native' task
|
246
260
|
unless Rake::Task.task_defined?("native:#{@gem_spec.name}:#{platf}")
|
247
261
|
task "native:#{@gem_spec.name}:#{platf}" do |t|
|
@@ -254,7 +268,7 @@ Java extension should be preferred.
|
|
254
268
|
spec.platform = Gem::Platform.new(platf)
|
255
269
|
|
256
270
|
# set ruby version constraints
|
257
|
-
ruby_versions = @ruby_versions_per_platform[platf]
|
271
|
+
ruby_versions = @ruby_versions_per_platform[platf]
|
258
272
|
sorted_ruby_versions = ruby_versions.sort_by do |ruby_version|
|
259
273
|
ruby_version.split(".").collect(&:to_i)
|
260
274
|
end
|
@@ -357,8 +371,7 @@ Java extension should be preferred.
|
|
357
371
|
end
|
358
372
|
|
359
373
|
# Update cross compiled platform/version combinations
|
360
|
-
|
361
|
-
ruby_versions << version
|
374
|
+
@ruby_versions_per_platform[for_platform] << version
|
362
375
|
|
363
376
|
define_cross_platform_tasks_with_version(for_platform, version)
|
364
377
|
|