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

Prevent rake-compiler from overriding required_ruby_version? #153

Closed
glebm opened this issue May 29, 2019 · 8 comments · May be fixed by #154
Closed

Prevent rake-compiler from overriding required_ruby_version? #153

glebm opened this issue May 29, 2019 · 8 comments · May be fixed by #154

Comments

@glebm
Copy link

glebm commented May 29, 2019

I'm working on a gem that uses FFI and doesn't use libruby directly.

This means it doesn't need an .so file per Ruby version, and that the pre-compiled binary gems should have the same required_ruby_version as the original gemspec.

rake-compiler currently does this when cross-compiling:

spec.required_ruby_version = [
">= #{ruby_api_version(sorted_ruby_versions.first)}",
"< #{ruby_api_version(sorted_ruby_versions.last).succ}.dev"
]

Is there any way to override this behaviour?

@glebm
Copy link
Author

glebm commented May 29, 2019

Super-ugly workaround:

gem_spec = Gem::Specification.load("sassc.gemspec")

# HACK: Prevent rake-compiler from overriding required_ruby_version,
# because the shared library here is Ruby-agnostic.
# See https://github.com/rake-compiler/rake-compiler/issues/153
module FixRequiredRubyVersion
  def required_ruby_version=(*); end
end
Gem::Specification.prepend(FixRequiredRubyVersion)

Rake::ExtensionTask.new('libsass', gem_spec) do |ext|
  ...
end

sass/sassc-ruby@f1c7677

@kou
Copy link
Member

kou commented May 31, 2019

sass/sassc-ruby@f1c7677#diff-52c976fc38ed2b4e3b1192f8a8e24cffL25 is expected code for this case.

The cross_compiling block exists for customizing corss-compiled gemspec:

callback.call(spec) if callback

@glebm
Copy link
Author

glebm commented May 31, 2019

Doesn't work when I override in the block. Perhaps it is invoked earlier?

@kou
Copy link
Member

kou commented May 31, 2019

How to reproduce your problem?

glebm added a commit to glebm/rake-compiler that referenced this issue Jun 12, 2019
This is needed for gems that use the ffi gem instead of libruby.

Fixes rake-compiler#153
glebm added a commit to glebm/rake-compiler that referenced this issue Jun 12, 2019
This is needed for gems that use the ffi gem instead of libruby.

Fixes rake-compiler#153
@glebm
Copy link
Author

glebm commented Jun 12, 2019

@kou Looks like it may be possible to override it in the block (not sure why it seemed to not work for me).

Still, I'd like to add a setting for this instead, as there is another thing to check when the gem doesn't use libruby: there should only be one RUBY_CC_VERSION.

@larskanis
Copy link
Member

spec.required_ruby_version can be overwritten by the registered ext.cross_compiling block. But there is an issue that this callback isn't called in any case, unless ext.no_native=true is set. This has been discussed in
#171 .

Next rake-compiler-dock version will set no_native=true per default, so that the callback can be used for cases like this.

CAMOBAP added a commit to lutaml/expressir that referenced this issue Dec 29, 2020
@larskanis
Copy link
Member

The required_ruby_version can be set per cross compile block like so:

Rake::ExtensionTask.new('my_extension', gem_spec) do |ext|
  ext.cross_compiling do |spec|
    spec.required_ruby_version = [">= 2.5", "< 3.2.dev"]
  end
end

The issue with not calling the cross_compiling block is solved in #171 . So can this issue be closed now?

@flavorjones
Copy link
Contributor

I agree that we can probably close it, given that the workaround exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants