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

Cross Compile looks for Ruby headers in the wrong directory #232

Closed
ParadoxV5 opened this issue Jan 21, 2024 · 5 comments · Fixed by #233
Closed

Cross Compile looks for Ruby headers in the wrong directory #232

ParadoxV5 opened this issue Jan 21, 2024 · 5 comments · Fixed by #233

Comments

@ParadoxV5
Copy link
Contributor

ParadoxV5 commented Jan 21, 2024

mkmf.rb can't find header files for ruby at <absolute/path/to/config/`tmp_dir`>/<`cross_platform`>/<`name`>/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

Edit: It could be that I used my existing RubyIntaller2 prebuild instead of letting rake-compiler rebuild the entire Ruby from source.

Analysis

Cross Compile currently works by replacing RbConfig::CONFIG with a fake.rb script in the $LOAD_PATH. This fake.rb copy-pastes the the target platform’s rbconfig.rb verbatim.

# copy the rbconfig from the cross-ruby location and
# genearte fake.rb for different ruby versions
file "#{tmp_path}/fake.rb" => [rbconfig_file] do |t|
File.open(t.name, 'w') do |f|
# Keep the original RbConfig::CONFIG["ENABLE_SHARED"] to use
# the same RubyGems extension directory. See also
# Gem::BasicSpecificaion#extenions_dir and
# Gem.extension_api_version.
#
# if RbConfig::CONFIG["ENABLE_SHARED"] == "no"
# "extensions/x86_64-linux/2.5.0-static"
# else
# "extensions/x86_64-linux/2.5.0"
# end
f.puts("require 'rbconfig'")
f.puts("original_enable_shared = RbConfig::CONFIG['ENABLE_SHARED']")
f.puts(fake_rb(for_platform, ruby_ver))
f.puts(File.read(t.prerequisites.first))
f.puts("RbConfig::CONFIG['ENABLE_SHARED'] = original_enable_shared")
end
end

However, rbconfig.rb begins with this for RubyIntaller2:

# Ruby installed directory.
TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/3.3.0/x64-mingw-ucrt")

Same for Ubuntu, for that matter:

# Ruby installed directory.
TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/3.3.0/x86_64-linux")

With __FILE__ being /path/to/project/tmp/fake.rb rather than /path/to/target/ruby/rbconfig.rb, RbConfig::TOPDIR becomes nil and leads to a cascade of fallbacks.

@kou
Copy link
Member

kou commented Jan 22, 2024

Do you want to cross compile on Windows?

@ParadoxV5
Copy link
Contributor Author

I want(ed) to cross compile from WSL Ubuntu to Windows.

@kou
Copy link
Member

kou commented Jan 22, 2024

Could you show all command lines you used for it? (How to reproduce this?)

@ParadoxV5
Copy link
Contributor Author

ParadoxV5 commented Jan 22, 2024

  1. Download and extract https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.3.0-1/rubyinstaller-3.3.0-1-x64.7z
  2. ~/.rake-compiler/config.yml:
    ---
    rbconfig-x64-mingw-3.3.0: /path/to/ruby33/ruby/lib/ruby/3.3.0/x64-mingw-ucrt/rbconfig.rb
  3. Skip rake-compile, go straight to rake cross compile

@kou
Copy link
Member

kou commented Jan 22, 2024

Thanks.
The usage isn't supported.

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.

2 participants