Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active April 30, 2026 17:34
Show Gist options
  • Select an option

  • Save t-nissie/f0fdc185e963e67fbbe736306f28ef41 to your computer and use it in GitHub Desktop.

Select an option

Save t-nissie/f0fdc185e963e67fbbe736306f28ef41 to your computer and use it in GitHub Desktop.
Compile mruby on Cygwin

Compile mruby on Cygwin

Few people may compile mruby on Cygwin, but here are memos for mruby-4.0.0 and After mruby-4.0.0.

Preparation

Install gcc, ruby, gem and git via Cygwin setup. Install rake with gem install rake.

mruby-4.0.0

Use hal-posix-*.c files.

--- build_config/default.rb~    2026-04-20 17:43:06.000000000 +0900
+++ build_config/default.rb     2026-04-26 17:46:09.895058800 +0900
@@ -9,6 +9,9 @@
   # end
   # conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
   # conf.gem :core => 'mruby-eval'
+  conf.gem :core => 'hal-posix-io'
+  conf.gem :core => 'hal-posix-socket'
+  conf.gem :core => 'hal-posix-dir'
   # conf.gem :mgem => 'mruby-onig-regexp'
   # conf.gem :github => 'mattn/mruby-onig-regexp'
   # conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
tar xf mruby-4.0.0.tar.gz
cd xf mruby-4.0.0
# Apply the patch above.
SERIAL=1 rake
rake test

After mruby-4.0.0

For Cygwin, Build#effective_ports in mruby/lib/mruby/build.rb should return ['posix']. With this patch, I can rake test:run:serial.

--- a/lib/mruby/build.rb
+++ b/lib/mruby/build.rb
@@ -201,7 +201,11 @@ module MRuby
         []
       elsif ENV['OS'] == 'Windows_NT' ||
             ('A'..'Z').any? { |v| Dir.exist?("#{v}:") }
-        ['win']
+        if RUBY_PLATFORM.include?("cygwin")
+          ['posix']
+        else
+          ['win']
+        end
       else
         ['posix']
       end

この変更を Fork https://github.com/t-nissie/mruby に施して、 GitHub ActionsでCygwinでのbuild & testをやろうとしたが、 おそらくCygwinのrubygemsまたはruby-rake pacageでインストールされるgemまたはrakeが静かに0を返しつつも動かない https://github.com/t-nissie/mruby/actions/runs/25100118602/job/73546831865 のでプルリクするわけにもいかず。

Summary

Here, I compiled mruby-4.0.0 and mruby from its repository on Cygwin. Maybe, we should use Posix things for Cygwin.

On Cygwin, I can run tests of

My rutine:

cd mruby/mruby/mruby
CC=gcc rake -m test:run:serial
pushd ../../t-nissie.mrubybind/test/; make clean; MRUBY=../../mruby/mruby make -j22 test
pushd ../../constantv; make clean && make && ./v10.constantv abc def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment