Skip to content

Commit

Permalink
ruby: make it possible to specify compiler for C extension
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:

```
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.
  • Loading branch information
stanhu committed Jan 3, 2025
1 parent 45ba25b commit 33693f8
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 33693f8

Please sign in to comment.