Skip to content

Patches that enable Windows Ruby to install C extension gems with MinGW without MSYS2 (Devkit)

License

Notifications You must be signed in to change notification settings

ParadoxV5/ruby-mingw-make

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

When it comes to C-based extension Ruby gems on Windows, the status quo depends on the heavyweight MSYS2 to build and install them. However, Minimum GNU for Windows (MinGW), a key component of MSYS2, is sufficient for half of the jobs all on its own.

mingw-make is a set of tiny non-intrusive mods for RubyInstaller2 for Windows that solves the hurdles on the other half minimally, namely by replacing rbconfig entries of compilation commands. With the aid of the secret ruby -run capability it has unleashed, all it took was a couple of quick hacks and we have ourselves a lightweight Devkit.

Setups with MinGW and RubyInstaller’s prebuilds with these patches are ideal to keep footprints small, though experts strongly recommend WSL for a fully-fledged Ruby environment.

Compatibility

I’m glad to announce that, except for Prism for which I have sent PRs, this experiment works with gem update versions of every Default and Bundled C extension 📈.

While I have only tested this experiment with the following projects, In theory, it’s compatible with anything that doesn’t leave rbconfig+mkmf’s comfort zone, which I expect to be the majority of C-based gems. (It will indeed “take a while” when “Building native extensions”.) Please do let me know if it doesn’t meet the expectations on something not unusual.

builds

  • railties 7.1.3
    • bigdecimal 3.1.6..3.1.8
    • io-console 0.7.2
    • racc 1.7.3..1.8.0
  • steep 1.6.0
    • json 2.7.2
    • debug 1.9.2
    • rbs 3.4.4
    • strscan 3.1.0
  • nkf 0.2.0
  • prism 9bb8710

fails

  • prism ..0.29.0:
    • It must be possible to build prism without needing ruby/rake/etc. Because once prism is the single parser in TruffleRuby, JRuby or CRuby there won't be another Ruby parser around to parse such Ruby code. […]

    The main solution for the second point seems a Makefile, otherwise many of the usages would have to duplicate the logic to build prism.

    https://github.com/ruby/prism/blob/19c67fb/docs/build_system.md#requirements

  • ffi ...1.17 (Prebuilt gems are available est. 1.17.0.rc.)

not thoroughly tested

  • syslog 0.1.2: It’s UNIX-specific.
  • readline-ext 0.2.0: extconf.rb:64:in `<main>': Neither readline nor libedit was found (RuntimeError)

Setup

Requirements

  • Windows
    • Linux need MinGW not.
  • Ruby from RubyInstaller2 without DevKit (MSYS2)
    • Does it work with other Rubies? Well… maybe?
  • MinGW for the Universal C Runtime (UCRT), with the binaries folder on the PATH
    • Will it work with MSYS? Uhh… likely not.

Installation

gem install mingw-make

Use with gem

Thanks to gem’s plugins system, it’s online out of the box!

Use with rake-compiler

Slap this somewhere in the Rakefile:

begin
  require 'mingw-make'
rescue LoadError
  # ignore
end

Use manually

Prepend (so it takes precedence) the lib/mingw-make/mkmf.rb script to the Ruby $LOAD_PATH. Because RubyGems require 'rbconfig', we must explicitly apply the rbconfig replacements.

set RUBYOPT=-Ipath/to/gems/mingw-make/lib/mingw-make/ -rrbconfig-patch

You may also need to specify a fallback for the MAKE tool, e.g.:

set MAKE=mingw32-make

How to Contribute

Ackchyually – I would much prefer you don’t, but instead forward my tinkering to their corresponding upstreams. Windows users like me would love if our chérie lang doesn’t require more (WSL) or less (MSYS) a Linux Virtual Machine. (Imagine… Ruby VM in a Linux VM in a Windows VM… 🫠) After all, the WTFPL means that I’ve decided to release my knowledge to the public domain, so no need to thank me and go bring developer happiness to its next level!

About

Patches that enable Windows Ruby to install C extension gems with MinGW without MSYS2 (Devkit)

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Languages