oxidize-rb / rb-sys

Easily build Ruby native extensions in Rust
https://oxidize-rb.github.io/rb-sys/
Apache License 2.0
230 stars 35 forks source link

Native gem rake task not included via ExtensionTask by default #249

Closed mgmarlow closed 1 year ago

mgmarlow commented 1 year ago

Description

Hello! I'm unsure what the intended behavior is for this issue, but I thought I'd raise it because it caused me a bit of confusion.

When I use the default generated Rakefile:

# frozen_string_literal: true

require "bundler/gem_tasks"
require "rb_sys/extensiontask"

task build: :compile

RbSys::ExtensionTask.new("my_gem") do |ext|
  ext.lib_dir = "lib/my_gem"
end

task default: :compile

And I try to build a native gem (e.g. one that includes the compiled dependency), I run into this error:

my_gem (main) % bundle exec rake native gem
rake aborted!
Don't know how to build task 'native' (See the list of available tasks with `rake --tasks`)
/Users/mgmarlow/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
/Users/mgmarlow/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'
(See full trace by running task with --trace)

I can fix the problem by manually passing GEMSPEC as the second argument to RbSys::ExtensionTask:

# ...snip

GEMSPEC = Gem::Specification.load("my_gem.gemspec")

RbSys::ExtensionTask.new("my_gem", GEMSPEC) do |ext|
  ext.lib_dir = "lib/my_gem"
end

Versions

GEM
  remote: https://rubygems.org/
  specs:
    rake (13.0.6)
    rake-compiler (1.2.1)
      rake
    rb_sys (0.9.81)
ianks commented 1 year ago

Yeah... I think this is the default behavior of rake-compiler. I think it would be worthwhile to address this in rubygems, so we just generate this code by default. Would you be interested in helping with that?

mgmarlow commented 1 year ago

Sure, I can take a look at that

mgmarlow commented 1 year ago

Closed by https://github.com/rubygems/rubygems/pull/7015