Skip to content

Commit

Permalink
ruby: make it possible to specify compiler for C extension (#19863)
Browse files Browse the repository at this point in the history
Previously running `gem install google-protobuf --platform ruby` used the default C compiler specified by `mkmf`, which uses `RbConfig::MAKEFILE_CONFIG["CC"]` and `RbConfig::MAKEFILE_CONFIG["CXX"]`.

This commit supports using `CC`, `CXX`, and `LD` from the environment:

```shell
export CC=my-custom-gcc
export CXX=my-custom-g++
gem install google-protobuf --platform ruby
```

Most native gems, such as grpc and nokogiri, allow for this.

Closes #19863

COPYBARA_INTEGRATE_REVIEW=#19863 from stanhu:sh-support-custom-gcc 33693f8
PiperOrigin-RevId: 713675592
  • Loading branch information
stanhu authored and copybara-github committed Jan 9, 2025
1 parent 0d4842d commit b46f315
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ruby/ext/google/protobuf_c/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

dir_config(ext_name)

if ENV["CC"]
RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
end

if ENV["CXX"]
RbConfig::CONFIG["CXX"] = RbConfig::MAKEFILE_CONFIG["CXX"] = ENV["CXX"]
end

if ENV["LD"]
RbConfig::CONFIG["LD"] = RbConfig::MAKEFILE_CONFIG["LD"] = ENV["LD"]
end

if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /freebsd/
$CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
else
Expand Down

0 comments on commit b46f315

Please sign in to comment.