-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[ruby] fix re2 compilation when older system version installed #32580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c358aea
to
01cb43c
Compare
re2 previously failed to compile if: 1. An old `re2` version is installed with a non-standard system prefix, such as `/opt/local`. 2. The environment variable is set: `CPPFLAGS=-I/opt/local/include`. Running `make` would result in function prototype mismatches because the Makefile would previously attempt to use the headers from `/opt/local/include/re2` before the `third_party/re2/re2` directory. To ensure the current directories receive priority, include the relevant re2 directories in the include path.
01cb43c
to
37a6ff0
Compare
Something changed between v1.42.0 and v1.50.0. Here's the search order before and after. Notice where Search order in v1.42.0g++ -Ithird_party/boringssl-with-bazel/src/include -Ithird_party/address_sorting/include -Ithird_party/cares -Ithird_party/cares/cares -DGPR_BACKWARDS_COMPATIBILITY_MODE -DGRPC_XDS_USER_AGENT_NAME_SUFFIX="\"RUBY\"" -DGRPC_XDS_USER_AGENT_VERSION_SUFFIX="\"1.42.0\"" -g -Wall -Wextra -DOSATOMIC_USE_INLINED=1 -Ithird_party/abseil-cpp -Ithird_party/re2 -Ithird_party/upb -Isrc/core/ext/upb-generated -Isrc/core/ext/upbdefs-generated -Ithird_party/xxhash -O2 -Wframe-larger-than=16384 -fPIC -I. -Iinclude -I/tmp/grpc/gens -DNDEBUG -DINSTALL_PREFIX=\"/usr/local\" -Ithird_party/zlib -I/opt/re2/include -std=c++11 -MMD -MF /tmp/grpc/objs/opt/third_party/re2/re2/prog.dep -c -o /tmp/grpc/objs/opt/third_party/re2/re2/prog.o third_party/re2/re2/prog.cc
mkdir -p `dirname /tmp/grpc/objs/opt/third_party/re2/re2/regexp.o`
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/10"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/tmp/grpc/gens"
#include "..." search starts here:
#include <...> search starts here:
third_party/boringssl-with-bazel/src/include
third_party/address_sorting/include
third_party/cares
third_party/cares/cares
third_party/abseil-cpp
third_party/re2
third_party/upb
src/core/ext/upb-generated
src/core/ext/upbdefs-generated
third_party/xxhash
.
include
third_party/zlib
/opt/re2/include
/usr/include/c++/10
/usr/include/x86_64-linux-gnu/c++/10
/usr/include/c++/10/backward
/usr/lib/gcc/x86_64-linux-gnu/10/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include Search order in v1.52.0
|
I should note I'm building the Ruby C extension, so perhaps there's a change in |
Ok, in v1.42.0, the grpc/src/ruby/ext/grpc/extconf.rb Lines 61 to 63 in 11f0048
In v1.52.0, grpc/src/ruby/ext/grpc/extconf.rb Lines 87 to 91 in febed51
With 0a5d982, I also can't use With this pull request, the search path now looks something like this when
Maybe we should prepend |
I suppose in the case of Truffleruby, it was intentional that these Maybe we want to make sure diff --git a/Makefile b/Makefile
index 72901b111a..fa562efff5 100644
--- a/Makefile
+++ b/Makefile
@@ -534,6 +534,7 @@ CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
GRPC_ABSEIL_DEP = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
GRPC_ABSEIL_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
+CPPFLAGS := -Ithird_party/abseil-cpp $(CPPFLAGS)
# Setup re2 dependency
@@ -547,6 +548,7 @@ CPPFLAGS := -Ithird_party/re2 $(CPPFLAGS)
UPB_DEP = $(LIBDIR)/$(CONFIG)/libupb.a
UPB_MERGE_OBJS = $(LIBUPB_OBJS)
UPB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libupb.a
+CPPFLAGS := -Ithird_party/upb $(CPPFLAGS)
# Setup boringssl dependency But this still leaves a few other packages vulnerable to being prefixed by
|
It's not clear to me about what the problem is and how to fix it as we deprecated Makefile already and it's there only to generate artifacts such as Ruby. So I just reassigned to Alex. |
If we prepend then the user-supplied CPPFLAGS env var would override the values set in extconf.rb, is that really what we want? I think that's inherently more brittle, no? But I might misunderstand the issue. |
A possibility could be instead of |
That would work. I wasn't sure if that would have worked for TruffleRuby. |
This reverts commit 37a6ff0.
grpc#27660 caused `CPPFLAGS` to inherit from the environment, but this can cause the Makefile to use external include files for re2 and other libraries if `-I` flags are defined. This commit reverts to the original behavior of only using `RbConfig::CONFIG` values to avoid using the wrong headers.
3496434
to
857897a
Compare
@eregon Can you review if this works for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is fine and looks more reliable (doesn't depend on random stuff in the user ENV, except for LD/LDXX).
One thing though is this no longer allows overriding |
This makes it possible to override the compiler and other programs.
@eregon Oh, that's a good point. I've updated this pull request with those changes. Ruby MRI also supports |
Looks good and should be compatible with the original logic. Re The only real difference with TruffleRuby is one must respect RbConfig values for CC (otherwise there is not bitcode, and that's needed by GraalVM LLVM) and CPPFLAGS/cppflags (otherwise the ABI version is lost). |
@apolcyn Is there anything else I need to do to get this merged? |
@apolcyn Sorry to ping you again. This pull request is blocking our ability to upgrade |
The previous version (2016-02-01) is pretty old, and it appears that the latest grpc gem attempts to build with the system-installed re2 headers due to grpc/grpc#32580 (comment). Update to a more recent version to work around an issue building the gem. Changelog: changed
An Arch Linux bug report related to this PR https://bugs.archlinux.org/task/78379 |
…32580) re2 previously failed to compile if: 1. An old `re2` version is installed with a non-standard system prefix, such as `/opt/local`. 2. The environment variable is set: `CPPFLAGS=-I/opt/local/include`. Running `make` would result in function prototype mismatches because the Makefile would previously attempt to use the headers from `/opt/local/include/re2` before the `third_party/re2/re2` directory. grpc#27660 caused `CPPFLAGS` to inherit from the environment, but this can cause the Makefile to use external include files for re2 and other libraries if `-I` flags are defined. This commit reverts to the original behavior of only using `RbConfig::CONFIG` values to avoid using the wrong headers.
re2 previously failed to compile if: 1. An old `re2` version is installed with a non-standard system prefix, such as `/opt/local`. 2. The environment variable is set: `CPPFLAGS=-I/opt/local/include`. Running `make` would result in function prototype mismatches because the Makefile would previously attempt to use the headers from `/opt/local/include/re2` before the `third_party/re2/re2` directory. #27660 caused `CPPFLAGS` to inherit from the environment, but this can cause the Makefile to use external include files for re2 and other libraries if `-I` flags are defined. This commit reverts to the original behavior of only using `RbConfig::CONFIG` values to avoid using the wrong headers.
On platforms that need to compile the grpc native extension, there is a bug introduced in grpc v1.48.0 that causes the native extension to include re2 headers from `/opt/gitlab/include` instead of `vendor/re2`. To work around that problem, add `vendor/re2` in the include path. Relates to: * https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/7815 * Relates to grpc/grpc#32580 Changelog: fixed
re2 previously failed to compile if:
re2
version is installed with a non-standard system prefix, such as/opt/local
.CPPFLAGS=-I/opt/local/include
.Running
make
would result in function prototype mismatches because the Makefile would previously attempt to use the headers from/opt/local/include/re2
before thethird_party/re2/re2
directory.#27660 caused
CPPFLAGS
to inherit from the environment, but this can cause the Makefile to use external include files for re2 and other libraries if-I
flags are defined.This commit reverts to the original behavior of only using
RbConfig::CONFIG
values to avoid using the wrong headers.