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
129 stars 13 forks source link

RE2 now requires C++11 #30

Closed stefanor closed 8 years ago

stefanor commented 8 years ago

Since google/re2@cd505f4597d4022902b25bd036de29478e22d481

mudge commented 8 years ago

Thanks for this (and apologies for Hound's noisy auto response, looks like its configuration might need tweaking).

Annoyingly, I can't test this on my ageing computer (Mac OS X 10.7) as it lacks C++11 support. I can test this out elsewhere in a few days though.

Looking at the official installation instructions, could we simplify the extconf.rb by specifically checking for atomic (perhaps with have_library)?

Also, are the Travis CI configuration changes still required (particularly dropping 1.8.7 support)?

stefanor commented 8 years ago

Hound was also right about a few things. I'm not much of a ruby-ist, so I'm not in touch with preferred style :)

as it lacks C++11 support

Yeah, that's a bit of a downside. There are a lot of systems out there without C++11 support, and requiring it is painful. So, figuring out a way to support both older and newer re2 may be sensible?

could we simplify the extconf.rb by specifically checking for atomic (perhaps with have_library)?

So, atomic is a header in the C++ stdlib. I don't think have_library will be that helpful.

Also, are the Travis CI configuration changes still required

So, look at the first Travis failure. Everything blew up because of lack of C++11 support in Ubuntu 12.04 https://travis-ci.org/mudge/re2/builds/121797286

(particularly dropping 1.8.7 support)?

I simply couldn't get it to work. https://travis-ci.org/stefanor/ruby-re2/builds/121813125


This has all got me thinking that we can probably detect whether the RE2 library requires C++11 yet, or not. And compile, appropriately.

Then you'll be able to revert the travis changes (you're testing against an ancient RE2 library, that doesn't require C++11, anyway). Or keep them, and maybe add a new dimension with a modern RE2.

I'll hack a bit.

stefanor commented 8 years ago

There we go. I think that's a lot simpler.

Works with the old Travis config too: https://travis-ci.org/stefanor/ruby-re2/builds/123618713

mudge commented 8 years ago

Thanks for that, Stefano.

I'm just trying to test this out locally but the latest stable version of re2 (2016-04-01), seems not to require C++11 when linking with this branch:

> rake
mkdir -p tmp/x86_64-darwin14/re2/2.3.0
cd tmp/x86_64-darwin14/re2/2.3.0
/Users/mudge/.rubies/ruby-2.3.0/bin/ruby -I. ../../../../ext/re2/extconf.rb
checking for main() in -lstdc++... yes
checking for stdint.h... yes
checking for rb_str_sublen()... yes
checking for RE2... yes
checking for RE2 requires C++11... no
checking for RE2::Match() with endpos argument... yes
creating Makefile

Should I be trying to link to a more recent, unreleased version?

mudge commented 8 years ago

Is the new version of re2 exposing any C++11 types or can we get away with linking to it without requiring C++11 on our side (c.f. "Can a compiled C++11 library (lib,dll,etc.) be linked in older C++ compilers?")?

stefanor commented 8 years ago

Is the new version of re2 exposing any C++11 types

It is using std::atomic in re2.h (indirectly), so to consume that header, you need to be using C++11.

stefanor commented 8 years ago

the latest stable version of re2 (2016-04-01), seems not to require C++11

That version should require it. It does for me:

mkdir -p tmp/x86_64-linux-gnu/re2/2.3.0
cd tmp/x86_64-linux-gnu/re2/2.3.0
/usr/bin/ruby2.3 -I. ../../../../ext/re2/extconf.rb
checking for main() in -lstdc++... yes
checking for stdint.h... yes
checking for rb_str_sublen()... yes
checking for RE2... yes
checking for RE2 requires C++11... yes
checking for RE2::Match() with endpos argument... yes
creating Makefile

Did you forget to rake clean ?

mudge commented 8 years ago

Just to revive this, I can finally reproduce the build failures and have the library compiling cleanly with Ruby 2.3.1.

To complicate matters, Ruby 2.3.0 had a bug with a use of memset_s in include/ruby/missing.h which breaks compilation (now fixed so I'll see if there is some workaround for that version.

mudge commented 8 years ago

Thanks so much for this contribution and apologies it took so long to get released but this is now fixed in version 1.0.0.