jgarber / redcloth

RedCloth is a Ruby library for converting Textile into HTML.
Other
443 stars 113 forks source link

Windows - loading of redcloth_scan #51

Closed MSP-Greg closed 8 months ago

MSP-Greg commented 6 years ago

On Windows, the loading code in redcloth.rb assumes that one is loading it from a 'fat binary' gem. Using standard windows Ruby versions from 2.4 forward, the gem can be compiled by the user.

I came across the issue running YARD tests. I'll post a PR later.

Also, I've come across a few gems where the owners /maintainers have (understandably) decided to not create Windows pre-compiled gems. Appveyor has all Ruby versions included in their normal image, so I believe one could assemble/compile the files for the gem package and save them as an artifact, which could then be downloaded, packaged, and finally pushed to rubygems.org.

Would that be helpful?

Thanks, Greg

MSP-Greg commented 6 years ago

As a follow up, the code currently used to load redcloth_scan is here, as shown below:

require 'rbconfig'
begin
  conf = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
  prefix = conf['arch'] =~ /mswin|mingw/ ? "#{conf['MAJOR']}.#{conf['MINOR']}/" : ''
  lib = "#{prefix}redcloth_scan"
  require lib
rescue LoadError => e
  e.message << %{\nCouldn't load #{lib}\nThe $LOAD_PATH was:\n#{$LOAD_PATH.join("\n")}}
  raise e
end

This will only load from a subdirectory of MAJOR.MINOR. As an example, Nokogiri uses the following for loading a nokogiri.so file, which will load for both their fat-binary and a user compiled gem install:

begin
  RUBY_VERSION =~ /(\d+\.\d+)/
  require "nokogiri/#{$1}/nokogiri"
rescue LoadError
  require 'nokogiri/nokogiri'
end

Thoughts?

Thanks, Greg

joshuasiler commented 6 years ago

We don't currently have a windows maintainer - would you be interested in taking on that role?

MSP-Greg commented 6 years ago

Thank you for the offer, but I'm already spread a little thin. Also, I'm not really a c type, but I am familiar with Windows (MSYS2/minGW) build tools.

So, feel free to ping me if a Windows specific question comes up.

I hope to write a template that will allow Owners/Collaborators to build windows 'fat-binary' gems on Appveyor, saving the files as an artifact. The files could then be downloaded, packaged, and uploaded to RubyGems.org.

Re this issue, the Nokogiri code is short and concise, but it won't raise anything other than a standard LoadError. Would you prefer to continue with a custom message?

Thanks, Greg