rake-compiler 1.2.2 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1307a1f8d635b6fa407ce62a9e301a9d2ccfb358fb77e3ed85c3d22492fd6a1e
4
- data.tar.gz: d562c91bfee82d65d39b67b118c9b9395e33be402b2c41058d4251ae2e88a37f
3
+ metadata.gz: 7a79867d000ebf722309c4b0573deda2d27364421729666fa2df74c0876daceb
4
+ data.tar.gz: e6ba055360cad7bde216401588647bfc1cca2319fb32e404430a98ecf0a26e03
5
5
  SHA512:
6
- metadata.gz: 1d1c34c803284711dff655cd8b4d7a34766d1ade90556ffeed111349777c67e143a55705bda5bce95f6629c2bc45a7e528da666f20595cb45c7e2986ee3c9269
7
- data.tar.gz: dfabaa0805a27ee2150a406a2e7e26c6345ea279866e271c1936ab95b8090a0bb6fa0919a42509ae4d6652e8d249a694c4b70b7ace351335afb7cbace8fa7cf8
6
+ metadata.gz: 6f234853779e19b35542456e590c32fefbc177d0124e4420ce2eeb109e6dd68c3b6f7f2ec1fb23540011e16fd3bbee913575ec3fd66691327f2c4f16386a4e40
7
+ data.tar.gz: ebce66c281af8bb6d6602bdd811b74ed57a4f56ff0542d648f21adb92c989e2f9cbd3afb25cb85aa3118f4f8cbd7c8ce80c7a701788e52986f0928b22fabdd9f
data/History.md CHANGED
@@ -1,3 +1,46 @@
1
+ ### 1.2.5 / 2023-08-03
2
+
3
+ * Fixes:
4
+ * GH-225: Fixed a bug that `rake compile` may not work on Windows.
5
+ [Reported by Lukasz Suleja]
6
+ * GH-224 GH-226: Fixed a bug that 1.2.4 doesn't work on Ruby < 2.6.
7
+ [Reported by Ivo Anjo]
8
+ [Patch by Mike Dalessio and Akira Matsuda separately]
9
+
10
+ * Thanks:
11
+ * Lukasz Suleja
12
+ * Ivo Anjo
13
+ * Mike Dalessio
14
+ * Akira Matsuda
15
+
16
+ ### 1.2.4 / 2023-08-01
17
+
18
+ * Enhancements:
19
+ * GH-221: Enabled syntax highlighting in documents.
20
+ [Patch by Ryo Nakamura]
21
+ * GH-202 GH-222: Use environment variables to set install paths.
22
+ [Reported by Brandon Fish]
23
+ [Patch by Michael Go]
24
+
25
+ * Thanks:
26
+ * Ryo Nakamura
27
+ * Brandon Fish
28
+ * Michael Go
29
+
30
+ ### 1.2.3 / 2023-05-30
31
+
32
+ * Enhancements:
33
+ * GH-217: Added support for `nil` in build options again.
34
+ [Patch by Mike Dalessio]
35
+
36
+ * Fixes:
37
+ * GH-219: Fixed a typo in documentation.
38
+ [Patch by y-yagi]
39
+
40
+ * Thanks:
41
+ * Mike Dalessio
42
+ * y-yagi
43
+
1
44
  ### 1.2.2 / 2023-05-25
2
45
 
3
46
  * Enhancements:
@@ -9,7 +52,7 @@
9
52
  [Reported by Jun Aruga]
10
53
 
11
54
  * Fixes:
12
- * GH-211: Fixed a typo in documentation.
55
+ * GH-212: Fixed a typo in documentation.
13
56
  [Patch by Jan-Benedikt Jagusch]
14
57
 
15
58
  * 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
- # File: extconf.rb
72
+ ```ruby
73
+ # File: extconf.rb
73
74
 
74
- # these lines must exist already
75
- require 'mkmf'
76
- create_makefile('hello_world')
75
+ # these lines must exist already
76
+ require 'mkmf'
77
+ create_makefile('hello_world')
77
78
 
78
- # File: Rakefile
79
+ # File: Rakefile
79
80
 
80
- require 'rake/extensiontask'
81
+ require 'rake/extensiontask'
81
82
 
82
- Rake::ExtensionTask.new('hello_world')
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
- # File: Rakefile
98
+ ```ruby
99
+ # File: Rakefile
97
100
 
98
- require 'rake/javaextensiontask'
101
+ require 'rake/javaextensiontask'
99
102
 
100
- Rake::JavaExtensionTask.new('hello_world')
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
- # somewhere in your Rakefile, define your gem spec
144
- spec = Gem::Specification.new do |s|
145
- s.name = "my_gem"
146
- s.platform = Gem::Platform::RUBY
147
- s.extensions = FileList["ext/**/extconf.rb"]
148
- end
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
- # add your default gem packing task
151
- Gem::PackageTask.new(spec) do |pkg|
152
- end
155
+ # add your default gem packing task
156
+ Gem::PackageTask.new(spec) do |pkg|
157
+ end
153
158
 
154
- # feed the ExtensionTask with your spec
155
- Rake::ExtensionTask.new('hello_world', spec)
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
- Rake::ExtensionTask.new do |ext|
213
- ext.name = 'hello_world' # indicate the name of the extension.
214
- ext.ext_dir = 'ext/weird_world' # search for 'hello_world' inside it.
215
- ext.lib_dir = 'lib/my_lib' # put binaries into this folder.
216
- ext.config_script = 'custom_extconf.rb' # use instead of the default 'extconf.rb'.
217
- ext.tmp_dir = 'tmp' # temporary folder used during compilation.
218
- ext.source_pattern = "*.{c,cpp}" # monitor file changes to allow simple rebuild.
219
- ext.config_options << '--with-foo' # supply additional options to configure script.
220
- ext.gem_spec = spec # optionally indicate which gem specification
221
- # will be used.
222
- end
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
- Rake::ExtensionTask.new('my_extension', gem_spec) do |ext|
342
- # enable cross compilation (requires cross compile toolchain)
343
- ext.cross_compile = true
344
-
345
- # set a single platform or an array of platforms to target
346
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
347
-
348
- # cross-compile options will be passed to extconf.rb for each
349
- # platform build, with platform-specific options in a hash.
350
- ext.cross_config_options << '--with-common-option'
351
- ext.cross_config_options << {
352
- 'x86-mswin32-60' => '--with-some-option',
353
- 'x64-mingw32' => '--enable-64bits',
354
- }
355
- ext.cross_config_options << '--with-final-option'
356
-
357
- # perform alterations on the gemspec when cross compiling
358
- ext.cross_compiling do |gem_spec|
359
- # such as packaging a file that isn't specified in the gemspec
360
- gem_spec.files << 'lib/generated_file.rb'
361
- # or adding a new installation message
362
- gem_spec.post_install_message = "You installed the binary version of this gem!"
363
- end
364
- end
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
- begin
423
- RUBY_VERSION =~ /(\d+\.\d+)/
424
- require "#{$1}/my_extension"
425
- rescue LoadError
426
- require "my_extension"
427
- end
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.
@@ -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
- sh "#{make} install target_prefix=", chdir: tmp_path
166
+ relative_lib_path = Pathname(lib_path).relative_path_from(Pathname.new(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, siteconf_path] do |t|
191
- options = @config_options.dup
192
-
193
- # include current directory
194
- include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
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
- # add options to command
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 *cmd
214
+ sh(*command)
219
215
  end
220
216
  end
221
217
 
@@ -517,12 +513,15 @@ Java extension should be preferred.
517
513
  def find_make
518
514
  candidates = ["gmake", "make"]
519
515
  paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
516
+ paths = paths.collect do |path|
517
+ Pathname(path).cleanpath
518
+ end
520
519
 
521
520
  exeext = RbConfig::CONFIG["EXEEXT"]
522
521
  candidates.each do |candidate|
523
522
  paths.each do |path|
524
- make = File.join(path, "#{candidate}#{exeext}")
525
- return make if File.executable?(make)
523
+ make = path + "#{candidate}#{exeext}"
524
+ return make.to_s if make.executable?
526
525
  end
527
526
  end
528
527
 
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.2
4
+ version: 1.2.5
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-05-25 00:00:00.000000000 Z
12
+ date: 2023-08-02 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