Skip to content

`bundle install` fails to install re2 gem with libre2 2023-07-01

Overview

If you upgrade Homebrew's re2 to 2023-07-01, you'll see this error when attempting to install the native extension for the re2 gem:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/gitlab/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/re2-1.6.0/ext/re2
/Users/gitlab/.asdf/installs/ruby/3.1.4/bin/ruby -I /Users/gitlab/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0 extconf.rb --with-re2-dir\=/opt/homebrew/opt/re2
checking for -lstdc++... yes
checking for stdint.h... yes
checking for rb_str_sublen()... yes
checking for -lre2... yes
checking for re2 requires C++11 compiler... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/gitlab/.asdf/installs/ruby/3.1.4/bin/$(RUBY_BASE_NAME)
	--with-re2-dir
	--with-re2-include
	--without-re2-include=${re2-dir}/include
	--with-re2-lib
	--without-re2-lib=${re2-dir}/lib
	--with-stdc++-dir
	--without-stdc++-dir
	--with-stdc++-include
	--without-stdc++-include=${stdc++-dir}/include
	--with-stdc++-lib
	--without-stdc++-lib=${stdc++-dir}/lib
	--with-stdc++lib
	--without-stdc++lib
	--with-stdint-dir
	--without-stdint-dir
	--with-stdint-include
	--without-stdint-include=${stdint-dir}/include
	--with-stdint-lib
	--without-stdint-lib=${stdint-dir}/lib
	--with-re2lib
	--without-re2lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/gitlab/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/re2-1.6.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/gitlab/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/re2-1.6.0 for inspection.
Results logged to /Users/gitlab/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/re2-1.6.0/gem_make.out

The mkmf.log shows:

/opt/homebrew/opt/re2/include/re2/re2.h:217:10: fatal error: 'absl/base/call_once.h' file not found
#include "absl/base/call_once.h"
         ^~~~~~~~~~~~~~~~~~~~~~~
15 warnings and 1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <re2/re2.h>
4: int main() { return 0; }
/* end */

Homebrew now ships with re2 2023-07-01, which now adds a direct dependency on abseil due to https://code-review.googlesource.com/c/re2/+/61250.

This means re2 now:

  1. Includes headers to the abseil library
  2. Needs a compiler supporting C++17 or C++20 (C++14 doesn't suffice, contrary to the documentation)

In support/bootstrap-common.sh, the re2 gem is build with this config:

bundle config build.re2 --with-re2-dir="$(brew --prefix re2)"

This --with-re2-dir config actually prevents including /opt/homebrew/include in the path.

Workarounds

  1. gem install re2 -v 1.6.0 -- --with-cppflags="-x c++ -std=c++20"
  2. Build a gem from https://github.com/mudge/re2/pull/65 and install that.

Impacted categories

The following categories relate to this issue:

Steps to replicate (optional)

Proposal (optional)

Environment (optional)

  • Operating system name: <!-- output of `uname -a` command -->
  • Architecture: <!-- output of `arch` command -->
  • The contents of your gdk.yml (if any)
  • Ruby version: <!-- output of `ruby --version` command -->
  • GDK version: <!-- output of `git rev-parse --short HEAD` command -->
Edited by Stan Hu