Skip to content

Commit 8887afb

Browse files
authored
[ruby] Set ruby version sub-dir (#10)
1 parent b895499 commit 8887afb

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.github/workflows/cross-build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ jobs:
8888
# If we want to go back to specific supported versions, we can use the following:
8989
ruby-versions: ${{ join(fromJSON(needs.ci-data.outputs.result).stable-ruby-versions, ',') }}
9090
# Tried doing this, but it said ">= 3.0, < 3.1.dev" on rubygems.
91-
# Maybe try ">=3.0, < 4" or something like that?
92-
# ruby-versions: ">=3.0"
91+
# Tried ">=3.0, < 4", but RubyGems said: ">= 3.0, < 3.1.dev"
9392
working-directory: ./ruby/optify
9493

9594
- name: "[Ruby] Publish"

ruby/optify/lib/optify.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
# This yields some warnings, but we should redeclare the methods in Ruby to help with type checking anyway.
99
# Warnings about redefining methods are normal and can be ignored
1010
# because the implementations in Ruby are not implemented and only exist to help with type checking.
11-
require_relative 'optify_ruby/optify_ruby'
11+
# Ideally we do:
12+
# `require_relative 'optify_ruby/optify_ruby'`
13+
# but that doesn't work when building for multiple versions of Ruby.
14+
# So we have to do this which is similar to something from 'https://github.com/matsadler/halton-rb/blob/main/lib/halton.rb'.
15+
begin
16+
ruby_version = T.must(RUBY_VERSION.match(/\d+\.\d+/))[0]
17+
require_relative "optify_ruby/#{ruby_version}/optify_ruby"
18+
rescue LoadError
19+
begin
20+
require_relative 'optify_ruby/optify_ruby'
21+
rescue LoadError # Cargo Builder in RubyGems < 3.4.6 doesn't install to dir
22+
require_relative 'optify_ruby.so'
23+
end
24+
end
1225

1326
require_relative 'optify_ruby/base_config'

ruby/optify/optify.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
VERSION = '0.4.2'
3+
VERSION = '0.4.4'
44

55
Gem::Specification.new do |spec|
66
spec.name = 'optify-config'

0 commit comments

Comments
 (0)