rake-compiler 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +48 -0
- data/{README.rdoc → README.md} +144 -117
- data/lib/rake/extensioncompiler.rb +1 -1
- data/lib/rake/extensiontask.rb +1 -0
- data/lib/rake/javaextensiontask.rb +81 -20
- data/spec/lib/rake/javaextensiontask_spec.rb +30 -0
- data/tasks/bin/cross-ruby.rake +13 -35
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c720116334e8a54ca3029125770c4bec5b7b7a4cf1f51e5b6784a884834934
|
4
|
+
data.tar.gz: b4e8b071bfb222435f4beb1a9f2e4ba321faa36e77a7c1b75519a2650ed4980c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32e025cf3a640534b5f1448cf0d89b45d41825dcf5ea2d0bd5dd5cc5037375206e8955749e95a65bbe9c6b1f66a17ee15703099df3a9785273d1b38e106631c3
|
7
|
+
data.tar.gz: 2eaf2fdad874b8e875233d121d071aaad651d1c98c711f2e55d69141b6e41177dc62bb29bbdfaec19b17b097ce08006eef11e8e279dfa181d043f6ed3de36f6b
|
data/History.txt
CHANGED
@@ -1,3 +1,51 @@
|
|
1
|
+
=== 1.1.1 / 2020-07-10
|
2
|
+
|
3
|
+
* Changes:
|
4
|
+
* Bump the default Java bytecode to 1.7.
|
5
|
+
#172 [Patch by Charles Oliver Nutter]
|
6
|
+
|
7
|
+
* Enhancements:
|
8
|
+
* Add support for finding x86_64 MinGW GCC.
|
9
|
+
#164 [Patch by Lars Kanis]
|
10
|
+
* Strip cross compiled shared library automatically.
|
11
|
+
#165 [Patch by Lars Kanis]
|
12
|
+
|
13
|
+
=== 1.1.0 / 2019-12-25
|
14
|
+
|
15
|
+
* Bugfixes:
|
16
|
+
* Fix a bug that JavaExtenstionTask can't build anything.
|
17
|
+
#163 [Reported by Kai Kuchenbecker]
|
18
|
+
|
19
|
+
=== 1.0.9 / 2019-12-23
|
20
|
+
|
21
|
+
* Changes:
|
22
|
+
* Use "-Xlint" option for JRuby native extension by default.
|
23
|
+
#158 [Patch by Stephen George]
|
24
|
+
|
25
|
+
* Enhancements:
|
26
|
+
* Make customizable compiler Xlint option for JRuby native extension.
|
27
|
+
#118 [Patch by Hiroshi Hatake]
|
28
|
+
* Add support for Ruby 2.7.
|
29
|
+
#161 [Reported by Masaki Hara]
|
30
|
+
|
31
|
+
=== 1.0.8 / 2019-09-21
|
32
|
+
|
33
|
+
* Enhancements:
|
34
|
+
* Added Rake::JavaExtensionTask#encoding= to pass the -encoding option to
|
35
|
+
javac.
|
36
|
+
#157 [Patch by Tiago Dias]
|
37
|
+
|
38
|
+
* Bugfixes:
|
39
|
+
* Drop EOL'd rubyforge_project directive from .gemspec.
|
40
|
+
#155 [Patch by Olle Jonsson]
|
41
|
+
|
42
|
+
=== 1.0.7 / 2019-01-04
|
43
|
+
|
44
|
+
* Bugfixes:
|
45
|
+
* Fix a bug that JRuby class path detection is failed on
|
46
|
+
cross-compilation.
|
47
|
+
#149 #151 [Reported by Chalupa Petr][Patch by Prashant Vithani]
|
48
|
+
|
1
49
|
=== 1.0.6 / 2018-12-23
|
2
50
|
|
3
51
|
* Enhancements:
|
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 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 Rake::ExtensionTask:
|
|
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
@@ -17,6 +17,11 @@ module Rake
|
|
17
17
|
# Generate class files for specific VM version
|
18
18
|
attr_accessor :target_version
|
19
19
|
|
20
|
+
attr_accessor :encoding
|
21
|
+
|
22
|
+
# Specify lint option
|
23
|
+
attr_accessor :lint_option
|
24
|
+
|
20
25
|
def platform
|
21
26
|
@platform ||= 'java'
|
22
27
|
end
|
@@ -29,10 +34,12 @@ module Rake
|
|
29
34
|
super
|
30
35
|
@source_pattern = '**/*.java'
|
31
36
|
@classpath = nil
|
32
|
-
@java_compiling = nil
|
33
37
|
@debug = false
|
34
|
-
@source_version = '1.
|
35
|
-
@target_version = '1.
|
38
|
+
@source_version = '1.7'
|
39
|
+
@target_version = '1.7'
|
40
|
+
@encoding = nil
|
41
|
+
@java_compiling = nil
|
42
|
+
@lint_option = nil
|
36
43
|
end
|
37
44
|
|
38
45
|
def define
|
@@ -92,10 +99,19 @@ execute the Rake compilation task using the JRuby interpreter.
|
|
92
99
|
EOF
|
93
100
|
warn_once(not_jruby_compile_msg) unless defined?(JRUBY_VERSION)
|
94
101
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
102
|
+
javac_command_line = [
|
103
|
+
"javac",
|
104
|
+
"-target", @target_version,
|
105
|
+
"-source", @source_version,
|
106
|
+
java_lint_arg,
|
107
|
+
"-d", tmp_path,
|
108
|
+
]
|
109
|
+
javac_command_line.concat(java_encoding_args)
|
110
|
+
javac_command_line.concat(java_extdirs_args)
|
111
|
+
javac_command_line.concat(java_classpath_args)
|
112
|
+
javac_command_line << "-g" if @debug
|
113
|
+
javac_command_line.concat(source_files)
|
114
|
+
sh(*javac_command_line)
|
99
115
|
|
100
116
|
# Checkpoint file
|
101
117
|
touch "#{tmp_path}/.build"
|
@@ -185,24 +201,36 @@ execute the Rake compilation task using the JRuby interpreter.
|
|
185
201
|
end
|
186
202
|
|
187
203
|
#
|
188
|
-
# Discover Java Extension Directories and build an extdirs
|
204
|
+
# Discover Java Extension Directories and build an extdirs arguments
|
189
205
|
#
|
190
|
-
def
|
206
|
+
def java_extdirs_args
|
191
207
|
extdirs = Java::java.lang.System.getProperty('java.ext.dirs') rescue nil
|
192
|
-
extdirs
|
193
|
-
|
208
|
+
extdirs ||= ENV['JAVA_EXT_DIR']
|
209
|
+
if extdirs.nil?
|
210
|
+
[]
|
211
|
+
else
|
212
|
+
["-extdirs", extdirs]
|
213
|
+
end
|
194
214
|
end
|
195
215
|
|
196
216
|
#
|
197
|
-
#
|
217
|
+
# Build an encoding arguments
|
198
218
|
#
|
199
|
-
|
200
|
-
|
219
|
+
def java_encoding_args
|
220
|
+
if @encoding.nil?
|
221
|
+
[]
|
222
|
+
else
|
223
|
+
["-encoding", @encoding]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# Discover the Java/JRuby classpath and build a classpath arguments
|
201
229
|
#
|
202
230
|
# Copied verbatim from the ActiveRecord-JDBC project. There are a small myriad
|
203
231
|
# of ways to discover the Java classpath correctly.
|
204
232
|
#
|
205
|
-
def
|
233
|
+
def java_classpath_args
|
206
234
|
jruby_cpath = nil
|
207
235
|
if RUBY_PLATFORM =~ /java/
|
208
236
|
begin
|
@@ -212,16 +240,49 @@ execute the Rake compilation task using the JRuby interpreter.
|
|
212
240
|
rescue => e
|
213
241
|
end
|
214
242
|
end
|
243
|
+
|
244
|
+
# jruby_cpath might not be present from Java-9 onwards as it removes
|
245
|
+
# sun.boot.class.path. Check if JRUBY_HOME is set as env variable and try
|
246
|
+
# to find jruby.jar under JRUBY_HOME
|
247
|
+
unless jruby_cpath
|
248
|
+
jruby_home = ENV['JRUBY_HOME']
|
249
|
+
if jruby_home
|
250
|
+
candidate = File.join(jruby_home, 'lib', 'jruby.jar')
|
251
|
+
jruby_cpath = candidate if File.exist?(candidate)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# JRUBY_HOME is not necessarily set in JRuby-9.x
|
256
|
+
# Find the libdir from RbConfig::CONFIG and find jruby.jar under the
|
257
|
+
# found lib path
|
215
258
|
unless jruby_cpath
|
216
259
|
libdir = RbConfig::CONFIG['libdir']
|
217
|
-
if libdir.start_with?
|
218
|
-
raise 'Cannot build with jruby-complete'
|
260
|
+
if libdir.start_with?("uri:classloader:")
|
261
|
+
raise 'Cannot build with jruby-complete from Java 9 onwards'
|
219
262
|
end
|
220
|
-
|
263
|
+
candidate = File.join(libdir, "jruby.jar")
|
264
|
+
jruby_cpath = candidate if File.exist?(candidate)
|
265
|
+
end
|
266
|
+
|
267
|
+
unless jruby_cpath
|
268
|
+
raise "Could not find jruby.jar. Please set JRUBY_HOME or use jruby in rvm"
|
269
|
+
end
|
270
|
+
|
271
|
+
if @classpath and @classpath.size > 0
|
272
|
+
jruby_cpath = [jruby_cpath, *@classpath].join(File::PATH_SEPARATOR)
|
221
273
|
end
|
222
|
-
jruby_cpath
|
223
|
-
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
|
274
|
+
["-cp", jruby_cpath]
|
224
275
|
end
|
225
276
|
|
277
|
+
#
|
278
|
+
# Convert a `-Xlint:___` linting option such as `deprecation` into a full javac argument, such as `-Xlint:deprecation`.
|
279
|
+
#
|
280
|
+
# @return [String] Default: _Simply `-Xlint` is run, which enables recommended warnings.
|
281
|
+
#
|
282
|
+
def java_lint_arg
|
283
|
+
return '-Xlint' unless @lint_option
|
284
|
+
|
285
|
+
"-Xlint:#{@lint_option}"
|
286
|
+
end
|
226
287
|
end
|
227
288
|
end
|
@@ -76,9 +76,14 @@ describe Rake::JavaExtensionTask do
|
|
76
76
|
@ext.config_options.should be_empty
|
77
77
|
end
|
78
78
|
|
79
|
+
it 'should have no lint option preset to delegate' do
|
80
|
+
@ext.lint_option.should be_falsey
|
81
|
+
end
|
82
|
+
|
79
83
|
it 'should default to Java platform' do
|
80
84
|
@ext.platform.should == 'java'
|
81
85
|
end
|
86
|
+
end
|
82
87
|
|
83
88
|
context '(tasks)' do
|
84
89
|
before :each do
|
@@ -165,6 +170,31 @@ describe Rake::JavaExtensionTask do
|
|
165
170
|
end
|
166
171
|
end
|
167
172
|
end
|
173
|
+
|
174
|
+
context 'A custom extension' do
|
175
|
+
let(:extension) do
|
176
|
+
Rake::JavaExtensionTask.new('extension_two') do |ext|
|
177
|
+
ext.lint_option = lint_option if lint_option
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'without a specified lint option' do
|
182
|
+
let(:lint_option) { nil }
|
183
|
+
|
184
|
+
it 'should honor the lint option' do
|
185
|
+
(extension.lint_option).should be_falsey
|
186
|
+
(extension.send :java_lint_arg).should eq '-Xlint'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with a specified lint option of 'deprecated'" do
|
191
|
+
let(:lint_option) { 'deprecated'.freeze }
|
192
|
+
|
193
|
+
it 'should honor the lint option' do
|
194
|
+
(extension.lint_option).should eq lint_option
|
195
|
+
(extension.send :java_lint_arg).should eq '-Xlint:deprecated'
|
196
|
+
end
|
197
|
+
end
|
168
198
|
end
|
169
199
|
end
|
170
200
|
private
|
data/tasks/bin/cross-ruby.rake
CHANGED
@@ -58,13 +58,16 @@ MINGW_TARGET = MINGW_HOST.gsub('msvc', '')
|
|
58
58
|
ENV.delete(var)
|
59
59
|
end
|
60
60
|
|
61
|
+
source_dir = "#{USER_HOME}/sources/#{RUBY_CC_VERSION}"
|
62
|
+
build_dir = "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}"
|
63
|
+
|
61
64
|
# define a location where sources will be stored
|
62
|
-
directory
|
63
|
-
directory
|
65
|
+
directory source_dir
|
66
|
+
directory build_dir
|
64
67
|
|
65
68
|
# clean intermediate files and folders
|
66
|
-
CLEAN.include(
|
67
|
-
CLEAN.include(
|
69
|
+
CLEAN.include(source_dir)
|
70
|
+
CLEAN.include(build_dir)
|
68
71
|
|
69
72
|
# remove the final products and sources
|
70
73
|
CLOBBER.include("#{USER_HOME}/sources")
|
@@ -87,36 +90,12 @@ end
|
|
87
90
|
|
88
91
|
# Extract the sources
|
89
92
|
source_file = RUBY_SOURCE ? RUBY_SOURCE.split('/').last : "#{RUBY_CC_VERSION}.tar.bz2"
|
90
|
-
file
|
93
|
+
file source_dir => ["#{USER_HOME}/sources/#{source_file}"] do |t|
|
91
94
|
chdir File.dirname(t.name) do
|
92
95
|
t.prerequisites.each { |f| sh "tar xf #{File.basename(f)}" }
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
96
|
-
# backup makefile.in
|
97
|
-
file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in.bak" => ["#{USER_HOME}/sources/#{RUBY_CC_VERSION}"] do |t|
|
98
|
-
cp "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in", t.name
|
99
|
-
end
|
100
|
-
|
101
|
-
# correct the makefiles
|
102
|
-
file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in" => ["#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in.bak"] do |t|
|
103
|
-
content = File.open(t.name, 'rb') { |f| f.read }
|
104
|
-
|
105
|
-
out = ""
|
106
|
-
|
107
|
-
content.each_line do |line|
|
108
|
-
if line =~ /^\s*ALT_SEPARATOR =/
|
109
|
-
out << "\t\t ALT_SEPARATOR = \"\\\\\\\\\"; \\\n"
|
110
|
-
else
|
111
|
-
out << line
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
when_writing("Patching Makefile.in") {
|
116
|
-
File.open(t.name, 'wb') { |f| f.write(out) }
|
117
|
-
}
|
118
|
-
end
|
119
|
-
|
120
99
|
task :mingw32 do
|
121
100
|
unless MINGW_HOST then
|
122
101
|
warn "You need to install mingw32 cross compile functionality to be able to continue."
|
@@ -126,8 +105,7 @@ task :mingw32 do
|
|
126
105
|
end
|
127
106
|
|
128
107
|
# generate the makefile in a clean build location
|
129
|
-
file "#{
|
130
|
-
"#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in"] do |t|
|
108
|
+
file "#{build_dir}/Makefile" => [build_dir, source_dir] do |t|
|
131
109
|
|
132
110
|
options = [
|
133
111
|
"--host=#{MINGW_HOST}",
|
@@ -135,7 +113,8 @@ file "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/Makefile" => ["#{USER
|
|
135
113
|
"--build=#{RUBY_BUILD}",
|
136
114
|
'--enable-shared',
|
137
115
|
'--disable-install-doc',
|
138
|
-
'--with-ext='
|
116
|
+
'--with-ext=',
|
117
|
+
'LDFLAGS=-pipe -s',
|
139
118
|
]
|
140
119
|
|
141
120
|
# Force Winsock2 for Ruby 1.8, 1.9 defaults to it
|
@@ -149,14 +128,14 @@ file "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/Makefile" => ["#{USER
|
|
149
128
|
end
|
150
129
|
|
151
130
|
# make
|
152
|
-
file "#{
|
131
|
+
file "#{build_dir}/ruby.exe" => ["#{build_dir}/Makefile"] do |t|
|
153
132
|
chdir File.dirname(t.prerequisites.first) do
|
154
133
|
sh MAKE
|
155
134
|
end
|
156
135
|
end
|
157
136
|
|
158
137
|
# make install
|
159
|
-
file "#{USER_HOME}/ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}/bin/ruby.exe" => ["#{
|
138
|
+
file "#{USER_HOME}/ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}/bin/ruby.exe" => ["#{build_dir}/ruby.exe"] do |t|
|
160
139
|
chdir File.dirname(t.prerequisites.first) do
|
161
140
|
sh "#{MAKE} install"
|
162
141
|
end
|
@@ -210,4 +189,3 @@ end
|
|
210
189
|
|
211
190
|
desc "Build #{RUBY_CC_VERSION} suitable for cross-platform development."
|
212
191
|
task 'cross-ruby' => [:mingw32, :install, 'update-config']
|
213
|
-
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
- Luis Lavena
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -77,14 +77,14 @@ executables:
|
|
77
77
|
- rake-compiler
|
78
78
|
extensions: []
|
79
79
|
extra_rdoc_files:
|
80
|
-
- README.
|
80
|
+
- README.md
|
81
81
|
- LICENSE.txt
|
82
82
|
- History.txt
|
83
83
|
files:
|
84
84
|
- Gemfile
|
85
85
|
- History.txt
|
86
86
|
- LICENSE.txt
|
87
|
-
- README.
|
87
|
+
- README.md
|
88
88
|
- Rakefile
|
89
89
|
- appveyor.yml
|
90
90
|
- bin/rake-compiler
|
@@ -126,10 +126,10 @@ homepage: https://github.com/rake-compiler/rake-compiler
|
|
126
126
|
licenses:
|
127
127
|
- MIT
|
128
128
|
metadata: {}
|
129
|
-
post_install_message:
|
129
|
+
post_install_message:
|
130
130
|
rdoc_options:
|
131
131
|
- "--main"
|
132
|
-
- README.
|
132
|
+
- README.md
|
133
133
|
- "--title"
|
134
134
|
- rake-compiler -- Documentation
|
135
135
|
require_paths:
|
@@ -145,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: 1.8.23
|
147
147
|
requirements: []
|
148
|
-
rubygems_version: 3.0.
|
149
|
-
signing_key:
|
148
|
+
rubygems_version: 3.2.0.pre1
|
149
|
+
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: Rake-based Ruby Extension (C, Java) task generator.
|
152
152
|
test_files: []
|