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

Gem v0.1.0 Does Not Load #20

Closed
PatrickTulskie opened this issue Jun 14, 2016 · 28 comments
Closed

Gem v0.1.0 Does Not Load #20

PatrickTulskie opened this issue Jun 14, 2016 · 28 comments

Comments

@PatrickTulskie
Copy link

Getting a weird error loading faster_path in an existing Rails application. Here's the back trace:

(trunk*) rails console
/Users/patrick/.rvm/gems/ruby-2.2.3/gems/ffi-1.9.10/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library '/Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/target/release/libfaster_path.dylib': dlopen(/Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/target/release/libfaster_path.dylib, 5): image not found (LoadError)
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `map'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `ffi_lib'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/lib/faster_path.rb:36:in `<module:Rust>'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/lib/faster_path.rb:34:in `<module:FasterPath>'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/lib/faster_path.rb:5:in `<top (required)>'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /Users/patrick/rails/test_app/config/application.rb:10:in `<top (required)>'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:82:in `require'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:82:in `preload'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:140:in `serve'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:128:in `block in run'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:122:in `loop'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application.rb:122:in `run'
    from /Users/patrick/.rvm/gems/ruby-2.2.3/gems/spring-1.1.2/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/patrick/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/patrick/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

I suspect it's an issue with the ffi version but I'm assuming the gemspec should address that rather than me mucking around with that in the application's Gemfile.

@danielpclark
Copy link
Owner

Yes. I thought this issue was addressed in #18 but it seems there's still an issue on Mac OS.

@danielpclark
Copy link
Owner

Do you have Rust installed?

@PatrickTulskie
Copy link
Author

Sure do.

~:bin (master) brew install rust
Warning: rust-1.9.0 already installed
~:bin (master) brew link rust
Warning: Already linked: /usr/local/Cellar/rust/1.9.0
~:bin (master) which rustc
/usr/local/bin/rustc

@danielpclark
Copy link
Owner

danielpclark commented Jun 14, 2016

Can you go to /Users/patrick/.rvm/gems/ruby-2.2.3/gems/faster_path-0.1.0/ and run cargo build --release and tell me what's in the target/release directory? Also see if it works after you do this.

@PatrickTulskie
Copy link
Author

PatrickTulskie commented Jun 14, 2016

That got the app to boot. Here's what it looks like after running cargo build --release

~:faster_path-0.1.0 tree target/release
target/release
├── build
├── deps
│   └── liblibc-38919d24e617a235.rlib
├── examples
├── libfaster_path.dylib
└── native

@danielpclark
Copy link
Owner

danielpclark commented Jun 14, 2016

Alright. I'm guessing Mac needs the libc dylib file. That's currently being deleted in the clean-up rake script.

@danielpclark
Copy link
Owner

Change line # 20 in the Rakefile to !f[/\.(?:so|dll|dylib|deps)\z/] and run rake clean_src. Tell me if it still loads for you after that.

@danielpclark
Copy link
Owner

I'm going to take a chance and merge that update.

@danielpclark
Copy link
Owner

Gem 0.1.1 has this update.

@PatrickTulskie
Copy link
Author

I just wiped out 0.1.0 and installed 0.1.1 and it has the same issue. I don't actually see a target directory at all. Also when I try just installing it without bundler, it goes into the building native extensions thing and then immediately says the gem is installed. I'm assuming it's just not running the cargo build process as part of the install for some reason.

@danielpclark
Copy link
Owner

danielpclark commented Jun 15, 2016

I have an idea. Perhaps the relative path for the extconf.rb is different in Mac. I'll try changing Dir.chdir('../../') to one that find the path relative to __FILE__

@danielpclark
Copy link
Owner

Alright release 0.1.2 runs the rake commands relative to the __FILE__ location.

@harmdewit
Copy link

0.1.2. and running cargo build --release fixed it for me

@danielpclark
Copy link
Owner

@harmdewit Thanks!

My hope is to get it where you don't have to type cargo build --release. I have a rake task for that. I might just need to remove my rake task that supposedly "tidies" up the compiled directory. On Linux and Windows it works when using bundler.

@PatrickTulskie
Copy link
Author

I just tried 0.1.3 and the issue persists. Still doesn't want to compile when the gem installs. What is the best way to run the extconf.rb file with some debugging?

@danielpclark
Copy link
Owner

danielpclark commented Jun 15, 2016

I can't seem to find it now, but there is a bundle method for invoking bundle commands in a clean context (no other bundle stuff loaded). I've looked for it but can't find it. Another way is to add a dummy rails directory to the test directory.

In the mean time you can do your modifications and test it manually by changing the version number and running gem bundle faster_path.gemspec and then doing a local install with gem install faster_path-#.#.#.gem

@danielpclark
Copy link
Owner

#33 may have fixed this. Please download from master, build and install the local gem and let me know.

@lukesutton
Copy link

I've just checked out master:

  • bundle
  • rake build_lib
  • rake build
  • rake install:local

I'm then able to open an IRB session in a new window, require FasterPath and call it's methods. So it looks as if it's working! That said, I'm going to keep poking about.

I have Rust nightly installed, Ruby 2.1.5p273 on OS X 10.11.5

@danielpclark
Copy link
Owner

Okay! I've published this as gem 0.1.5 . I'd like a confirmation or two on this working with a Mac in a bundle install and I'll close this issue. Thanks for your feedback!

@PatrickTulskie
Copy link
Author

Same error for me with 0.1.5. Still doesn't seem to be creating the target/release directory when doing a clean install on the Mac.

@danielpclark
Copy link
Owner

I'll have some help on this this weekend. I'm currently at the Ruby for Good event and there are a lot of Macs here.

@PatrickTulskie
Copy link
Author

Awesome. I've tried to do some debugging myself but the limiting factor seems to just be time. If I find anything meaningful I'll let you know.

@travisofthenorth
Copy link

I've had a similar issue on Circle and Heroku. Rust appears to be installed just fine:

ubuntu@box618:~$ which rustc
/usr/local/bin/rustc

And there are no errors running bundle, but as soon as faster_path is required, this error occurs:

LoadError: Could not open library '/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/faster_path-0.1.7/target/release/libfaster_path.so': /home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/faster_path-0.1.7/target/release/libfaster_path.so: cannot open shared object file: No such file or directory
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.10/lib/ffi/library.rb:133:in `block in ffi_lib'
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `map'
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `ffi_lib'
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/faster_path-0.1.7/lib/faster_path.rb:50:in `<module:Rust>'
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/faster_path-0.1.7/lib/faster_path.rb:48:in `<module:FasterPath>'
/home/ubuntu/myapp/vendor/bundle/ruby/2.3.0/gems/faster_path-0.1.7/lib/faster_path.rb:5:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.3.1/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'

Oddly, I had no issues installing/running on my Mac.

@danielpclark
Copy link
Owner

I think Bundler swallows up the error output that is designed in the Rakefile. There are some alternative ways to go about using the extconf.rb extension builder which may be explored to fix this. Apparently a Rakefile can be used instead of a Makefile. I haven't found much on this as the documentation largely focusses on C code builds. But using a Rakefile instead of calling Rake tasks from extconf.rb might be a solution.

danielpclark added a commit that referenced this issue Dec 24, 2016
danielpclark added a commit that referenced this issue Dec 24, 2016
@stereobooster
Copy link
Contributor

Getting same error. But I suppose it is due the fact that there is no rust on my system. Are you planning to produce gems with prebuilt binaries?

@danielpclark
Copy link
Owner

Yes. I'll be adding Thermite soon. I need to figure out how to build for specific architectures and then sign it with something like gpg.

@danielpclark danielpclark added this to the 0.2.0 milestone Mar 1, 2017
@danielpclark
Copy link
Owner

danielpclark commented Mar 1, 2017

This commit may resolve this issue for many 69ea7df

@danielpclark
Copy link
Owner

I've written an AssetResolution module that will build the library on require if it wasn't built during gem install. If that fails it will error out with a very clear message as to why.

Also I've added OSX testing with TravisCI and it passes. So I'm closing this issue.

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

No branches or pull requests

6 participants