rake-compiler 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +29 -0
  3. data/README.md +74 -63
  4. data/lib/rake/extensiontask.rb +19 -22
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 348048ed79bcda098bdaa8f8fa523e2e3b85263911f81ccbb173b879d2d9fd05
4
- data.tar.gz: 2485652f621bcb18ee6a552d2a278ddf6f8cbe584848d6d14799325e1cdad1bd
3
+ metadata.gz: 7a79867d000ebf722309c4b0573deda2d27364421729666fa2df74c0876daceb
4
+ data.tar.gz: e6ba055360cad7bde216401588647bfc1cca2319fb32e404430a98ecf0a26e03
5
5
  SHA512:
6
- metadata.gz: a2053558c9908644a0aea5a3fd758b2ee11bf8b57e7e91dd9cb794acd391b5ea35232ad75780f2f86e394c0867fcde13e2fef0913990feff8f1d5dd6745b16f0
7
- data.tar.gz: 0e2da4951102147e9e92e88fbcfd5f6bef58462f82a0c012a22aeaca451d2629994b20db243b7ea93ca09b8682b03ed6229ef8a46b7fada9c76729e6d3c8fbba
6
+ metadata.gz: 6f234853779e19b35542456e590c32fefbc177d0124e4420ce2eeb109e6dd68c3b6f7f2ec1fb23540011e16fd3bbee913575ec3fd66691327f2c4f16386a4e40
7
+ data.tar.gz: ebce66c281af8bb6d6602bdd811b74ed57a4f56ff0542d648f21adb92c989e2f9cbd3afb25cb85aa3118f4f8cbd7c8ce80c7a701788e52986f0928b22fabdd9f
data/History.md CHANGED
@@ -1,3 +1,32 @@
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
+
1
30
  ### 1.2.3 / 2023-05-30
2
31
 
3
32
  * Enhancements:
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,7 +80,7 @@ module Rake
79
80
  end.flatten
80
81
  end
81
82
 
82
- def make_makefile_cmd(root_path, tmp_path, extconf, siteconf_path, cross_platform) # :nodoc:
83
+ def make_makefile_cmd(root_path, tmp_path, extconf, cross_platform) # :nodoc:
83
84
  # include current directory
84
85
  include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
85
86
 
@@ -89,7 +90,7 @@ module Rake
89
90
  rel_extconf = abs_extconf.relative_path_from(abs_tmp_path).to_s
90
91
 
91
92
  # base command
92
- cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}", rel_extconf]
93
+ cmd = [Gem.ruby, "-I#{include_dirs}", rel_extconf]
93
94
 
94
95
  # add all the options
95
96
  cmd += @config_options
@@ -140,7 +141,6 @@ module Rake
140
141
  tmp_path = "#{@tmp_dir}/#{platf}/#{@name}/#{ruby_ver}"
141
142
  stage_path = "#{@tmp_dir}/#{platf}/stage"
142
143
 
143
- siteconf_path = "#{tmp_path}/.rake-compiler-siteconf.rb"
144
144
  tmp_binary_path = "#{tmp_path}/#{binary_path}"
145
145
  tmp_binary_dir_path = File.dirname(tmp_binary_path)
146
146
  stage_binary_path = "#{stage_path}/#{lib_binary_path}"
@@ -158,26 +158,20 @@ module Rake
158
158
  directory lib_path
159
159
  directory stage_binary_dir_path
160
160
 
161
- directory File.dirname(siteconf_path)
162
- # Set paths for "make install" destinations
163
- file siteconf_path => File.dirname(siteconf_path) do
164
- File.open(siteconf_path, "w") do |siteconf|
165
- siteconf.puts "require 'rbconfig'"
166
- siteconf.puts "require 'mkmf'"
167
- siteconf.puts "dest_path = mkintpath(#{File.expand_path(lib_path).dump})"
168
- %w[sitearchdir sitelibdir].each do |dir|
169
- siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
170
- siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
171
- end
172
- end
173
- end
174
-
175
161
  # copy binary from temporary location to final lib
176
162
  # tmp/extension_name/extension_name.{so,bundle} => lib/
177
163
  task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
178
164
  # install in lib for native platform only
179
165
  unless for_platform
180
- 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)
181
175
  end
182
176
  end
183
177
  # copy binary from temporary location to staging directory
@@ -207,14 +201,14 @@ Java extension should be preferred.
207
201
 
208
202
  # makefile depends of tmp_dir and config_script
209
203
  # tmp/extension_name/Makefile
210
- file "#{tmp_path}/Makefile" => [tmp_path, extconf, siteconf_path] do |t|
204
+ file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
211
205
  if t.prerequisites.include?("#{tmp_path}/fake.rb")
212
206
  cross_platform = platf
213
207
  else
214
208
  cross_platform = nil
215
209
  end
216
210
 
217
- command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, siteconf_path, cross_platform)
211
+ command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, cross_platform)
218
212
 
219
213
  chdir tmp_path do
220
214
  sh(*command)
@@ -519,12 +513,15 @@ Java extension should be preferred.
519
513
  def find_make
520
514
  candidates = ["gmake", "make"]
521
515
  paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
516
+ paths = paths.collect do |path|
517
+ Pathname(path).cleanpath
518
+ end
522
519
 
523
520
  exeext = RbConfig::CONFIG["EXEEXT"]
524
521
  candidates.each do |candidate|
525
522
  paths.each do |path|
526
- make = File.join(path, "#{candidate}#{exeext}")
527
- return make if File.executable?(make)
523
+ make = path + "#{candidate}#{exeext}"
524
+ return make.to_s if make.executable?
528
525
  end
529
526
  end
530
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.3
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-30 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