rake-compiler 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +13 -0
  3. data/README.md +29 -0
  4. data/lib/rake/extensiontask.rb +44 -12
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49fcf758dd603f22ed6ce9a327ebf2dfed50a2b54644050fd5059ad9901d5e4e
4
- data.tar.gz: 7716b914ed2965585f32119f10d052e2556e468128246a4a878815cc75ba9466
3
+ metadata.gz: 9cb4094b72287bf86e445b06b208331b6b9057a70677345bbe5396dd2536979b
4
+ data.tar.gz: 5187cb62cd90f974bcec3aa26e0d91562c961480c99ebafa549d2c3e20e79aa0
5
5
  SHA512:
6
- metadata.gz: 787addff745e3330c8402da616bae6dd76233506c629f6b3a14905a5b5bec4aa3a6bb6d3cd1869f89a34d35c780aa7b1800fdfc35e5c6ad5eee2809b284a7b8b
7
- data.tar.gz: 0ef3f9091f58ac37c47a662cc209b11cb4cc1c90ead30232b5a9cbf7afdf00339557773eaa7d49085f77007865bb6b806229a67c53efcc595c42c94abc22ee57
6
+ metadata.gz: 9a435b46290e8736a57dab44cddc8b1180b64b39575e943285525c54393f131c03b1957498aaba96f6b89d303ce66399904640858ab4e49f5f385c9193283757
7
+ data.tar.gz: e3a7e183a03b298caa425c1f4836227499e4203c10d90db32c615c093338cc2a255d1f85b4c55a1729dc6f7fb3e58ee7f5ad2523af3e0854a861608d765ee2e1
data/History.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 1.3.2 / 2026-10-08
2
+
3
+ * Improvements:
4
+ * GH-257: Add support for content addressable gem.
5
+ * Patch by Harriet Oughton
6
+ * Patch by Jenny Shen
7
+ * Patch by Gira Chawda
8
+
9
+ * Thanks:
10
+ * Harriet Oughton
11
+ * Jenny Shen
12
+ * Gira Chawda
13
+
1
14
  ### 1.3.1 / 2025-05-06
2
15
 
3
16
  * Improvements:
data/README.md CHANGED
@@ -247,6 +247,7 @@ end
247
247
  | cross_config_options | ExtensionTask (CRuby) | [Optional] See [Cross compilation - the future is now.](#cross-compilation---the-future-is-now) Default: `[]`. |
248
248
  | no_native | ExtensionTask (CRuby) | [Optional] Set to true to prevent non-CRuby platforms from defining native tasks. Default: `false`. |
249
249
  | config_includes | ExtensionTask (CRuby) | [Optional] Specify an Array of paths to include as `-I...:...` includes during compilation. Default: `['.']`. |
250
+ | content_addressable | ExtensionTask (CRuby) | [Optional] Set to true to also build a content addressable gem per Ruby ABI. See [Building content addressable gems](#building-content-addressable-gems). Default: `false`. |
250
251
  | classpath | JavaExtensionTask | [Optional] Specify additional classpath paths as an Array. Default: _Uses the current CLASSPATH._ |
251
252
  | debug | JavaExtensionTask | [Optional] Whether to set the debug flag during compilation. Default: `false`. |
252
253
  | source_version | JavaExtensionTask | [Optional] The JRE version that your source code requires to compile. Default: `1.6`. |
@@ -444,6 +445,34 @@ This approach catch the cases of provided fat binaries or gems compiled by the
444
445
  end user installing the gem. It has also been implemented successfully in
445
446
  several projects.
446
447
 
448
+ #### Building content addressable gems
449
+
450
+ RubyGems 4.1.0 or later can build gems that target a single Ruby ABI and are
451
+ named by the hash of their contents instead of by platform. If you enable
452
+ `content_addressable`, rake-compiler builds one of these gems for each Ruby
453
+ version in `RUBY_CC_VERSION`, in addition to the multi ABI gem:
454
+
455
+ ```ruby
456
+ Rake::ExtensionTask.new('my_extension', gem_spec) do |ext|
457
+ ext.cross_compile = true
458
+ ext.cross_platform = ['x86_64-linux', 'arm64-darwin']
459
+ ext.content_addressable = true
460
+ end
461
+ ```
462
+
463
+ rake cross native gem RUBY_CC_VERSION=3.3.11:3.4.9
464
+
465
+ This produces, in `pkg/`, the usual multi ABI gem plus one gem per Ruby ABI whose
466
+ `required_ruby_version` is pinned to that ABI:
467
+
468
+ pkg/my_gem-1.0.0-x86_64-linux.gem # multi ABI gem, Ruby >= 3.3, < 3.5.dev
469
+ pkg/my_gem-1.0.0-<hash>.gem # Ruby ~> 3.3.0
470
+ pkg/my_gem-1.0.0-<hash>.gem # Ruby ~> 3.4.0
471
+
472
+ `rake native` and `rake native:<platform>` build the multi ABI gem and all of
473
+ the single ABI gems. To build only the gem for one Ruby ABI, run
474
+ `rake native:<gem name>:<platform>:<ruby abi>`.
475
+
447
476
  ## What are you talking about? (Give me examples)
448
477
 
449
478
  I know all the above sounds like a complete foreign language (it does even for me!).
@@ -15,6 +15,7 @@ module Rake
15
15
  attr_writer :cross_config_options
16
16
  attr_accessor :no_native
17
17
  attr_accessor :config_includes
18
+ attr_accessor :content_addressable
18
19
 
19
20
  def init(name = nil, gem_spec = nil)
20
21
  super
@@ -26,6 +27,7 @@ module Rake
26
27
  @cross_compiling = nil
27
28
  @no_native = (ENV["RAKE_EXTENSION_TASK_NO_NATIVE"] == "true")
28
29
  @config_includes = []
30
+ @content_addressable = false
29
31
  # Default to an empty list of ruby versions for each platform
30
32
  @ruby_versions_per_platform = Hash.new { |h, k| h[k] = [] }
31
33
  @make = nil
@@ -54,6 +56,13 @@ module Rake
54
56
  warn "WARNING: rake-compiler found compiled files in '#{@ext_dir}' directory. Please remove them."
55
57
  end
56
58
 
59
+ if @content_addressable && !Gem::PackageTask.method_defined?(:content_addressable=)
60
+ warn <<~MSG
61
+ WARNING: content_addressable is enabled but RubyGems #{Gem::VERSION} does not support content addressable gems.
62
+ Only the multi-ABI gem will be built. Upgrade RubyGems with `gem update --system`.
63
+ MSG
64
+ end
65
+
57
66
  # only gems with 'ruby' platforms are allowed to define native tasks
58
67
  define_native_tasks if !@no_native && (@gem_spec && @gem_spec.platform == 'ruby')
59
68
 
@@ -257,9 +266,22 @@ Java extension should be preferred.
257
266
  # Update compiled platform/version combinations
258
267
  @ruby_versions_per_platform[platf] << ruby_ver
259
268
 
269
+ native_task_name = "native:#{@gem_spec.name}:#{platf}"
270
+
271
+ # packaging tasks to define: task name => Ruby ABI (nil for the multi-ABI gem)
272
+ package_tasks = { native_task_name => nil }
273
+
274
+ # when content addressable, also build a single Ruby ABI gem per Ruby version
275
+ if content_addressable && Gem::PackageTask.method_defined?(:content_addressable=)
276
+ abi = ruby_api_version(ruby_ver)
277
+ package_tasks["#{native_task_name}:#{abi}"] = abi
278
+ end
279
+
260
280
  # create 'native:gem_name' and chain it to 'native' task
261
- unless Rake::Task.task_defined?("native:#{@gem_spec.name}:#{platf}")
262
- task "native:#{@gem_spec.name}:#{platf}" do |t|
281
+ package_tasks.each do |task_name, ruby_abi|
282
+ next if Rake::Task.task_defined?(task_name)
283
+
284
+ task task_name do |t|
263
285
  # FIXME: workaround Gem::Specification limitation around cache_file:
264
286
  # http://github.com/rubygems/rubygems/issues/78
265
287
  spec = gem_spec.dup
@@ -269,14 +291,19 @@ Java extension should be preferred.
269
291
  spec.platform = Gem::Platform.new(platf)
270
292
 
271
293
  # set ruby version constraints
272
- ruby_versions = @ruby_versions_per_platform[platf]
273
- sorted_ruby_versions = ruby_versions.sort_by do |ruby_version|
274
- ruby_version.split(".").collect(&:to_i)
294
+ if ruby_abi
295
+ # pessimistic version requirement for a single Ruby ABI gem
296
+ spec.required_ruby_version = "~> #{ruby_abi}.0"
297
+ else
298
+ ruby_versions = @ruby_versions_per_platform[platf]
299
+ sorted_ruby_versions = ruby_versions.sort_by do |ruby_version|
300
+ ruby_version.split(".").collect(&:to_i)
301
+ end
302
+ spec.required_ruby_version = [
303
+ ">= #{ruby_api_version(sorted_ruby_versions.first)}",
304
+ "< #{ruby_api_version(sorted_ruby_versions.last).succ}.dev"
305
+ ]
275
306
  end
276
- spec.required_ruby_version = [
277
- ">= #{ruby_api_version(sorted_ruby_versions.first)}",
278
- "< #{ruby_api_version(sorted_ruby_versions.last).succ}.dev"
279
- ]
280
307
 
281
308
  # set rubygems version constraints
282
309
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.22") &&
@@ -313,6 +340,9 @@ Java extension should be preferred.
313
340
  # Do not copy any files per PackageTask, because
314
341
  # we need the files from the staging directory
315
342
  p.package_files.clear
343
+ # Gem::PackageTask scopes its staging directory by Ruby ABI when
344
+ # content_addressable is set, so every gem still lands in `pkg/`.
345
+ p.content_addressable = true if ruby_abi
316
346
  end
317
347
 
318
348
  # copy other gem files to staging directory if added by the callback
@@ -343,7 +373,9 @@ Java extension should be preferred.
343
373
  end
344
374
 
345
375
  # add binaries to the dependency chain
346
- task "native:#{@gem_spec.name}:#{platf}" => ["#{stage_path}/#{lib_binary_path}"]
376
+ package_tasks.each_key do |task_name|
377
+ task task_name => ["#{stage_path}/#{lib_binary_path}"]
378
+ end
347
379
 
348
380
  # ensure the extension get copied
349
381
  unless Rake::Task.task_defined?(lib_binary_path) then
@@ -352,12 +384,12 @@ Java extension should be preferred.
352
384
  file "#{stage_path}/#{lib_binary_path}" => ["copy:#{@name}:#{platf}:#{ruby_ver}"]
353
385
 
354
386
  # Allow segmented packaging by platform (open door for 'cross compile')
355
- task "native:#{platf}" => ["native:#{@gem_spec.name}:#{platf}"]
387
+ task "native:#{platf}" => package_tasks.keys
356
388
 
357
389
  # Only add this extension to the compile chain if current
358
390
  # platform matches the indicated one.
359
391
  if platf == RUBY_PLATFORM then
360
- task "native:#{@gem_spec.name}" => ["native:#{@gem_spec.name}:#{platf}"]
392
+ task "native:#{@gem_spec.name}" => package_tasks.keys
361
393
  task "native" => ["native:#{platf}"]
362
394
  end
363
395
  end
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.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: 1.8.23
144
144
  requirements: []
145
- rubygems_version: 3.6.9
145
+ rubygems_version: 4.0.20
146
146
  specification_version: 4
147
147
  summary: Rake-based Ruby Extension (C, Java) task generator.
148
148
  test_files: []