mudge / re2

Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python".
http://mudge.name/re2/
BSD 3-Clause "New" or "Revised" License
130 stars 13 forks source link

Vendor re2 #61

Closed mudge closed 1 year ago

mudge commented 1 year ago

As suggested by @tomstuart: so that users don’t need to separately install the underlying re2 library, provide a vendored version that is compiled when the gem is installed.

In order to avoid breaking compatibility for existing users, the system re2 should still be preferred (either automatically found in /usr/local, /opt/homebrew or /usr or specified during install with —with-re2-dir) with the vendored version only built and used as a fallback.

Starting points

Questions

stanhu commented 1 year ago

I came across this issue because every time Homebrew updates re2, this appears to break the gem and users have to run gem pristine re2 to get back into a working state. I was looking to make this gem statically link re2, but it appears that Homebrew only ships the shared library. https://github.com/Homebrew/homebrew-core/pull/119928 fixes that.

How can we reliably compile our own version of re2 that links to the gem successfully?

https://github.com/flavorjones/mini_portile, which Nokogiri uses, should help. I think you also have to keep in mind to include the .tar.gz with the gem because you'll want to avoid downloading the source from an external site every time the gem installs.

Related work with ruby-magic:

  1. https://github.com/kwilczynski/ruby-magic/pull/3
  2. https://github.com/kwilczynski/ruby-magic/pull/5

How do we support various different platforms (including Windows)?

mini_portile should handle most of the issues. You'll see Nokogiri has some special handling for Windows.

What are the licensing implications of vendoring the upstream re2 source code inside the gem?

I suspect there's no issue since the re2 is a BSD license, and you're not actually modifying it?

Does this put pressure on releasing the gem every time there is an re2 update?

Perhaps. It looks like re2 updates every few months.

mudge commented 1 year ago

The first part of this is now done thanks to https://github.com/mudge/re2/pull/67

tomstuart commented 1 year ago

Hurrah! 🎉