technion / ruby-argon2

A Ruby gem offering bindings for Argon2 password hashing
MIT License
229 stars 30 forks source link

FFI compiler LoadError #1

Closed thomvil closed 8 years ago

thomvil commented 8 years ago

loading the gems fails

LoadError: cannot find 'argon2_wrap' library
    from /Users/me/.rvm/gems/ruby-2.2.1/gems/ffi-compiler-0.1.3/lib/ffi-compiler/loader.rb:21:in `find'
    from /Users/me/.rvm/gems/ruby-2.2.1/gems/argon2-0.1.0/lib/argon2/ffi_engine.rb:8:in `<module:Ext>'
    from /Users/me/.rvm/gems/ruby-2.2.1/gems/argon2-0.1.0/lib/argon2/ffi_engine.rb:6:in `<module:Argon2>'
    from /Users/me/.rvm/gems/ruby-2.2.1/gems/argon2-0.1.0/lib/argon2/ffi_engine.rb:4:in `<top (required)>'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Users/me/.rvm/gems/ruby-2.2.1/gems/argon2-0.1.0/lib/argon2.rb:2:in `<top (required)>'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
    from (irb):1
    from /Users/me/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'

I don't have any experience with FFI myself. Although extensions in the gemspec seems to be set up as expected?

technion commented 8 years ago

Hi Thomvil.

Thank you for reporting this error. I've been trying to investigate what may have occurred here.

As you can see from Travis, the gem currently loads and runs in the environments I've been testing with. I also ran and tested from a different machine.

$ gem install argon2
Building native extensions.  This could take a while...
Successfully installed argon2-0.1.0

Can you try running the install, and ensure you see the above? The argon2_wrap function is a component of the native extensions, and if it fails to build, you'll see what you're seeing.

Assuming you can get past that, I haven't identified any issue with running the gem.

2.2.3 :001 > require 'argon2'
 => true
2.2.3 :002 > hasher = Argon2::Password.new(t_cost: 2, m_cost: 16)
 => #<Argon2::Password:0x00559a898de838 @t_cost=2, @m_cost=16, @salt="\xF5\x8FQP\x1CG\xA5\x85\x9E(<\x83\x99D\x81\xE7", @secret=nil>
2.2.3 :003 > hasher.hash("password")
 => "$argon2i$m=65536,t=2,p=1$9Y9RUBxHpYWeKDyDmUSB5w$sXszJXDoh7PmLSqxIl6xs+4e0D2y5Hjyp+P8lsoHGMo"

What OS are you running?

technion commented 8 years ago

If the above doesn't leave any clues, can you please try building the gem extensions manually and see how we go.

$ git clone https://github.com/technion/ruby-argon2.git
Cloning into 'ruby-argon2'...
$ cd ruby-argon2
$ git submodule update --init --recursive
$ cd ext/argon2_wrap/
$ make && make test
$ cd ../../
$ bundle install
$ rake test
technion commented 8 years ago

@thomvil Since you haven't responded I'm down to guess work, but I have noted that if you happen to be on a system that does not have gcc installed (many Mac users only have clang installed) you may have noted a failure to compile in the above steps.

I've pushed version 0.1.1 as a fix for this issue and will close this ticket based as "assumed fixed", please let me know if this is not the case.

thomvil commented 8 years ago

thank you for the suggestion.

make test actually fails for me

clang -pthread -O3 -fsanitize=address -fsanitize=undefined -Wall -g ../phc-winner-argon2/src/argon2.c ../phc-winner-argon2/src/core.c ../phc-winner-argon2/src/blake2/blake2b.c ../phc-winner-argon2/src/thread.c ../phc-winner-argon2/src/encoding.c argon_wrap.c ../phc-winner-argon2/src/opt.c test.c -o tests
clang: error: unsupported argument 'undefined' to option 'fsanitize='
make: *** [test] Error 1

the compilation however completes without failure.

The compilation also completes during the gem installation process. The directory ~/.rvm/gems/ruby-2.2.1/gems/argon2-0.1.1/ext/argon2_wrap contains both libargon2_wrap.so and libargon2_wrap.so.dSYM


rake test fails for me.

/Users/me/.rvm/gems/ruby-2.2.1/gems/ffi-compiler-0.1.3/lib/ffi-compiler/loader.rb:21:in `find': cannot find 'argon2_wrap' library (LoadError)
    from /Users/me/workspace/ruby-argon2/lib/argon2/ffi_engine.rb:8:in `<module:Ext>'
    from /Users/me/workspace/ruby-argon2/lib/argon2/ffi_engine.rb:6:in `<module:Argon2>'
    from /Users/me/workspace/ruby-argon2/lib/argon2/ffi_engine.rb:4:in `<top (required)>'
    from /Users/me/workspace/ruby-argon2/lib/argon2.rb:2:in `require'
    from /Users/me/workspace/ruby-argon2/lib/argon2.rb:2:in `<top (required)>'
    from /Users/me/workspace/ruby-argon2/test/test_helper.rb:6:in `require'
    from /Users/me/workspace/ruby-argon2/test/test_helper.rb:6:in `<top (required)>'
    from /Users/me/workspace/ruby-argon2/test/api_test.rb:1:in `require'
    from /Users/me/workspace/ruby-argon2/test/api_test.rb:1:in `<top (required)>'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:15:in `require'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:15:in `block in <main>'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `select'
    from /Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:test:lib" -I"/Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0" "/Users/me/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb" "test/api_test.rb" "test/engine_test.rb" "test/error_test.rb" "test/key_test.rb" "test/low_level_test.rb" "test/rubycheck_test.rb" "test/util_test.rb" ]
/Users/me/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/Users/me/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
technion commented 8 years ago

"make test" failures only demonstrate that your compiler doesn't support the tests. I don't think that's an issue.

What is an issue is that you've confirmed the relevant file is being created, but on your system, it's just not getting found.

What OS are you running?

thomvil commented 8 years ago

osx 10.11.1

technion commented 8 years ago

@thomvil I have a suspicion https://github.com/technion/ruby-argon2/commit/b7bf0cf675f45132ab1698176064aa370e271b8e will be relevant here.

Can you pull the latest source and try the above process again? I understand OSX doesn't use the same file extensions Linux does - but I don't have an OSX machine around to test with. This recent commit changes the extension.

If that works I'll tag a new release.

thomvil commented 8 years ago

no this doesn't work

technion commented 8 years ago

@thomvil Unfortunately this seems to be documented as an issue for several gems at the moment:

http://cgarvey.ie/archive/2015/10/01/mysql-client-library-issues-on-os-x-el-capitan/ https://github.com/jordansissel/fpm/issues/1010

Not having a Mac - this is proving difficult.

thomvil commented 8 years ago

oh that's unfortunate. Thank you for identifying the problem.

technion commented 8 years ago

There is a branch here that is working on the issue: https://github.com/ffi/ffi/issues/461

technion commented 8 years ago

The Jekyll team have documented their workaround for the same issue here:

http://jekyllrb.com/docs/troubleshooting/#jekyll-amp-mac-os-x-1011

xlavoie commented 5 years ago

I had this same problem but being on Windows 10 using RubyInstaller 2.5.3-1 I could not apply the workaround above.

I managed to fix the issue by replacing line 7 in lib/argon2/ffi_engine.rb from: ffi_lib FFI::Compiler::Loader.find('argon2_wrap') to: ffi_lib FFI::Compiler::Loader.find('libargon2_wrap')

Hope this can help someone out!