Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binaries installed into subdirectories based on Ruby version - incompatible with how bundler's Rust extension template works #312

Open
taylorthurlow opened this issue Jan 12, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@taylorthurlow
Copy link

taylorthurlow commented Jan 12, 2024

I had no issues getting my Rust extension working locally, but one of the issues I ran into was using the cross-compile action. Once I got the build working, the resulting gem packages were built with the precompiled binary in a path like lib/my_gem/3.0/my_gem.bundle. This is incompatible with the extconf.rb generated by Bundler. The local build generates lib/my_gem/my_gem.bundle.

# lib/my_gem/extconf.rb as generated by Bundler

# frozen_string_literal: true

require_relative "my_gem/version"
require_relative "my_gem/my_gem"

module MyGem
  class Error < StandardError; end
end

I saw that wasmtime seemed to have the same problem, and they fixed it like so:

# lib/my_gem/extconf.rb

# frozen_string_literal: true

require_relative "my_gem/version"

# Tries to require the extension for the given Ruby version first
begin
  RUBY_VERSION =~ /(\d+\.\d+)/
  require "my_gem/#{Regexp.last_match(1)}/my_gem"
rescue LoadError
  require_relative "my_gem/my_gem"
end

module MyGem
  class Error < StandardError; end
end

EDIT: Looks like specifying a single Ruby version target gets you the standard my_gem/my_gem.bundle, multiple gets you the subdirectories. Understandable, but worth mentioning.

@ianks
Copy link
Collaborator

ianks commented Apr 12, 2024

Yeah, it's a bit of a hack but that's the recommended rake-compiler pattern so I went with it... Would def accept a patch to document this better.

@ianks ianks added documentation Improvements or additions to documentation good first issue Good for newcomers labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants