rake-compiler 1.2.3 → 1.2.4

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 +14 -0
  3. data/README.md +74 -63
  4. data/lib/rake/extensiontask.rb +14 -20
  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: 89347c74f92c88f38e362b44957b4f3995846f9354f3462bd2774e9fab7fe2a9
4
+ data.tar.gz: 0e074b3563de7228bcf09036527eb2756653e519c3493926fdfeda3b64761b92
5
5
  SHA512:
6
- metadata.gz: a2053558c9908644a0aea5a3fd758b2ee11bf8b57e7e91dd9cb794acd391b5ea35232ad75780f2f86e394c0867fcde13e2fef0913990feff8f1d5dd6745b16f0
7
- data.tar.gz: 0e2da4951102147e9e92e88fbcfd5f6bef58462f82a0c012a22aeaca451d2629994b20db243b7ea93ca09b8682b03ed6229ef8a46b7fada9c76729e6d3c8fbba
6
+ metadata.gz: 6d9d1a747ff0ad05422b8bf96de8f5be572f405a66ba8dbcb9a97fd6c4a343358f27de553ab02b9c5674ed52dd6697144dc2b176ec7da3d2eea99ae28f9fc5d4
7
+ data.tar.gz: 9350f3c428d92e6a9b0a08ecdd0b220043d3990ffb1fcaf33aaf4e9ffd513d0001f0bcf0e9a78964392f135dd9263d45e21b2d8dbe33e74f4582fdafd8387fa4
data/History.md CHANGED
@@ -1,3 +1,17 @@
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
+
1
15
  ### 1.2.3 / 2023-05-30
2
16
 
3
17
  * 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(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)
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.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-05-30 00:00:00.000000000 Z
12
+ date: 2023-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake