From 91922e05afcb12d94748202c146ef4e40d70a29a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 16 Oct 2025 16:05:49 +0900 Subject: [PATCH] mruby-io,mruby-dir: use posix hal for mingw instead of windows hal mingw provides posix-compatible functions (readlink, symlink, opendir, etc.) so it should use hal-posix-io/dir instead of hal-win-io/dir. detect mingw by checking if host_target or compiler command contains "mingw". check posix platforms first so mingw is caught before for_windows check. this fixes test failures on mingw where readlink returned absolute paths instead of relative paths, and symlink/socket tests failed due to api differences between windows native apis and posix apis. Co-authored-by: Claude --- mrbgems/mruby-dir/mrbgem.rake | 10 ++++++++-- mrbgems/mruby-io/mrbgem.rake | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mrbgems/mruby-dir/mrbgem.rake b/mrbgems/mruby-dir/mrbgem.rake index 71ed21cbd..905d28697 100644 --- a/mrbgems/mruby-dir/mrbgem.rake +++ b/mrbgems/mruby-dir/mrbgem.rake @@ -6,12 +6,18 @@ MRuby::Gem::Specification.new('mruby-dir') do |spec| # HAL gems must be explicitly specified in build config (recommended) or via auto-selection below spec.build.gems.one? { |g| g.name =~ /^hal-.*-dir$/ } or begin # No HAL found - determine appropriate error message or auto-load + # MinGW provides POSIX compatibility, so use hal-posix-dir + # Detect MinGW by checking host_target or compiler command + is_mingw = (spec.build.kind_of?(MRuby::CrossBuild) && + spec.build.host_target =~ /mingw/) || + spec.cc.command.to_s =~ /mingw/ + suggested_hal = if ENV['MRUBY_DIR_HAL'] ENV['MRUBY_DIR_HAL'] + elsif RUBY_PLATFORM =~ /linux|darwin|bsd/ || is_mingw + 'hal-posix-dir' elsif spec.for_windows? 'hal-win-dir' - elsif RUBY_PLATFORM =~ /linux|darwin|bsd/ - 'hal-posix-dir' else nil end diff --git a/mrbgems/mruby-io/mrbgem.rake b/mrbgems/mruby-io/mrbgem.rake index 6663666df..8bab028ca 100644 --- a/mrbgems/mruby-io/mrbgem.rake +++ b/mrbgems/mruby-io/mrbgem.rake @@ -10,10 +10,16 @@ MRuby::Gem::Specification.new('mruby-io') do |spec| # HAL gems must be explicitly specified in build config (recommended) or via auto-selection below spec.build.gems.one? { |g| g.name =~ /^hal-.*-io$/ } or begin # No HAL found - determine appropriate error message or auto-load - suggested_hal = if spec.for_windows? - 'hal-win-io' - elsif RUBY_PLATFORM =~ /linux|darwin|bsd/ + # MinGW provides POSIX compatibility, so use hal-posix-io + # Detect MinGW by checking host_target or compiler command + is_mingw = (spec.build.kind_of?(MRuby::CrossBuild) && + spec.build.host_target =~ /mingw/) || + spec.cc.command.to_s =~ /mingw/ + + suggested_hal = if RUBY_PLATFORM =~ /linux|darwin|bsd/ || is_mingw 'hal-posix-io' + elsif spec.for_windows? + 'hal-win-io' else nil end