Skip to content

Commit

Permalink
Fix source gem compilation (#8471)
Browse files Browse the repository at this point in the history
* Select appropriate protoc binary for gem build

This should allow gem installation when
`bundle config force_ruby_platform true` has been set.

It has the unfortunate side effect of printing the protoc version during
build, but a quiet cross-platform solution is more complicated.

* Add path to wyhash header for source gem compilation
  • Loading branch information
jamesgecko committed Apr 12, 2021
1 parent ee04809 commit 68cb69e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions ruby/Rakefile
Expand Up @@ -24,6 +24,12 @@ proto2_protos = %w[
google/protobuf/compiler/plugin.proto
]

if system('../src/protoc --version')
protoc_command = '../src/protoc'
else
protoc_command = 'protoc'
end

genproto_output = []

# We won't have access to .. from within docker, but the proto files
Expand All @@ -34,7 +40,7 @@ unless ENV['IN_DOCKER'] == 'true'
output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
genproto_output << output_file
file output_file => input_file do |file_task|
sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
sh "#{protoc_command} -I../src --ruby_out=lib #{input_file}"
end
end
end
Expand Down Expand Up @@ -108,43 +114,43 @@ genproto_output << "tests/multi_level_nesting_test.rb"
genproto_output << "tests/wrappers.rb"

file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/generated_code.proto"
sh "#{protoc_command} --ruby_out=. tests/generated_code.proto"
end

file "tests/generated_code_proto2.rb" => "tests/generated_code_proto2.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/generated_code_proto2.proto"
sh "#{protoc_command} --ruby_out=. tests/generated_code_proto2.proto"
end

file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/test_import.proto"
sh "#{protoc_command} --ruby_out=. tests/test_import.proto"
end

file "tests/test_import_proto2.rb" => "tests/test_import_proto2.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/test_import_proto2.proto"
sh "#{protoc_command} --ruby_out=. tests/test_import_proto2.proto"
end

file "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto"
sh "#{protoc_command} --ruby_out=. tests/test_ruby_package.proto"
end

file "tests/test_ruby_package_proto2.rb" => "tests/test_ruby_package_proto2.proto" do |file_task|
sh "../src/protoc --ruby_out=. tests/test_ruby_package_proto2.proto"
sh "#{protoc_command} --ruby_out=. tests/test_ruby_package_proto2.proto"
end

file "tests/basic_test.rb" => "tests/basic_test.proto" do |file_task|
sh "../src/protoc --experimental_allow_proto3_optional -I../src -I. --ruby_out=. tests/basic_test.proto"
sh "#{protoc_command} --experimental_allow_proto3_optional -I../src -I. --ruby_out=. tests/basic_test.proto"
end

file "tests/basic_test_proto2.rb" => "tests/basic_test_proto2.proto" do |file_task|
sh "../src/protoc -I../src -I. --ruby_out=. tests/basic_test_proto2.proto"
sh "#{protoc_command} -I../src -I. --ruby_out=. tests/basic_test_proto2.proto"
end

file "tests/multi_level_nesting_test.rb" => "tests/multi_level_nesting_test.proto" do |file_task|
sh "../src/protoc -I../src -I. --ruby_out=. tests/multi_level_nesting_test.proto"
sh "#{protoc_command} -I../src -I. --ruby_out=. tests/multi_level_nesting_test.proto"
end

file "tests/wrappers.rb" => "../src/google/protobuf/wrappers.proto" do |file_task|
sh "../src/protoc -I../src -I. --ruby_out=tests ../src/google/protobuf/wrappers.proto"
sh "#{protoc_command} -I../src -I. --ruby_out=tests ../src/google/protobuf/wrappers.proto"
end

task :genproto => genproto_output
Expand Down
1 change: 1 addition & 0 deletions ruby/ext/google/protobuf_c/extconf.rb
Expand Up @@ -17,4 +17,5 @@
$objs = ["protobuf.o", "convert.o", "defs.o", "message.o",
"repeated_field.o", "map.o", "ruby-upb.o", "wrap_memcpy.o"]

find_header('third_party/wyhash/wyhash.h', '../../../..')
create_makefile("google/protobuf_c")

0 comments on commit 68cb69e

Please sign in to comment.