rake-compiler 1.2.2 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +29 -1
- data/README.md +74 -63
- data/lib/rake/extensiontask.rb +37 -41
- metadata +2 -8
- data/spec/lib/rake/compiler_config_spec.rb +0 -54
- data/spec/lib/rake/extensiontask_spec.rb +0 -679
- data/spec/lib/rake/javaextensiontask_spec.rb +0 -237
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -15
- data/spec/support/capture_output_helper.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89347c74f92c88f38e362b44957b4f3995846f9354f3462bd2774e9fab7fe2a9
|
4
|
+
data.tar.gz: 0e074b3563de7228bcf09036527eb2756653e519c3493926fdfeda3b64761b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d9d1a747ff0ad05422b8bf96de8f5be572f405a66ba8dbcb9a97fd6c4a343358f27de553ab02b9c5674ed52dd6697144dc2b176ec7da3d2eea99ae28f9fc5d4
|
7
|
+
data.tar.gz: 9350f3c428d92e6a9b0a08ecdd0b220043d3990ffb1fcaf33aaf4e9ffd513d0001f0bcf0e9a78964392f135dd9263d45e21b2d8dbe33e74f4582fdafd8387fa4
|
data/History.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
### 1.2.4 / 2023-08-01
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
* GH-221: Enabled syntax highlighting in documents.
|
5
|
+
[Patch by Ryo Nakamura]
|
6
|
+
* GH-202 GH-222: Use environment variables to set install paths.
|
7
|
+
[Reported by Brandon Fish]
|
8
|
+
[Patch by Michael Go]
|
9
|
+
|
10
|
+
* Thanks:
|
11
|
+
* Ryo Nakamura
|
12
|
+
* Brandon Fish
|
13
|
+
* Michael Go
|
14
|
+
|
15
|
+
### 1.2.3 / 2023-05-30
|
16
|
+
|
17
|
+
* Enhancements:
|
18
|
+
* GH-217: Added support for `nil` in build options again.
|
19
|
+
[Patch by Mike Dalessio]
|
20
|
+
|
21
|
+
* Fixes:
|
22
|
+
* GH-219: Fixed a typo in documentation.
|
23
|
+
[Patch by y-yagi]
|
24
|
+
|
25
|
+
* Thanks:
|
26
|
+
* Mike Dalessio
|
27
|
+
* y-yagi
|
28
|
+
|
1
29
|
### 1.2.2 / 2023-05-25
|
2
30
|
|
3
31
|
* Enhancements:
|
@@ -9,7 +37,7 @@
|
|
9
37
|
[Reported by Jun Aruga]
|
10
38
|
|
11
39
|
* Fixes:
|
12
|
-
* GH-
|
40
|
+
* GH-212: Fixed a typo in documentation.
|
13
41
|
[Patch by Jan-Benedikt Jagusch]
|
14
42
|
|
15
43
|
* Thanks:
|
data/README.md
CHANGED
@@ -69,17 +69,19 @@ contribute back to your project.
|
|
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:
|
71
71
|
|
72
|
-
|
72
|
+
```ruby
|
73
|
+
# File: extconf.rb
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
# these lines must exist already
|
76
|
+
require 'mkmf'
|
77
|
+
create_makefile('hello_world')
|
77
78
|
|
78
|
-
|
79
|
+
# File: Rakefile
|
79
80
|
|
80
|
-
|
81
|
+
require 'rake/extensiontask'
|
81
82
|
|
82
|
-
|
83
|
+
Rake::ExtensionTask.new('hello_world')
|
84
|
+
```
|
83
85
|
|
84
86
|
That's it? Yes, that's it! No other lines of code are needed for
|
85
87
|
rake-compiler to work its magic.
|
@@ -93,11 +95,13 @@ below for details.
|
|
93
95
|
If you want to do the same for a JRuby extension written in Java, it's just
|
94
96
|
as easy:
|
95
97
|
|
96
|
-
|
98
|
+
```ruby
|
99
|
+
# File: Rakefile
|
97
100
|
|
98
|
-
|
101
|
+
require 'rake/javaextensiontask'
|
99
102
|
|
100
|
-
|
103
|
+
Rake::JavaExtensionTask.new('hello_world')
|
104
|
+
```
|
101
105
|
|
102
106
|
### The simple process
|
103
107
|
|
@@ -140,19 +144,21 @@ building native gems on Windows systems.
|
|
140
144
|
Creating native gems is really easy with rake-compiler's
|
141
145
|
`Rake::ExtensionTask`:
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
```ruby
|
148
|
+
# somewhere in your Rakefile, define your gem spec
|
149
|
+
spec = Gem::Specification.new do |s|
|
150
|
+
s.name = "my_gem"
|
151
|
+
s.platform = Gem::Platform::RUBY
|
152
|
+
s.extensions = FileList["ext/**/extconf.rb"]
|
153
|
+
end
|
149
154
|
|
150
|
-
|
151
|
-
|
152
|
-
|
155
|
+
# add your default gem packing task
|
156
|
+
Gem::PackageTask.new(spec) do |pkg|
|
157
|
+
end
|
153
158
|
|
154
|
-
|
155
|
-
|
159
|
+
# feed the ExtensionTask with your spec
|
160
|
+
Rake::ExtensionTask.new('hello_world', spec)
|
161
|
+
```
|
156
162
|
|
157
163
|
As expected, you can still build your pure-ruby gem in the usual way
|
158
164
|
(standard output) by running:
|
@@ -209,18 +215,19 @@ Yes you can! While the conventional project structure is recommended, you may
|
|
209
215
|
want, or need, to tweak those conventions. Rake-compiler allows you to customize
|
210
216
|
several settings for `Rake::ExtensionTask`:
|
211
217
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
218
|
+
```ruby
|
219
|
+
Rake::ExtensionTask.new do |ext|
|
220
|
+
ext.name = 'hello_world' # indicate the name of the extension.
|
221
|
+
ext.ext_dir = 'ext/weird_world' # search for 'hello_world' inside it.
|
222
|
+
ext.lib_dir = 'lib/my_lib' # put binaries into this folder.
|
223
|
+
ext.config_script = 'custom_extconf.rb' # use instead of the default 'extconf.rb'.
|
224
|
+
ext.tmp_dir = 'tmp' # temporary folder used during compilation.
|
225
|
+
ext.source_pattern = "*.{c,cpp}" # monitor file changes to allow simple rebuild.
|
226
|
+
ext.config_options << '--with-foo' # supply additional options to configure script.
|
227
|
+
ext.gem_spec = spec # optionally indicate which gem specification
|
228
|
+
# will be used.
|
229
|
+
end
|
230
|
+
```
|
224
231
|
|
225
232
|
### Show me all of the supported configuration options
|
226
233
|
|
@@ -338,30 +345,32 @@ reporting any issues.
|
|
338
345
|
|
339
346
|
Now, you only need specify a few additional options in your extension definition:
|
340
347
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
348
|
+
```ruby
|
349
|
+
Rake::ExtensionTask.new('my_extension', gem_spec) do |ext|
|
350
|
+
# enable cross compilation (requires cross compile toolchain)
|
351
|
+
ext.cross_compile = true
|
352
|
+
|
353
|
+
# set a single platform or an array of platforms to target
|
354
|
+
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
|
355
|
+
|
356
|
+
# cross-compile options will be passed to extconf.rb for each
|
357
|
+
# platform build, with platform-specific options in a hash.
|
358
|
+
ext.cross_config_options << '--with-common-option'
|
359
|
+
ext.cross_config_options << {
|
360
|
+
'x86-mswin32-60' => '--with-some-option',
|
361
|
+
'x64-mingw32' => '--enable-64bits',
|
362
|
+
}
|
363
|
+
ext.cross_config_options << '--with-final-option'
|
364
|
+
|
365
|
+
# perform alterations on the gemspec when cross compiling
|
366
|
+
ext.cross_compiling do |gem_spec|
|
367
|
+
# such as packaging a file that isn't specified in the gemspec
|
368
|
+
gem_spec.files << 'lib/generated_file.rb'
|
369
|
+
# or adding a new installation message
|
370
|
+
gem_spec.post_install_message = "You installed the binary version of this gem!"
|
371
|
+
end
|
372
|
+
end
|
373
|
+
```
|
365
374
|
|
366
375
|
By default, cross compilation targets 'i386-mingw32' which is the default
|
367
376
|
GCC platform for Ruby. MRI Ruby's current official distribution uses
|
@@ -419,12 +428,14 @@ cross compiling from a Linux or OSX host. Patches are welcome if building
|
|
419
428
|
|
420
429
|
Now it's up to you to make your gem load the proper binary at runtime:
|
421
430
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
431
|
+
```ruby
|
432
|
+
begin
|
433
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
434
|
+
require "#{$1}/my_extension"
|
435
|
+
rescue LoadError
|
436
|
+
require "my_extension"
|
437
|
+
end
|
438
|
+
```
|
428
439
|
|
429
440
|
The above technique will lookup first for 1.8 or 1.9 version of the extension
|
430
441
|
and when not found, will look for the plain extension.
|
data/lib/rake/extensiontask.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rbconfig"
|
2
|
+
require "shellwords"
|
2
3
|
|
3
4
|
require 'rake/baseextensiontask'
|
4
5
|
require "rubygems/package_task"
|
@@ -79,6 +80,26 @@ module Rake
|
|
79
80
|
end.flatten
|
80
81
|
end
|
81
82
|
|
83
|
+
def make_makefile_cmd(root_path, tmp_path, extconf, cross_platform) # :nodoc:
|
84
|
+
# include current directory
|
85
|
+
include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
|
86
|
+
|
87
|
+
# build a relative path to extconf script
|
88
|
+
abs_tmp_path = (Pathname.new(root_path) + tmp_path).realpath
|
89
|
+
abs_extconf = (Pathname.new(root_path) + extconf).realpath
|
90
|
+
rel_extconf = abs_extconf.relative_path_from(abs_tmp_path).to_s
|
91
|
+
|
92
|
+
# base command
|
93
|
+
cmd = [Gem.ruby, "-I#{include_dirs}", rel_extconf]
|
94
|
+
|
95
|
+
# add all the options
|
96
|
+
cmd += @config_options
|
97
|
+
cmd += cross_config_options(cross_platform) if cross_platform
|
98
|
+
cmd += extra_options
|
99
|
+
|
100
|
+
cmd.compact
|
101
|
+
end
|
102
|
+
|
82
103
|
private
|
83
104
|
# copy other gem files to staging directory
|
84
105
|
def define_staging_file_tasks(files, lib_path, stage_path, platf, ruby_ver)
|
@@ -120,7 +141,6 @@ module Rake
|
|
120
141
|
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}/#{ruby_ver}"
|
121
142
|
stage_path = "#{@tmp_dir}/#{platf}/stage"
|
122
143
|
|
123
|
-
siteconf_path = "#{tmp_path}/.rake-compiler-siteconf.rb"
|
124
144
|
tmp_binary_path = "#{tmp_path}/#{binary_path}"
|
125
145
|
tmp_binary_dir_path = File.dirname(tmp_binary_path)
|
126
146
|
stage_binary_path = "#{stage_path}/#{lib_binary_path}"
|
@@ -138,26 +158,20 @@ module Rake
|
|
138
158
|
directory lib_path
|
139
159
|
directory stage_binary_dir_path
|
140
160
|
|
141
|
-
directory File.dirname(siteconf_path)
|
142
|
-
# Set paths for "make install" destinations
|
143
|
-
file siteconf_path => File.dirname(siteconf_path) do
|
144
|
-
File.open(siteconf_path, "w") do |siteconf|
|
145
|
-
siteconf.puts "require 'rbconfig'"
|
146
|
-
siteconf.puts "require 'mkmf'"
|
147
|
-
siteconf.puts "dest_path = mkintpath(#{File.expand_path(lib_path).dump})"
|
148
|
-
%w[sitearchdir sitelibdir].each do |dir|
|
149
|
-
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
150
|
-
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
161
|
# copy binary from temporary location to final lib
|
156
162
|
# tmp/extension_name/extension_name.{so,bundle} => lib/
|
157
163
|
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
|
158
164
|
# install in lib for native platform only
|
159
165
|
unless for_platform
|
160
|
-
|
166
|
+
relative_lib_path = Pathname(lib_path).relative_path_from(tmp_path)
|
167
|
+
|
168
|
+
make_command_line = Shellwords.shellsplit(make)
|
169
|
+
make_command_line << "install"
|
170
|
+
make_command_line << "sitearchdir=#{relative_lib_path}"
|
171
|
+
make_command_line << "sitelibdir=#{relative_lib_path}"
|
172
|
+
make_command_line << "target_prefix="
|
173
|
+
|
174
|
+
sh(*make_command_line, chdir: tmp_path)
|
161
175
|
end
|
162
176
|
end
|
163
177
|
# copy binary from temporary location to staging directory
|
@@ -187,35 +201,17 @@ Java extension should be preferred.
|
|
187
201
|
|
188
202
|
# makefile depends of tmp_dir and config_script
|
189
203
|
# tmp/extension_name/Makefile
|
190
|
-
file "#{tmp_path}/Makefile" => [tmp_path, extconf
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}"]
|
196
|
-
|
197
|
-
# build a relative path to extconf script
|
198
|
-
abs_tmp_path = (Pathname.new(Dir.pwd) + tmp_path).realpath
|
199
|
-
abs_extconf = (Pathname.new(Dir.pwd) + extconf).realpath
|
200
|
-
|
201
|
-
# now add the extconf script
|
202
|
-
cmd << abs_extconf.relative_path_from(abs_tmp_path).to_s
|
203
|
-
|
204
|
-
# fake.rb will be present if we are cross compiling
|
205
|
-
if t.prerequisites.include?("#{tmp_path}/fake.rb") then
|
206
|
-
options.push(*cross_config_options(platf))
|
204
|
+
file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
|
205
|
+
if t.prerequisites.include?("#{tmp_path}/fake.rb")
|
206
|
+
cross_platform = platf
|
207
|
+
else
|
208
|
+
cross_platform = nil
|
207
209
|
end
|
208
210
|
|
209
|
-
|
210
|
-
cmd.push(*options)
|
211
|
-
|
212
|
-
# add any extra command line options
|
213
|
-
unless extra_options.empty?
|
214
|
-
cmd.push(*extra_options)
|
215
|
-
end
|
211
|
+
command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, cross_platform)
|
216
212
|
|
217
213
|
chdir tmp_path do
|
218
|
-
sh
|
214
|
+
sh(*command)
|
219
215
|
end
|
220
216
|
end
|
221
217
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -112,12 +112,6 @@ files:
|
|
112
112
|
- lib/rake/extensioncompiler.rb
|
113
113
|
- lib/rake/extensiontask.rb
|
114
114
|
- lib/rake/javaextensiontask.rb
|
115
|
-
- spec/lib/rake/compiler_config_spec.rb
|
116
|
-
- spec/lib/rake/extensiontask_spec.rb
|
117
|
-
- spec/lib/rake/javaextensiontask_spec.rb
|
118
|
-
- spec/spec.opts
|
119
|
-
- spec/spec_helper.rb
|
120
|
-
- spec/support/capture_output_helper.rb
|
121
115
|
- tasks/bin/cross-ruby.rake
|
122
116
|
- tasks/bootstrap.rake
|
123
117
|
- tasks/common.rake
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
require 'rake/extensiontask'
|
4
|
-
require 'rbconfig'
|
5
|
-
require 'tempfile'
|
6
|
-
|
7
|
-
describe Rake::CompilerConfig do
|
8
|
-
def config_file(contents)
|
9
|
-
Tempfile.new.tap do |tf|
|
10
|
-
tf.write(contents)
|
11
|
-
tf.close
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the matching config for exact platform match" do
|
16
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
17
|
-
---
|
18
|
-
rbconfig-x86_64-linux-3.0.0: "/path/to/aaa/rbconfig.rb"
|
19
|
-
rbconfig-x86_64-darwin-3.1.0: "/path/to/bbb/rbconfig.rb"
|
20
|
-
rbconfig-x86_64-linux-3.1.0: "/path/to/ccc/rbconfig.rb"
|
21
|
-
CONFIG
|
22
|
-
|
23
|
-
expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
|
24
|
-
expect(cc.find("3.1.0", "x86_64-darwin")).to eq("/path/to/bbb/rbconfig.rb")
|
25
|
-
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/ccc/rbconfig.rb")
|
26
|
-
|
27
|
-
expect(cc.find("2.7.0", "x86_64-linux")).to be_nil
|
28
|
-
expect(cc.find("3.1.0", "arm64-linux")).to be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns the matching config for inexact platform match" do
|
32
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
33
|
-
---
|
34
|
-
rbconfig-x86_64-linux-gnu-3.0.0: "/path/to/aaa/rbconfig.rb"
|
35
|
-
rbconfig-x86_64-linux-musl-3.1.0: "/path/to/bbb/rbconfig.rb"
|
36
|
-
CONFIG
|
37
|
-
|
38
|
-
expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
|
39
|
-
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/bbb/rbconfig.rb")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "does not match the other way around" do
|
43
|
-
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("3.3.21")
|
44
|
-
skip "rubygems 3.3.21+ only"
|
45
|
-
end
|
46
|
-
|
47
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
48
|
-
---
|
49
|
-
rbconfig-x86_64-linux-3.1.0: "/path/to/bbb/rbconfig.rb"
|
50
|
-
CONFIG
|
51
|
-
|
52
|
-
expect(cc.find("3.1.0", "x86_64-linux-musl")).to be_nil
|
53
|
-
end
|
54
|
-
end
|