Rakefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. require "rubygems"
  2. require "rubygems/package_task"
  3. require "rake/extensiontask" unless RUBY_PLATFORM == "java"
  4. require "rake/testtask"
  5. spec = Gem::Specification.load("google-protobuf.gemspec")
  6. well_known_protos = %w[
  7. google/protobuf/any.proto
  8. google/protobuf/api.proto
  9. google/protobuf/duration.proto
  10. google/protobuf/empty.proto
  11. google/protobuf/field_mask.proto
  12. google/protobuf/source_context.proto
  13. google/protobuf/struct.proto
  14. google/protobuf/timestamp.proto
  15. google/protobuf/type.proto
  16. google/protobuf/wrappers.proto
  17. ]
  18. # These are omitted for now because we don't support proto2.
  19. proto2_protos = %w[
  20. google/protobuf/descriptor.proto
  21. google/protobuf/compiler/plugin.proto
  22. ]
  23. genproto_output = []
  24. # We won't have access to .. from within docker, but the proto files
  25. # will be there, thanks to the :genproto rule dependency for gem:native.
  26. unless ENV['IN_DOCKER'] == 'true'
  27. well_known_protos.each do |proto_file|
  28. input_file = "../src/" + proto_file
  29. output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
  30. genproto_output << output_file
  31. file output_file => input_file do |file_task|
  32. sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
  33. end
  34. end
  35. end
  36. if RUBY_PLATFORM == "java"
  37. if `which mvn` == ''
  38. raise ArgumentError, "maven needs to be installed"
  39. end
  40. task :clean do
  41. system("mvn --batch-mode clean")
  42. end
  43. task :compile do
  44. system("mvn --batch-mode package")
  45. end
  46. else
  47. Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
  48. ext.ext_dir = "ext/google/protobuf_c"
  49. ext.lib_dir = "lib/google"
  50. ext.cross_compile = true
  51. ext.cross_platform = [
  52. 'x86-mingw32', 'x64-mingw32',
  53. 'x86_64-linux', 'x86-linux',
  54. 'universal-darwin'
  55. ]
  56. end
  57. task 'gem:windows' do
  58. require 'rake_compiler_dock'
  59. RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0"
  60. end
  61. if RUBY_PLATFORM =~ /darwin/
  62. task 'gem:native' do
  63. system "rake genproto"
  64. system "rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0"
  65. end
  66. else
  67. task 'gem:native' => [:genproto, 'gem:windows']
  68. end
  69. end
  70. # Proto for tests.
  71. genproto_output << "tests/generated_code.rb"
  72. genproto_output << "tests/test_import.rb"
  73. file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
  74. sh "../src/protoc --ruby_out=. tests/generated_code.proto"
  75. end
  76. file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
  77. sh "../src/protoc --ruby_out=. tests/test_import.proto"
  78. end
  79. task :genproto => genproto_output
  80. task :clean do
  81. sh "rm -f #{genproto_output.join(' ')}"
  82. end
  83. Gem::PackageTask.new(spec) do |pkg|
  84. end
  85. Rake::TestTask.new(:test => :build) do |t|
  86. t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb")
  87. end
  88. # gc_test needs to be split out to ensure the generated file hasn't been
  89. # imported by other tests.
  90. Rake::TestTask.new(:gc_test => :build) do |t|
  91. t.test_files = FileList["tests/gc_test.rb"]
  92. end
  93. task :build => [:clean, :compile, :genproto]
  94. task :default => [:build]
  95. # vim:sw=2:et