Skip to content

Commit

Permalink
[ruby] fix re2 compilation when older system version installed (grpc#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
stanhu authored and eugeneo committed May 17, 2023
1 parent 8fd89a2 commit 328c4d4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/ruby/ext/grpc/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ def env_unset?(name)
ENV[name].nil? || ENV[name].size == 0
end

def rbconfig_set?(name)
RbConfig::CONFIG[name] && RbConfig::CONFIG[name].size > 0
def inherit_env_or_rbconfig(name)
ENV[name] = inherit_rbconfig(name) if env_unset?(name)
end

def inherit_rbconfig(name)
ENV[name] = RbConfig::CONFIG[name] if env_unset?(name) && rbconfig_set?(name)
ENV[name] = RbConfig::CONFIG[name] || ''
end

def env_append(name, string)
ENV[name] ||= ''
ENV[name] += ' ' + string
end

inherit_rbconfig 'AR'
inherit_rbconfig 'CC'
inherit_rbconfig 'CXX'
inherit_rbconfig 'RANLIB'
inherit_rbconfig 'STRIP'
inherit_env_or_rbconfig 'AR'
inherit_env_or_rbconfig 'CC'
inherit_env_or_rbconfig 'CXX'
inherit_env_or_rbconfig 'RANLIB'
inherit_env_or_rbconfig 'STRIP'
inherit_rbconfig 'CPPFLAGS'
inherit_rbconfig 'LDFLAGS'

Expand Down

0 comments on commit 328c4d4

Please sign in to comment.