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


Re the mswin change, the cost is low, and the benefit is high.

Re requiring devkit, my request is a specific solution to a specific problem.

RubyGems has hooks, and will also load/require specific files, like `operating_system.rb`. `*.gemspec` files also allow for 'free-form' metadata.

Rather than the specific solution, should something like the following be added as a hook for packagers in `mkmf.rb`?

```ruby
begin
  require "#{RbConfig::CONFIG['sitelibdir']}/mkmf_pre.rb"
rescue
end
```

MinGW builds using RubyInstaller2/RIDK use gemspec metadata to install packages/libraries needed to compile/install an extension gem.

Something similar could be used in `mkmf_pre.rb` to allow packagers to do the same to 'enable the typical extension build in CI'.

*.gemspec metadata could include the names of packages required for Ubuntu, macOS, mingw, and maybe mswin.  This could be used for both extension CI builds and gem installation.  Certainly would make cross platform building/installing/compiling easier on MRI builds, and minimize the platform specific code needed.

@larskanis - Thanks for the post.  I apologize for not pinging you here.  I'm not quite all there (flu).

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

* 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>