Issue #16517 has been updated by MSP-Greg (Greg L).


@nobu

### MinGW devkit issue

`devkit.rb` is a file included in RubyInstaller and RubyInstaller2 builds.  These are the standard for Windows Rubies, and all CI that I have ever worked with uses them, and devkit.rb is included (on current master, located in `lib/ruby/site_ruby/2.8.0`).  'RubyInstaller' Rubies are compiled with MSYS2 tools, and hence are 'mingw'.

On non Windows OS's, c build tools and many packages are installed and available.  On Windows, MSYS2 tools are needed to build mingw Ruby, and also to compile extension gems.  MSYS2 tools are not normally in one's PATH, so devkit.rb has code to add them so make, gcc, etc are available.  Many CI scripts (rake, yml, etc) account for this by requiring devkit in some way or other.

As to installing extension gems, 'RubyInstaller' Rubies set PATH to include MSYS2 tools via `Gem.pre_install` located in `rubygems/defaults/operating_system.rb`.

So, installing gems is being accounted for, but directly using mkmf.rb doesn't use those hooks, so CI won't working unless specific code is added to require devkit.

Note that I loaded it with rescue, as (for instance) it obviously won't load when building ruby itself.  Also, the devkit gem you mentioned is rather old, and I really doubt any windows systems will have it installed.

### mswin library issue

I think with the OpenSSL code listed, compile will be called three times:

```ruby
have_library("crypto", "CRYPTO_malloc")     #=> fail
have_library("libcrypto", "CRYPTO_malloc")  #=> pass
have_library("libssl", "SSL_new")           #=> pass
```

The code I suggested will call `have_library` four times, which is an increase.  But, the vast majority of extconf.rb files do not have mswin specific code, and will fail if a needed library starts with lib.

mswin builds are not publicly available, but they are supported here in CI.  When working on https://github.com/ruby/ruby/pull/2838, I saved the build as an artifact and installed it locally.  I then tried to build puma, which compiles with OpenSSL, and noticed the issue.  I then looked at ruby/openssl, and noticed the mswin specific code.

Many packages/libraries required by popular extension gems are available from https://github.com/Microsoft/vcpkg, so there is a chance that many extension may compile on mswin.

One issues with MinGW builds is that MSYS2 packages are compiled against msvcrt.dll, while many Windows apps are compiled against vcruntime140.dll.  This runtime mismatch can cause issues, especially with 'embedded Ruby'.  Hence, I think there are reasons to have 'real world' support of mswin, which uses vcruntime140.dll.

### General reasons for this request

1. With the arrival of Actions, having one CI script/workflow run with a minimal amount of platform specific code is possible with extension gems on MinGW & mswin.

2. The two suggested changes are real world issues that I believe fall within the definition of 'supporting a platform'.  They could be backported to currently supported Ruby versions.

----------------------------------------
Feature #16517: mkmf.rb - changes for Windows ?
https://bugs.ruby-lang.org/issues/16517#change-83973

* Author: MSP-Greg (Greg L)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I propose two changes to mkmf.rb to make it more Windows friendly.

1) mingw - `devkit` has been the standard for 'enabling' compile tools in publicly available MinGW builds for quite a while.  Could something like the following be added?  Not sure whether to rescue on LoadError or not, or whether to output anything if it doesn't load.

```ruby
if $mingw
  begin
    require 'devkit'
  rescue
  end
end
```

2) mswin - most compile tools other than msvc will find libraries without a lib prefix.  Note the following code in extconf.rb for OpenSSL:

```ruby
ret = have_library("crypto", "CRYPTO_malloc") &&
  have_library("ssl", "SSL_new")
return ret if ret

if $mswin
  # OpenSSL >= 1.1.0: libcrypto.lib and libssl.lib.
  if have_library("libcrypto", "CRYPTO_malloc") &&
      have_library("libssl", "SSL_new")
    return true
  end
```

If something like the following was added, the above wouldn't be needed:

```ruby
if $mswin
  alias_method :orig_find_library, :find_library
  
  def find_library(lib, func, *paths, &b)
    orig_find_library(lib, func, *paths, b) || orig_find_library("lib#{lib}", func, *paths, b)
  end

  alias_method :orig_have_library, :have_library

  def have_library(lib, func = nil, headers = nil, opt = "", &b)
    orig_have_library(lib, func, headers, opt, b) || orig_have_library("lib#{lib}", func, headers, opt, b)
  end
end
```

Adding something similar to above two items would remove the need for Windows specific build code in many extension gems.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>