Building CompassApp (jruby app) executable from source on Windows - 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

Related

Can a ruby gem/module be added just like a java jar file?

I use Eclispse Kepler with DLTK plugin for ruby. I am unable to "require" nokogiri module because it cannot be found by eclipse. I tried some gem install command from some website and that did not help. Now, I don't want to use commandline until I first master Ruby programming.
I learned that I can add java jars to my project by creating a lib folder, copying jars to that folder and then adding them all to the build path. So easy, right ?
Can I do the same thing for ruby gems and modules ? Ideally, I'd like to use only the IDE for this instead of using commandline and complext install scripts.
Please help.
If this gem already installed with all dependencies, then you can add it with simple require command:
require "/path_to_gems/gem_name/lib/gem_name"
In my case the command is:
require '/Users/yukke/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri'
Otherwise you can try to require rubygems first:
require "rubygems"
require "gem-name"
I would suggest maybe using a different IDE with better Ruby support, such as Aptana, which is Eclipse-based but has a lot of additional addons to support Ruby development. You can install Ruby gems in it on the start page, or through the integrated terminal.
If you run the command gem which bundler you will see the folder gems are installed on your system.
You can copy executables there but it's highly recommended you use gem install on the command line.
I have find the answer to this question. I not sure if this is the best way to do it, but it works for me. Pro developers, can you please review this answer ? So, for now let me give quick guide for this.
1 - Install Eclipse DLTK plugin for Ruby as suggested here - Preferred Ruby plugin for Eclipse?
See the answer with photo, by James.
2 - Next, lets pick a random gem such as nokogiri and download it from rubygems.org. The file name of the Gem tells you which OS its meant for. I use windows 7 64bits. So, I take version with x64-mingw32. Here is a sample list of downloads:
1.6.4.1 November 7, 2014 java (2.37 MB)
1.6.4.1 November 7, 2014 x64-mingw32 (2.86 MB)
1.6.4.1 November 7, 2014 (8.81 MB)
1.6.4.1 November 7, 2014 x86-mingw32 (3.91 MB)
1.6.4 November 5, 2014 java (2.37 MB)
Show all versions (271 total)
3 - AFAIK, eclipse cannot use the gem file as is. You need to unpack it first. Lets say you kept the gem file in c:\RubyGems\extras, and you want to unpack it there itself.
open windows cmd > cd into the above directory > gem unpack nokogiri-1.6.4.1-x64-mingw32.gem > press enter !!!
Now, your gem will be unpacked into a folder nokogiri-1.6.4.1-x64-mingw32.
4 - Locate the nokogiri.rb file inside the unpacked folder. Its in the lib folder.
Copy the full path of this folder - c:\RubyGems\extras\nokogiri-1.6.4.1-x64-mingw32\lib. We need this for eclipse.
5 - Eclipse > create new ruby project > right click project > build path > configure build path > libraries tab > add external source folder > enter the path from step 4 > Ok > ok. You can now use the gem in your project.
6 - Testing if the steps work. Use the code in your project !
require 'nokogiri'
puts "Chenqui ! It is work!!!"
If the message prints without error, then you are a success ! To see the error you get when the required modules can't be found, add something like this require 'restclient'.

Moving Sinatra from Webrick to a different server on windows - thin installed but can't load eventmachine

I'm building a simple web app on Sinatra that I can deploy like a gem to artifactory; to start with I'm getting everything setup.
Here's what I've done:
I've got the the gemspec done so I can deploy like a gem
I've got sinatra modular set up with a basic 'hello world' page
I've got Rspec setup for testing (hello world test passes)
I've got rake tasks to make things easier (booting up sinatra, building the gem, running tests, etc)
Now I need to move Sinatra from Webrick to somthing a bit more robust and that's this is where I'm hitting a wall.
I've tried Unicorn,thin and Puma but they all won't install and I don't know what to do.
They all fail at Building Native extensions, I don't know what to do.
I'm using windows 8.1 (i'd rather be doing this on ubuntu but the company uses windows and to be honest I like a challenge) ruby 2.1 and I have devkit installed (and it's working now, wouldn't last night).
From what I've read Unicorn won't work on windows so the best bet is to go with thin but that fails with: extconf.rb
checking for main() in -lc... *** extconf.rb failed ***
It mentions that I need the devkit installed (it is the first line is Temporarily enhancing PATH to include DevKit...)
Despite this it fails, I tried doing what I found in this but that didn't help ( Installing event machine didn't do anything).
I'm at a loss of what to do next.
EDIT:
Whilst I've solved the problem of getting Thin to install it now has a differant error
IT can't load eventmachine.
EDIT:
It all comes down to the fact that the Devkit wasn't being recognised or it didn't install properly or something. I wonder why.
I've tried Unicorn,thin and Puma but they all won't install and I don't know what to do. They all fail at Building Native extensions, I don't know what to do.
The reason these are failing is that many ruby gems use native C extensions which expect to be compiled and installed on a linux or unix environment.
Doing any sort of Ruby development work on a Windows machine is an exercise in sadomasochism.
I strongly recommend you install VirtualBox, download an Ubuntu or similar linux virtual machine image, boot it, configure it, and use it as your development webserver. You can continue to edit your code in windows, but you will be running it in a sane environment.
Ultimately, you may have to learn some new skills, but you will save yourself an enormous amount of frustration by moving off windows as your development platform.
I managed to get thin installed but it wasn't easy
I wiped every bit of ruby from my machine, including all references in the registry, got rid of pik as well.
I then followed these steps (that I worked out along with an answer from another question) and it now works
install rubyinstaller 2.1.3
install devkit
gem install thin --platform=[win64]
notepad C:\Ruby21-x64\lib\ruby\gems\2.1.0\gems\eventmachine-1.0.3\ext\project.h #append line 97 with //
cd C:\Ruby21-x64\lib\ruby\gems\2.1.0\gems\eventmachine-1.0.3
gem build eventmachine.gemspec
move eventmachine-1.0.3.gem up one directory
cd ..
gem install eventmachine-1.0.3.gem
del the gemfile
cd
gem install thin --platform=[win64]
A bit of a job BUT it worked,
The answer in question isthis one.
specifically
2) edited the file:
c:\Ruby21-x64\lib\ruby\gems\2.0.0\gems\eventmachine-1.0.3\ext\project.h
and commented the line 97
//typedef int pid_t; for a more robust correction, checkout the
solution here
https://github.com/eventmachine/eventmachine/pull/450/files
3) then, i've opened command prompt, and went to the gem folder
c:\Ruby21-x64\lib\ruby\gems\2.0.0\gems\eventmachine-1.0.3 and run:
gem build eventmachine.gemspec
In the end, after hammering my head against a wall, on a suggestion I installed chef-client and using the embedded ruby allowed it to work, that said it only uses ruby 1.9.3 but it works so for now it will have to do.

Integrate Jekyll to run into WebStorm on Windows

Is it possible to run Jekyll as External Tool into WebStorm? (same for RubyMine, IntelliJ IDEA, ...)
The most obvious thing is to run the jekyll.bat file:
...but this doesn't work.
I haven't found any solution so after some trial+error I discover this working configuration:
In this example I am using: RubyInstaller + gem install jekyll.
If you prefer using straight Ruby+DevKit then Program and Parameters paths must be changed according.

how do I repackage a ruby gem with native extensions

I need to install a number of ruby gems (all with C extensions) on a production server which does not have any dev tools installed. I'd like to build gems on a dev server first and then repackage and install resulting native gems on production server.
However, there seems to be no standard methods to package gem with native extensions for redistribution. I am aware of rake-compiler, but none of the gems in concern works with it out of the box. Specifically, I am working with json-1.7.5, rb-inotify-0.8.8 and ffi-1.2.1 gems.
Any pointers on how to do this task or documentations on the subject are appreciated.
Using Jordan Sissel's fpm you can take various input archives (including gems) and compile and package them as (among others) DEBs or RPMs.
An example to compile the json gem into a deb package follows:
cd /tmp
fpm -s gem -t deb json
This will download the latest version of the json gem and create a rubygem-json-1.5.7-1.amd64.deb archive in /tmp which you can install on your server. Note that the compile box and the final server need to be rather identical. At least the distribution and bitness, the ruby version and its file layout, and the available loadable libraries should be the same. Basically all the constraints your upstream distribution deals with...
That said, in the long term I found it much easier to just install a compiler on the target servers and use rbenv or rvm on the server. For most small and mid-size installations, it's much easier to handle as you don't need to pre-compile and ship everything to your servers.
Hi You could do it with: gem-compiler
You need to tell RubyGems the filename of the gem you want to compile:
$ gem compile yajl-ruby-1.1.0.gem
The above command will unpack, compile any existing extensions found and repackage everything as a binary gem:
Unpacking gem: 'yajl-ruby-1.1.0' in temporary directory...
Building native extensions. This could take a while...
Successfully built RubyGem
Name: yajl-ruby
Version: 1.1.0
File: yajl-ruby-1.1.0-x86-mingw32.gem
It have well written documentations here:
https://github.com/luislavena/gem-compiler.
I am using it as well as we have own gem server. Just have to be careful with distribution because some gems compiled on wheezy won't work on jessie and so on.
You're going to have to build them on a system that's almost exactly the same for this to work. If you're linking against shared libraries that are in a different location or have slightly different versions it may not work at all. Sometimes you have some slack, where it will work with a range of versions, but this cannot be assured.
There's no way to package with native extensions for this very reason, there's just too many possible combinations of libraries.
You'll also need to make sure you're using the same architecture, including 32-bit or 64-bit as required.
Sometimes you'll get lucky and there's a package for your OS that can install these for you, but these won't work with rvm or rbenv.

Self contained ruby "binary"?

[Ruby Noob]
I have a small (command line) utility written in Ruby, which requires a few gems. Is there a way to create a self contained bundle of my program such that I can run it on another machine that has Ruby installed (but not necessarily the gems)?
FWIW, the target machine runs Linux/Ubuntu.
You can use the gem bundle http://gembundler.com/
With bundle you create a Gemfile in your project root - a text that contains all your dependencies, very similar to Maven concept
In order to fetch all your dependencies simply tun
bundle install
The only issue is that you need to have the bundle gem itself installed, so you are back with the chicken-or-Egg problem :-)
I've used:
http://www.erikveen.dds.nl/rubyscript2exe/
before, but it was a while ago. Seemed to work okay for simple programs.
You can download it here:
http://rubyforge.org/projects/rubyscript2exe/

Resources