Ruby Native Extension - Manual Compilation - ruby

I created new Ruby C Extension and hosted it in GitHub,
and I install via Bundler (gem 'my_cool_gem', git: '..').
But when I run the application (rails s) I get an error -
cannot load such file -- my_cool_gem/my_cool_gem
My current solution, is to manually compile it:
$ cd $(bundle show my_cool_gem)
$ rm ext/my_cool_gem/*.o
$ rake compile
only then, my app works.
Any ideas?

You probably misconfigured your extconf.rb.
Make sure you have create_makefile line to look like:
create_makefile(File.join(extension_name, extension_name))

Related

Struggling to run my ruby cli app

I built a small Cli app in ruby (first ever ruby app), but I'm not able to actually run it.
I started the project off with bundle gem. I have been testing it inside my apps folder by running bundle exec bin/konstruct and everything works fine.
I want to install it locally and test it before I submit it, and so I ran bundle exec rake install after updating all of the info in my gemspec file. It gave successfull output:
konstruct 0.1.1 built to pkg/konstruct-0.1.1.gem.
konstruct (0.1.1) installed.
But when I run the app by entering $ konstruct it gives me an Could not locate Gemfile or .bundle/ directory error, unless I run it from within the root folder of the app.
I have tried to Google but I can't pin the results down to the same issue as I'm having. I've been having this problem even in development (How can I test my Ruby CLI app while still in development?)
I do have a Gemfile and it contains:
source 'https://rubygems.org'
# Specify your gem's dependencies in konstruct.gemspec
gemspec
I don't have a .bundle/ folder though. I'm not sure where/how that folder should be generated. I have run bundle and bundle install many times now.
I have a konstruct.gemspec file which contains: https://github.com/konstruct/konstruct.cli/blob/master/konstruct.gemspec
Most of that file is as it was generated. I just filled it in where I could.
I'm sorry if this is a stupid question, but I am super stuck.
You have the following line in your gemspec:
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
I believe that means if you move your executable file into an exe directory instead of a bin directory, it will work as you expect.
http://guides.rubygems.org/specification-reference/#executables
It turns out I am a first class idiot. Some time ago I added Konstruct in my .path file, which obviously was now overriding the proper konstruct command. Back then what I did din't work, so I just forgot about it.
So the answer to this question: It's not broken. OP is an idiot. :-/

Rails console not working on server

When I run bundle exec rails console production or rails console production via SSH on the server in the Current folder of the Capistrano deploy I get:
Usage:
rails new APP_PATH [options]
Options:
(...)
with an explanation to start a new app. Locally it works. Why can't I start a console remotely?
I'm assuming that you updated to rails 4 from version 3 and your app can't find the executables in the bin directory. Run this to see your rails version:
$ rails -v
If your rails version is 4 or above, try running this:
$ rake rails:update:bin
Source: Rails 4 Release Notes
6.1 Notable changes
Your app's executables now live in the bin/ dir. Run rake rails:update:bin to get bin/bundle, bin/rails, and bin/rake.
I am using capistrano to deploy, including the capistrano/bundler gem. Since the ./bin directory is version controlled in Rails 4, we need to prevent Capistrano from linking it on deployments by removing bin from set :linked_dirs.
Now in order to prevent bundler from overwriting the version controlled binstubs, we can add the line set :bundle_binstubs, nil which will prevent capistrano-bundler from setting the --binstubs option when running bundle install.
My config/deploy.rb file now has these lines:
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :bundle_binstubs, nil
Note the lack of the bin directory in the :linked_dirs line.
I have the same problem, and turns out when you deploy through cap shared/bin is symlink to current/bin.
Here's what works for me:
rm current/bin
mkdir current/bin
rake rails:update:bin
This should help, but it is somewhat a temporary solution, I'm trying to find out how to make cap not auto symlink-ing current/bin.
In case of Rails 5.2
I had to remove bin directory by running below command in project root directory.
rm -rf bin
and then I ran another command in project root directory:
rake app:update:bin
It will show you output like below:
create bin
create bin/bundle
create bin/rails
create bin/rake
create bin/setup
create bin/update
create bin/yarn
That's it.
It's been a little while since this was answered.
In my case I needed to run:
rake app:update:bin
Note- app rather than rails.
I was missing the bin directory all-together in my Rails 5.1 App
I faced this issue on my production server when I updated my application from Rails 5.2 to 6.0.4. Simply follow these steps:
cd to_your_project_dir
rm -r bin
rake app:update:bin

Building CompassApp (jruby app) executable from source on Windows

I would like to build the executable of CompassApp, a GUI application that lets webdesigners compile stylesheets by using SASS and Compass without using the command line.
The source can be found on GitHub here: https://github.com/handlino/CompassApp.
CompassApp is a an application developed in Jruby.
From the GitHub webpage of the project:
If you want to build your own copy, you will need JRuby and rawr
I am using Windows 7 as operating system for my webdesign projects. I never built a jruby app from source. It seems on linux it's easier to install the required things, anyway i'm using Windows now.
First i cloned the GitHub repository.
Then i installed jruby.
Now i should install rawr (https://github.com/rawr/rawr)
It seems that rawr also requires javac and rake
I saw that rawr and rake are 2 ruby gems.
So how do i install those 2 ruby gems for jruby on Windows?
And how do i build CompassApp from source after i have everything i need?
I would need a step by step guide from the install of the requirements
to the build of the application.
(i never used jruby in the past).
If someone of you develops apps in jruby i think that can help me easily.
I thank you in advance.
#Fabio Hi, we made Compass.app and Fire.app :-)
It is easy to build Compass.app on OS X or Linux. We have a (almost) step by step guide about building Fire.app on the GitHub wiki and it can be applied to Compass.app too: https://github.com/handlino/FireApp/wiki
We have never tried to build it on Windows, and do not think it can be done easily.
I'm trying to do a similar thing, but in my case only package the gems in a self-contained executable jar. the docs are not very descriptive and some are outdated.
I tried rawr but managed to get further with warbler
here's what I did: I created a folder named jrcompass and installed compass into it:
c:\test\jrcompass>%JRUBY%\jruby -S gem install compass -i .
I installed warbler and then ran the warble command in that folder:
C:\test\jrcompass>c:\apps\jruby\bin\jruby -S warble
that created a ~20MB jar file named jrcompass.jar which is farther than I got with rawr.
now I'm trying to execute the jar with:
C:\test\jrcompass>java -jar jrcompass.jar
and I get the following error below. I hope that this will help you make progress. please let me know if you figure it out.
Gem::LoadError: Could not find compass (>= 0) amongst [rake-0.9.2.2]
to_specs at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/dependency.rb:247
to_spec at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/dependency.rb:256
gem at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems.rb:1231
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/jrcompass/bin/compass:22
load at org/jruby/RubyKernel.java:1046
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/META-INF/main.rb:1
require at org/jruby/RubyKernel.java:1027
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/META-INF/main.rb:1
(root) at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1

How to build and run a Ruby command-line tool found on github?

Hi cloned a simple app ( https://github.com/cfx/twix) on github that allows me to send Twitter messages from the console, but I'm not sure how to run it.
I now have a folder in my users/name director called Twix. Inside twix, I have these folders created by the app.
README Rakefile bin lib test
The readme doesn't provide a lot of instruction to get things started. It just tells you what to do after the program's running (see below).
Questions: What command do I use to get this started? What folder do I need to be in?
The README
Twix 0.0.1
Simple twitter client for console
Keys:
q - quit
t - write new message
If you want to post your twit, finish you message with !SEND
If you want abort and back to your feed, finish your message with !EXIT
new features soon
This program is packaged as a gem. The following command will install the gem (run it in the Twix directory):
rake package && gem install pkg/twix-0.0.1.gem
You can now run the program from anywhere with the twix command.
Edit
The first thing I saw in the repository was the Rakefile, meaning there were some rake tasks defined. When you find yourself in this case, running rake -T is your best bet as it will show you the rake tasks available. Its output was the following:
(in /home/benoit/code/clones/twix)
rake clobber_package # Remove package products
rake gem # Build the gem file twix-0.0.1.gem
rake package # Build all the packages
rake repackage # Force a rebuild of the package files
I picked the command that would be the most likely to build the gem: the package one. I guess the gem task would have worked as well.
Running rake package gave me the following output:
(in /home/benoit/code/clones/twix)
mkdir -p pkg
WARNING: no homepage specified
Successfully built RubyGem
Name: twix
Version: 0.0.1
File: twix-0.0.1.gem
mv twix-0.0.1.gem pkg/twix-0.0.1.gem
All that was left was to install the pkg/twix-0.0.1.gem created by the previous command:
gem install pkg/twix-0.0.1.gem
There's another case you could have encountered: the presence of a twix.gemspec in the root directory of the application. In this case, running:
gem build twix.gemspec
would have built the gem, the installation step remains the same.
ruby ./bin/twix
or
ruby -I lib ./bin/twix

Is there any bundler *after* hook?

I would like to have ctags generate a TAGS file of all my bundled gems or all the gems under the rvm gemset directory bundler installs its gems. Ideally, a bundle install or bundle update should generate a TAGS file at the last step using a ruby script I'll provide. Afterthat emacs joy.
Is there any kind of a bundler after hook I can use?
You could look at what Tim Pope does in his Hookup project:
https://github.com/tpope/hookup
I'd imagine it wouldn't be too hard to an an extra step after the bundler run.
Personally I just have a good old Makefile in my Ruby project:
.PHONY: tags
tags:
ETAGS=ctags
rm -rf TAGS
ctags -a -e -f TAGS --tag-relative -R app lib vendor
I have a shell script I run in the morning which sets up my dev environment which also runs make tags.
According to https://github.com/bundler/bundler/blob/dd1e11d8f8e869ffab4fc68d4854b27e1f486de4/lib/bundler/source/path.rb, there is the ability to run 'post_install' hooks. It uses meta-programming to deduce the method name, and the gem is supposed to implement that method. Will try and check if this works
My approach has been two pronged:
1) Put a rake task in place that generates tags for all code in the project as well as all required gems:
desc 'Create ctags'
task :tags do
system "ctags -R --language-force=ruby app config lib `rvm gemdir`/gems"
end
2) Using the excellent "foreman" gem (which I was using anyway) to run inotifywait and fire off the rake task if a file changes:
tags: while inotifywait -q -r -e MODIFY --exclude swp$ app/ config/ lib/ ; do bundle exec rake tags; done
If you are not using foreman you can of course just run that line without the first "tags:" part manually in a shell.

Resources