Search code examples
rubydevkitmkmf

Ruby failed to build native gem


I'm trying to make Ruby development environment portable, and I've had a few issues localising DevKit. It installed fine, but when I try to install a gem that requires it (in this case, wdm). The contents of mkmf.log can be found below:

"gcc -o conftest.exe -IE:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/i386-mingw32 -IE:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/backward -IE:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c  -L. -LE:/Resources/Windows/Software/Ruby/RubyPortable/lib -L.      -lmsvcrt-ruby230  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
In file included from E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby.h:33:0,
                 from conftest.c:1:
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:131:14: error: size of array 'ruby_check_sizeof_voidp' is negative
In file included from E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby.h:33:0,
                 from conftest.c:1:
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_obj_freeze_inline':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1360:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1361:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1362:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1362:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_data_object_get':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1400:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_data_object_make':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1414:5: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_data_typed_object_make':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1421:5: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_num2char_inline':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1587:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1588:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1588:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1588:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_class_of':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1949:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_type':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1966:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
In file included from E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby.h:33:0,
                 from conftest.c:1:
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_clone_setup':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1997:56: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1998:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1999:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:1999:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_dup_setup':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2005:42: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2006:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2006:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_array_len':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2012:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2013:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2013:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_array_const_ptr':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2027:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2027:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2027:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_struct_len':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2034:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2035:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2035:26: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h: In function 'rb_struct_const_ptr':
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2041:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2041:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
E:/Resources/Windows/Software/Ruby/RubyPortable/include/ruby-2.3.0/ruby/ruby.h:2041:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }

The ruby installation is working fine, I'm not sure what's causing this. All gems that don't require devkit work OK, but DevKit just isn't working...


Solution

  • From the looks of things, you either are pretty close and have done most of this, or you have gcc in your PATH somewhere that isn't the DevKit, but I'll explain the entire process on how I would do it if I was going to. NOTE: I don't want to, ever. =(

    This answer is really dense because of all the things that are happening.
    In other words, you have to really want to make this work.
    Don't expect to copy/paste the code and things work without understanding what's going on.

    The DevKit "installs" with absolute paths. If you want to change that you'll have do some really dirty work to make it work.

    The rb file that loads the DevKit is actually located at <ruby>/lib/ruby/site_ruby/devkit.rb assuming <ruby> is the root installation directory. So you'll need to open that.
    NOTE: This file is loaded in a different part of the installation process.

    Then assuming that the devkit folder location is in the same location as your ruby folder, e.g. E:\folderA\ruby and E:\FolderA\devkit you'll need to change it to look something like this:

    # enable RubyInstaller DevKit usage as a vendorable helper library
    devkit_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..', 'devkit'))
    msys_bin_path = File.join(devkit_root, 'bin').gsub(File::SEPARATOR, File::ALT_SEPARATOR)
    mingw_bin_path = File.join(devkit_root, 'mingw', 'bin').gsub(File::SEPARATOR, File::ALT_SEPARATOR)
    
    unless ENV['PATH'].include?(mingw_bin_path) then
      phrase = 'Temporarily enhancing PATH to include DevKit...'
      if defined?(Gem)
        Gem.ui.say(phrase) if Gem.configuration.verbose
      else
        puts phrase
      end
      puts "Prepending ENV['PATH'] to include DevKit..." if $DEBUG
      ENV['PATH'] = "#{msys_bin_path};#{mingw_bin_path};" + ENV['PATH']
    end
    ENV['RI_DEVKIT'] = devkit_root.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
    ENV['CC'] = 'gcc'
    ENV['CXX'] = 'g++'
    ENV['CPP'] = 'cpp'
    

    If the location is any different then you'll have to change the devkit_root relative join.
    If you want to confirm that the path exists, then you can use realpath instead of expand_path.

    Now, if all of this looks similar then it's probably something with the Makefile generation from extconf.rb in the gem you're trying to install. In which case, you'll have to fix that in the gem and maybe open a PR if you're feeling charitable. But it could also be a ton of other things going wrong, so in essence YMMV.