On Windows, you might face an error installing SassC for use with Rails or with Jekyll, especially if you are using JRuby. Resolving this issue requires having a C/C++ compiler installed on your Windows system and on your path.
Background / Problem
My blog is built using Jekyll and has always used CRuby. I wanted to try to see how it works if I set it up for JRuby (especially as there is an issue filed for slow performance), so I did the usual
jgem install jekyll to get the gem installed. Half-way through, it crashed out with this error.
Building native extensions. This could take a while... ERROR: Error installing jekyll: ERROR: Failed to build gem native extension. current directory: C:/jruby-22.214.171.124/lib/ruby/gems/shared/gems/sassc-2.4.0/ext C:/jruby-126.96.36.199/bin/jruby.exe -I C:/jruby-188.8.131.52/lib/ruby/stdlib -r ./siteconf20210609-16440-h3c2ly.rb extconf.rb creating Makefile current directory: C:/jruby-184.108.40.206/lib/ruby/gems/shared/gems/sassc-2.4.0/ext make "DESTDIR=" clean MAKE Version 5.43 Copyright (c) 1987, 2019 Embarcadero Technologies, Inc. Fatal: 'clean-so' does not exist - don't know how to make it current directory: C:/jruby-220.127.116.11/lib/ruby/gems/shared/gems/sassc-2.4.0/ext make "DESTDIR=" MAKE Version 5.43 Copyright (c) 1987, 2019 Embarcadero Technologies, Inc. Fatal: 'ast.o' does not exist - don't know how to make it make failed, exit code 1 Gem files will remain installed in C:/jruby-18.104.22.168/lib/ruby/gems/shared/gems/sassc-2.4.0 for inspection. Results logged to C:/jruby-22.214.171.124/lib/ruby/gems/shared/extensions/universal-java-1.8/2.5.0/sassc-2.4.0/gem_make.out
I remembered that I had read that SassC which failed can be installed and loaded under JRuby since it uses FFI. So, I was surprised. However, I realised the culprit when reading the error message more carefully:
MAKE Version 5.43 Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.
This was a
make on the path that did not know how to deal with the Makefile from the Ruby native extension. A different compiler toolchain should be invoked!
Let’s fix it!
For successfully installing these kinds of gems (for JRuby or Ruby on Windows), you need two main things:
- A C/C++ compiler and toolchain (including make) that can compile the native code
- This toolchain needs to be on the path so that when you do
makeduring the gem installation, it finds it
For Ruby developers on Windows, the easiest thing to do is the following:
- Install a modern Ruby, e.g. Ruby 2.6/ 2.7/ 3.0 together with the DevKit (which installs the compilers, etc.)
- You might want to use pik so that you can switch between different Ruby versions
- When installing a native gem, ensure that the DevKit is on your path
When using CRuby on Windows, this will probably happen automatically. It will change the path to bump up the DevKit directories. When using JRuby, especially with pik, it won’t do so. You might find that the installation fails because it cannot find the compiler or finds something else on the path first.
The solution for that is to
enable the DevKit. This can be done by doing the following on your command line (I’m assuming Ruby 2.6 since that is installed for me, you’ll need to adjust the path for your case):
When I do this I get:
$ c:\Ruby26-x64\ridk_use\ridk.cmd enable $ set "RI_DEVKIT=C:\Ruby26-x64\msys64" $ set "MSYSTEM=MINGW64" $ set "PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig" $ set "ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal" $ set "MANPATH=/mingw64/share/man" $ set "MINGW_PACKAGE_PREFIX=mingw-w64-x86_64" $ set "LANG=en_GB.UTF-8"
With all this done, when I rerun the installation, I happily get:
Building native extensions. This could take a while... Successfully installed sassc-2.4.0
If you see a similar error even when using CRuby, the fix is the same.
Note! Using SassC
I’m still following this up in this issue but it seems like you will need to keep DevKit on the path when you want to use the SassC gem from JRuby.
When I started jirb and did require sassc it fails with an error:
16: from org/jruby/RubyKernel.java:1189:in `catch' 15: from org/jruby/RubyKernel.java:1189:in `catch' 14: from org/jruby/RubyKernel.java:1442:in `loop' 13: from org/jruby/RubyKernel.java:1048:in `eval' 12: from (irb):1:in `evaluate' 11: from C:/jruby-126.96.36.199/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:158:in `require' 10: from org/jruby/RubyKernel.java:974:in `require' 9: from C:/jruby-188.8.131.52/lib/ruby/gems/shared/gems/sassc-2.4.0/lib/sassc.rb:31:in `<main>' 8: from org/jruby/RubyKernel.java:1002:in `require_relative' 7: from org/jruby/RubyKernel.java:974:in `require' 6: from C:/jruby-184.108.40.206/lib/ruby/gems/shared/gems/sassc-2.4.0/lib/sassc/native.rb:5:in `<main>' 5: from C:/jruby-220.127.116.11/lib/ruby/gems/shared/gems/sassc-2.4.0/lib/sassc/native.rb:6:in `<module:SassC>' 4: from C:/jruby-18.104.22.168/lib/ruby/gems/shared/gems/sassc-2.4.0/lib/sassc/native.rb:13:in `<module:Native>' 3: from C:/jruby-22.214.171.124/lib/ruby/stdlib/ffi/library.rb:84:in `ffi_lib' 2: from org/jruby/RubyArray.java:2588:in `map' 1: from C:/jruby-126.96.36.199/lib/ruby/stdlib/ffi/library.rb:114:in `block in ffi_lib' Could not open library 'C:/jruby-188.8.131.52/lib/ruby/gems/shared/gems/sassc-2.4.0/ext/libsass.dll' : The operation completed successfully.
After the installation steps above, you can check that the DLL file exists at
C:/jruby-184.108.40.206/lib/ruby/gems/shared/gems/sassc-2.4.0/ext/libsass.dll and so, that’s not the problem.
However, I found that it works if the DevKit is still on the path. So, when I have this as my path, I have no problems:
If I find out more, I will update this post. But till then, assume that you need to have DevKit on the path for running it also. This issue on Sassc-ruby resolves the problem and once it’s rolled out, it should work fine.
I wrote this up because I had run into this earlier and had forgotten what I had done. so I wanted to be able to remember how to do it the next time. Of course, if it helps someone, that’s great! If you have some comments, please add below so that I can reflect changes here. If you are setting up Ruby on Windows, take a look at Installing JRuby on Windows and Installing Ruby 3.0 on Windows both on this site itself.