Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rake-compiler/rake-compiler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.0
Choose a base ref
...
head repository: rake-compiler/rake-compiler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.1
Choose a head ref
  • 5 commits
  • 9 files changed
  • 3 contributors

Commits on Apr 15, 2022

  1. Bump version

    kou committed Apr 15, 2022
    Copy the full SHA
    31a2b8f View commit details

Commits on Oct 14, 2022

  1. Fix typo (#208)

    gjtorikian authored Oct 14, 2022
    Copy the full SHA
    8c907ac View commit details

Commits on Dec 15, 2022

  1. Add support for RubyGems 3.3.21 or later (#209)

    Since Rubygems 3.3.21, the Gem::Platform name always contains the
    library version for gnu platforms. So where the rake-compiler config
    entries previously were:
    
    ```yaml
    ---
    rbconfig-x86_64-linux-gnu-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
    rbconfig-x86_64-linux-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
    ```
    
    with later versions of rubygems, it is only
    
    ```yaml
    ---
    rbconfig-x86_64-linux-gnu-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
    ```
    
    This means that the current way of finding a matching runtime, by doing
    a string comparison on the config keys, is no longer appropriate. This
    is causing failing builds downstream in `rake-compiler-dock`.
    
    This PR:
    
    - extracts a new CompilerConfig class to encapsulate the logic
    - uses `Gem::Platform#=~` to tell if the gem platform matches the
    runtime platform
    flavorjones authored Dec 15, 2022
    Copy the full SHA
    66740bb View commit details

Commits on Dec 16, 2022

  1. ci: add release workflow

    kou committed Dec 16, 2022
    Copy the full SHA
    78de4a8 View commit details
  2. Add 1.2.1 entry

    kou committed Dec 16, 2022
    Copy the full SHA
    80b6258 View commit details
Showing with 176 additions and 30 deletions.
  1. +23 −0 .github/workflows/release.yml
  2. +14 −0 History.md
  3. +1 −1 README.md
  4. +2 −0 lib/rake/baseextensiontask.rb
  5. +38 −0 lib/rake/compiler_config.rb
  6. +5 −7 lib/rake/extensiontask.rb
  7. +1 −1 rake-compiler.gemspec
  8. +54 −0 spec/lib/rake/compiler_config_spec.rb
  9. +38 −21 spec/lib/rake/extensiontask_spec.rb
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
push:
tags:
- "*"
jobs:
github:
name: GitHub
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Extract release note
run: |
ruby \
-e 'print("## rake-compiler "); \
puts(ARGF.read.split(/^### /)[1].gsub(/ {.+?}/, ""))' \
History.md > release-note.md
- name: Upload to release
run: |
gh release create \
--discussion-category Announcements \
--notes-file release-node.md
14 changes: 14 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
### 1.2.1 / 2022-12-16

* Enhancements:
* GH-209: Added support for RubyGems 3.3.21 or later.
[Patch by Mike Dalessio]

* Fixes:
* GH-208: Fixed a typo in documentation.
[Patch by Garen Torikian]

* Thanks:
* Garen Torikian
* Mike Dalessio

### 1.2.0 / 2022-04-15

* Enhancements:
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -241,7 +241,7 @@ several settings for `Rake::ExtensionTask`:
| no_native | ExtensionTask (CRuby) | [Optional] Set to true to prevent non-CRuby platforms from defining native tasks. Default: `false`. |
| config_includes | ExtensionTask (CRuby) | [Optional] Specify an Array of paths to include as `-I...:...` includes during compilation. Default: `['.']`. |
| classpath | JavaExtensionTask | [Optional] Specify additional classpath paths as an Array. Default: _Uses the current CLASSPATH._ |
| debug | JavaExtensionTask | [Optional] Whether to set the debug flag during complication. Default: `false`. |
| debug | JavaExtensionTask | [Optional] Whether to set the debug flag during compilation. Default: `false`. |
| source_version | JavaExtensionTask | [Optional] The JRE version that your source code requires to compile. Default: `1.6`. |
| target_version | JavaExtensionTask | [Optional] The oldest JRE version you want to support. Default: `1.6`. |
| encoding | JavaExtensionTask | [Optional] Specify an -encoding option to provide to the compiler. Default: `nil`. |
2 changes: 2 additions & 0 deletions lib/rake/baseextensiontask.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@

require 'pathname'

require_relative "compiler_config"

module Rake
class BaseExtensionTask < TaskLib

38 changes: 38 additions & 0 deletions lib/rake/compiler_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Rake
class CompilerConfig
def initialize(config_path)
require "yaml"
@config = YAML.load_file(config_path)
end

def find(ruby_version, gem_platform)
gem_platform = Gem::Platform.new(gem_platform)

@config.each do |config_name, config_location|
# There are two variations we might find in the rake-compiler config.yml
#
# 1. config_name: rbconfig-x86_64-linux-3.0.0
# runtime_platform_name: x86_64-linux
# runtime_version: 3.0.0
#
# 2. config_name: rbconfig-x86_64-linux-gnu-3.0.0
# runtime_platform_name: x86_64-linux-gnu
# runtime_version: 3.0.0
#
# With rubygems < 3.3.21, both variations will be present (two entries pointing at the same
# installation).
#
# With rubygems >= 3.3.21, only the second variation will be present.
runtime_platform_name = config_name.split("-")[1..-2].join("-")
runtime_version = config_name.split("-").last
runtime_platform = Gem::Platform.new(runtime_platform_name)

if (ruby_version == runtime_version) && (gem_platform =~ runtime_platform)
return config_location
end
end

nil
end
end
end
12 changes: 5 additions & 7 deletions lib/rake/extensiontask.rb
Original file line number Diff line number Diff line change
@@ -393,8 +393,11 @@ def define_cross_platform_tasks_with_version(for_platform, ruby_ver)
return
end

require "yaml"
config_file = YAML.load_file(config_path)
rbconfig_file = Rake::CompilerConfig.new(config_path).find(ruby_ver, for_platform)
unless rbconfig_file
warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})"
return
end

# tmp_path
tmp_path = "#{@tmp_dir}/#{for_platform}/#{@name}/#{ruby_ver}"
@@ -405,11 +408,6 @@ def define_cross_platform_tasks_with_version(for_platform, ruby_ver)
# lib_binary_path
lib_binary_path = "#{lib_path}/#{File.basename(binary(for_platform))}"

unless rbconfig_file = config_file["rbconfig-#{for_platform}-#{ruby_ver}"] then
warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})"
return
end

# mkmf
mkmf_file = File.expand_path(File.join(File.dirname(rbconfig_file), '..', 'mkmf.rb'))

2 changes: 1 addition & 1 deletion rake-compiler.gemspec
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
Gem::Specification.new do |s|
# basic information
s.name = "rake-compiler"
s.version = "1.2.0"
s.version = "1.2.1"
s.platform = Gem::Platform::RUBY

# description and details
54 changes: 54 additions & 0 deletions spec/lib/rake/compiler_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'rake/extensiontask'
require 'rbconfig'
require 'tempfile'

describe Rake::CompilerConfig do
def config_file(contents)
Tempfile.new.tap do |tf|
tf.write(contents)
tf.close
end
end

it "returns the matching config for exact platform match" do
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
---
rbconfig-x86_64-linux-3.0.0: "/path/to/aaa/rbconfig.rb"
rbconfig-x86_64-darwin-3.1.0: "/path/to/bbb/rbconfig.rb"
rbconfig-x86_64-linux-3.1.0: "/path/to/ccc/rbconfig.rb"
CONFIG

expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
expect(cc.find("3.1.0", "x86_64-darwin")).to eq("/path/to/bbb/rbconfig.rb")
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/ccc/rbconfig.rb")

expect(cc.find("2.7.0", "x86_64-linux")).to be_nil
expect(cc.find("3.1.0", "arm64-linux")).to be_nil
end

it "returns the matching config for inexact platform match" do
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
---
rbconfig-x86_64-linux-gnu-3.0.0: "/path/to/aaa/rbconfig.rb"
rbconfig-x86_64-linux-musl-3.1.0: "/path/to/bbb/rbconfig.rb"
CONFIG

expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/bbb/rbconfig.rb")
end

it "does not match the other way around" do
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("3.3.21")
skip "rubygems 3.3.21+ only"
end

cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
---
rbconfig-x86_64-linux-3.1.0: "/path/to/bbb/rbconfig.rb"
CONFIG

expect(cc.find("3.1.0", "x86_64-linux-musl")).to be_nil
end
end
59 changes: 38 additions & 21 deletions spec/lib/rake/extensiontask_spec.rb
Original file line number Diff line number Diff line change
@@ -381,9 +381,10 @@
end

it 'should warn if no section of config file defines running version of ruby' do
config = Hash.new
expect(config).to receive(:[]).with("rbconfig-#{@platform}-#{@ruby_ver}").and_return(nil)
allow(YAML).to receive(:load_file).and_return(config)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find).with(@ruby_ver, @platform).and_return(nil)
)

out, err = capture_output do
Rake::ExtensionTask.new('extension_one') do |ext|
ext.cross_compile = true
@@ -403,9 +404,9 @@
end

it 'should generate additional rake tasks if files are added when cross compiling' do
config = Hash.new
allow(config).to receive(:[]).and_return('/rubies/1.9.1/rbconfig.rb')
allow(YAML).to receive(:load_file).and_return(config)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find).and_return("/rubies/1.9.1/rbconfig.rb")
)

# Use a real spec instead of a mock because define_native_tasks dups and
# calls methods on Gem::Specification, which is more than mock can do.
@@ -433,9 +434,11 @@
end

it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
config = Hash.new
expect(config).to receive(:[]).with("rbconfig-i386-mingw32-1.9.1").and_return('/rubies/1.9.1/rbconfig.rb')
allow(YAML).to receive(:load_file).and_return(config)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with("1.9.1", "i386-mingw32")
.and_return("/rubies/1.9.1/rbconfig.rb")
)

ENV['RUBY_CC_VERSION'] = '1.9.1'
Rake::ExtensionTask.new('extension_one') do |ext|
@@ -444,10 +447,16 @@
end

it 'should allow multiple versions be supplied to RUBY_CC_VERSION' do
config = Hash.new
expect(config).to receive(:[]).once.with("rbconfig-i386-mingw32-1.8.6").and_return('/rubies/1.8.6/rbconfig.rb')
expect(config).to receive(:[]).once.with("rbconfig-i386-mingw32-1.9.1").and_return('/rubies/1.9.1/rbconfig.rb')
allow(YAML).to receive(:load_file).and_return(config)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with("1.8.6", "i386-mingw32")
.and_return("/rubies/1.8.6/rbconfig.rb")
)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with("1.9.1", "i386-mingw32")
.and_return("/rubies/1.9.1/rbconfig.rb")
)

ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
Rake::ExtensionTask.new('extension_one') do |ext|
@@ -459,18 +468,19 @@
platforms = ["x86-mingw32", "x64-mingw32"]
ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1", "2.11.0"]
ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
config = Hash.new

ruby_cc_versions.each do |ruby_cc_version|
platforms.each do |platform|
unless platform == "x64-mingw32" && ruby_cc_version == "2.11.0"
rbconf = "/rubies/#{ruby_cc_version}/rbconfig.rb"
end
allow(config).to receive(:[]).
with("rbconfig-#{platform}-#{ruby_cc_version}").
and_return(rbconf)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with(ruby_cc_version, platform)
.and_return(rbconf)
)
end
end
allow(YAML).to receive(:load_file).and_return(config)

allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)

@@ -515,9 +525,16 @@

context "(cross compile for multiple versions)" do
before :each do
config = Hash.new
allow(config).to receive(:[]).and_return('/rubies/1.8.6/rbconfig.rb', '/rubies/1.9.1/rbconfig.rb')
allow(YAML).to receive(:load_file).and_return(config)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with("1.8.6", "universal-unknown")
.and_return("/rubies/1.8.6/rbconfig.rb")
)
allow_any_instance_of(Rake::CompilerConfig).to(
receive(:find)
.with("1.9.1", "universal-unknown")
.and_return("/rubies/1.9.1/rbconfig.rb")
)

ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
@ext = Rake::ExtensionTask.new('extension_one') do |ext|