rb-sys
rb-sys copied to clipboard
extconf.rb Makefile compiles binary into wrong directory depending on OS
Hello, I'm running into an issue building a native extension from bundle gem --ext=rust
with the default setup. I believe I've narrowed it down to the Makefile generated by create_rust_makefile
in this package.
When I compile locally on my M1 Mac, the resulting gem in bundler has this directory structure:
lib/
my_gem.rb
my_gem/
my_gem.bundle
version.rb
Note the location of my_gem.bundle
, nested under lib/my_gem/
.
However, when I pull my gem down in production (an x86_64 linux machine) and run bundler, I have a different folder structure:
lib/
my_gem.rb
my_gem.so
my_gem/
version.rb
Note my_gem.so
is now up a directory.
This breaks my gem since the require_relative
path in my_gem.rb
expects the compiled binary to live in the my_gem/
directory.
My extconf.rb
is the default generated by bundle gem --ext=rust
:
# frozen_string_literal: true
require "mkmf"
require "rb_sys/mkmf"
create_rust_makefile("my_gem/my_gem")
And the gem entrypoint:
# frozen_string_literal: true
require_relative "my_gem/version"
require_relative "my_gem/my_gem"
module MyGem
class Error < StandardError; end
# Your code goes here...
end
Hmm yeah that looks like a potential bug. Thanks for the excellent report, btw. Will take a look!
Hello @mgmarlow !
Can you still replicate this issue with the latest version of rb-sys
?
I currently can't replicate this issue.
Does this issue happens even if you empty your tmp
folder before you run rake compile
?
Also, could you tell us more information about your environment, please?
What is your version of gem --version
, and which version of rake-compiler
are you using?
Ah, okay nice I think the gem version was the original issue.
- I bumped rb-sys to
0.9.81
and published a new Ruby platform gem, but ran into the same issue on my x86_64 machine. - That linux machine was running a gem version of
3.3.19
. - I bumped the linux gem version to
3.4.18
. - After that, the
*.so
is installed to the proper place.
So it looks like the gem version requirement isn't just on the host machine that actually built the gem (e.g. my Mac that ran bundle exec build
and pushed the gem to a registry) but also on the destination machine when it tries to build that native extension during bundle install
.
I had swapped over to rake native gem
awhile ago which didn't have the same issue, though I wonder if there was a gem --version
difference between those two x86_64 linux machines; that is, the machine that built the native gem and pushed it to the registry, which is different from the destination machine that I've been testing against bundle install
.
It is interesting that the destination machine also has a gem version requirement to run bundle install
, I had thought the gem version requirement was just for using bundle gem --ext=rust
and the related tooling. Is that expected?