ruby-prof / ruby-prof

A ruby profiler. See https://ruby-prof.github.io for more information.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to load 1.4.3 on Ruby 2.5

thomthom opened this issue · comments

I'm using Ruby on Windows (via Ruby Installer). 1.4.3 expects to load the binary from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/ext/ruby_prof/ruby_prof.so but no such binary exists. It appear that 2.7 and 3.0 have pre-compiled binaries;

  • C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\ruby-prof-1.4.3-x64-mingw32\lib\2.7
  • C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\ruby-prof-1.4.3-x64-mingw32\lib\3.0

While 2.5 does not and the C extension doesn't compile on demand on compilation. (Used to do so in previous versions.)

1.4.3 installed fine under 2.7 on the same machine.

C:\>gem install ruby-prof
Successfully installed ruby-prof-1.4.3-x64-mingw32
Parsing documentation for ruby-prof-1.4.3-x64-mingw32
Done installing documentation for ruby-prof after 1 seconds
1 gem installed

C:\>irb
irb(main):001:0> require 'ruby-prof'
Traceback (most recent call last):
        8: from C:/Ruby25-x64/bin/irb.cmd:19:in `<main>'
        7: from (irb):1
        6: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require'
        5: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
        4: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require'
        3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:5:in `<top (required)>'
        2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:9:in `rescue in <top (required)>'
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:9:in `require_relative'
LoadError (cannot load such file -- C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/ext/ruby_prof/ruby_prof.so)
irb(main):002:0>

Right, Ruby 2.5 is now officially out of support (https://www.ruby-lang.org/en/downloads/branches/). However, ruby-prof still run on 2.5 and works (as you can see from the automated tests).

But you'll have to build your own version. Which means you need to have devkit installed or have rolled your own msys2/mingw64 environment (or msvc which also works).

Build it from the source repo instead of gem install?

For my own curiosity; on mac it installed via gem install just fine, it built on-demand. This gem used to do the same thing on Windows as well. Did that change and now Windows is pre-built only via gem install?

Follow up question, how does one build the gem from source?

After activating devkitvars.bat and trying to build on Windows I get this:

C:\Users\tthomas2\SourceTree\ruby-prof>rake compile
cd tmp/x64-mingw32/ruby_prof/2.5.7
C:\RubyDevKit\bin/make.exe
generating ruby_prof-x64-mingw32.def
compiling ../../../../ext/ruby_prof/rp_aggregate_call_tree.c
compiling ../../../../ext/ruby_prof/rp_allocation.c
compiling ../../../../ext/ruby_prof/rp_call_tree.c
compiling ../../../../ext/ruby_prof/rp_call_trees.c
compiling ../../../../ext/ruby_prof/rp_measure_allocations.c
compiling ../../../../ext/ruby_prof/rp_measure_memory.c
compiling ../../../../ext/ruby_prof/rp_measure_process_time.c
compiling ../../../../ext/ruby_prof/rp_measure_wall_time.c
compiling ../../../../ext/ruby_prof/rp_measurement.c
compiling ../../../../ext/ruby_prof/rp_method.c
compiling ../../../../ext/ruby_prof/rp_profile.c
compiling ../../../../ext/ruby_prof/rp_stack.c
compiling ../../../../ext/ruby_prof/rp_thread.c
compiling ../../../../ext/ruby_prof/ruby_prof.c
linking shared-object ruby_prof.so
c:/rubydevkit/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgmp
collect2.exe: error: ld returned 1 exit status
make: *** [ruby_prof.so] Error 1
rake aborted!
Command failed with status (2): [C:\RubyDevKit\bin/make.exe...]

Tasks: TOP => compile => compile:x64-mingw32 => compile:ruby_prof:x64-mingw32 => copy:ruby_prof:x64-mingw32:2.5.7 => tmp/x64-mingw32/ruby_prof/2.5.7/ruby_prof.so
(See full trace by running task with --trace)

C:\Users\tthomas2\SourceTree\ruby-prof>

Unable to link with a dependency gmp from what I understand? Something that needs to be installed separately as a requirement for this project?

I tried on another machine with 2.5 and got the same error.

Then I tried with 2.7 - just to make sure I have a working build system, but then I got different error:

C:\Users\tthomas2\SourceTree\ruby-prof>rake compile
mkdir -p lib/2.7
mkdir -p tmp/x64-mingw32/ruby_prof/2.7.2
cd tmp/x64-mingw32/ruby_prof/2.7.2
C:/Ruby27-x64/bin/ruby.exe -I. ../../../../ext/ruby_prof/extconf.rb
creating Makefile
cd -
cd tmp/x64-mingw32/ruby_prof/2.7.2
C:\RubyDevKit\bin/make.exe
generating ruby_prof-x64-mingw32.def
compiling ../../../../ext/ruby_prof/rp_aggregate_call_tree.c
x86_64-w64-mingw32-gcc.exe: error: unrecognized command line option '-fstack-protector-strong'
make: *** [rp_aggregate_call_tree.o] Error 1
rake aborted!
Command failed with status (2): [C:\RubyDevKit\bin/make.exe...]

Tasks: TOP => compile => compile:x64-mingw32 => compile:ruby_prof:x64-mingw32 => copy:ruby_prof:x64-mingw32:2.7.2 => tmp/x64-mingw32/ruby_prof/2.7.2/ruby_prof.so
(See full trace by running task with --trace)

C:\Users\tthomas2\SourceTree\ruby-prof>

I'm used to bulding Ruby C extensions directly in Visual Studio, but not via rake/mingw. Any pointers to what I might be missing?

Sorry, by build I mean build on install. So like this:

gem install --platform ruby ruby-prof

That will tell Ruby Gems to download the source code and not the prebuilt binaries.

The error you are seeing is caused by missing libgmp. But that is not a requirement of ruby-prof nor ruby 2.7 (I just checked the ruby-prof binaries I built). So I have no idea where that is coming from, I doubt devkit would have added that.

But if you don't want to spend time figuring that out, then you can just install it and avoid the problem:

pacman -S mingw-w64-x86_64-gmp

And this bug is:

x86_64-w64-mingw32-gcc.exe: error: unrecognized command line option '-fstack-protector-strong'

Ruby will use the parameters it was built with when generating makefiles via mkmf. I vaguely remember seeing that one...but I don't remember what I did to resolve it (I always build my own version of Ruby so I probably mucked around with some makefile).

Interesting. I have to look up what --platform ruby means in this context.

When I do try that I however get a dependency error:

C:\RubyDevKit>ruby -v
ruby 2.5.7p206 (2019-10-01 revision 67816) [x64-mingw32]

C:\RubyDevKit>gem install --platform ruby ruby-prof
ERROR:  While executing gem ... (Gem::UnsatisfiableDependencyError)
    Unable to resolve dependency: No match for 'psych (= 3.1.0)' on this platform. Found: x64-mingw32

I do have psych installed:

C:\RubyDevKit>gem list psych

*** LOCAL GEMS ***

psych (3.1.0 x64-mingw32, default: 3.0.2)

However, that is x64-mingw32 platform, so I tried to install psych the same way,

C:\RubyDevKit>gem install --platform ruby psych
ERROR:  While executing gem ... (Gem::UnsatisfiableDependencyError)
    Unable to resolve dependency: No match for 'psych (= 3.1.0)' on this platform. Found: x64-mingw32

I'll dig further. At least I now know how you do it - I'll follow that.

I think I got it working now, thanks to this thread explaining similar issues: eventmachine/eventmachine#896 (comment)

Seems like the already installed x64-mingw32 version of psych causes problems when using --platform ruby to install another gem.

Not sure what impact that might have on other gems on my system, but upon uninstalling I got only got a warning about an old rubycop version (which is obsolete anyway).

C:\RubyDevKit>gem uninstall psych

You have requested to uninstall the gem:
        psych-3.1.0-x64-mingw32

rubocop-0.67.2 depends on psych (>= 3.1.0)
If you remove this gem, these dependencies will not be met.

Huh... same weirdness with ruby-prof. Since I had previously tried to install without --platform ruby it would load properly. gem list displayed one version. gem uninstall displayed two variants - and even if I picked only the mingw variant both disappeared after uninstalling.

C:\RubyDevKit>irb
irb(main):001:0> require 'ruby-prof'
Traceback (most recent call last):
        8: from C:/Ruby25-x64/bin/irb.cmd:19:in `<main>'
        7: from (irb):1
        6: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require'
        5: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
        4: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require'
        3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:5:in `<top (required)>'
        2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:9:in `rescue in <top (required)>'
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/lib/ruby-prof.rb:9:in `require_relative'
LoadError (cannot load such file -- C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ruby-prof-1.4.3-x64-mingw32/ext/ruby_prof/ruby_prof.so)
irb(main):002:0> exit

C:\RubyDevKit>gem list ruby-prof

*** LOCAL GEMS ***

ruby-prof (1.4.3 ruby x64-mingw32)

C:\RubyDevKit>gem uninstall ruby-prof

Select gem to uninstall:
 1. ruby-prof-1.4.3
 2. ruby-prof-1.4.3-x64-mingw32
 3. All versions
> 2
Remove executables:
        ruby-prof, ruby-prof-check-trace

in addition to the gem? [Yn]  y
Removing ruby-prof
Removing ruby-prof-check-trace
Successfully uninstalled ruby-prof-1.4.3-x64-mingw32
Remove executables:
        ruby-prof, ruby-prof-check-trace

in addition to the gem? [Yn]  y
Removing ruby-prof
Removing ruby-prof-check-trace
Successfully uninstalled ruby-prof-1.4.3

C:\RubyDevKit>gem uninstall ruby-prof
Gem 'ruby-prof' is not installed

However, after ruby-prof had been completely uninstalled I then installed it again and now it works:

C:\RubyDevKit>gem install ruby-prof --platform ruby
Fetching ruby-prof-1.4.3.gem
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed ruby-prof-1.4.3
Parsing documentation for ruby-prof-1.4.3
Installing ri documentation for ruby-prof-1.4.3
Done installing documentation for ruby-prof after 1 seconds
1 gem installed

C:\RubyDevKit>irb
irb(main):001:0> require 'ruby-prof'
=> true
irb(main):002:0> exit

C:\RubyDevKit>

(Leaving my experience here in case someone else should wander into similar issues. The link I mentioned earlier here certainly helped me resolve my problems with this.)

(And I bet I'll be running into this again at some later point when I'll have forgotten everything about this. Hello future me! 👋)

Well, I got it all working now. 1.4.3 on Ruby 2.5 on Windows and macOS.

Thank you for your assistance, I really appreciate it.

(Reason I still tinker with 2.5 is that we embed Ruby into our application for people to write extensions for it. So we got a bit more drag in terms of moving on from older versions as this is application installed on user's machines. This in turn force extension developers to account for multiple Ruby versions as users might be using older versions of the software. The version that used 2.5 is two years old, but there's enough users there for extensions developers to ignore. Some of our extension developers aren't even on the latest version of the software.)

Great - glad its working.

FYI, that issue with gem uninstall actually removing all gems, versus the one you picked, was a bug for a year or two but has been fixed. Maybe you can upgrade your version of Ruby gems to avoid it, but I'm not sure how backwards compatible it is.

Ah, I thought this was related to having two platform variations of the same gem. I've uninstalled individual versions before which seemed to had worked fine. But I'll make sure to upgrade regardless, worth doing. gem -v gave me 3.0.3. I just did a gem update --system and now it says 3.2.15.