Rakefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. unless RUBY_PLATFORM =~ /darwin/
  49. # TODO: also set "no_native to true" for mac if possible. As is,
  50. # "no_native" can only be set if the RUBY_PLATFORM doing
  51. # cross-compilation is contained in the "ext.cross_platform" array.
  52. ext.no_native = true
  53. end
  54. ext.ext_dir = "ext/google/protobuf_c"
  55. ext.lib_dir = "lib/google"
  56. ext.cross_compile = true
  57. ext.cross_platform = [
  58. 'x86-mingw32', 'x64-mingw32',
  59. 'x86_64-linux', 'x86-linux',
  60. 'universal-darwin'
  61. ]
  62. end
  63. task 'gem:windows' do
  64. require 'rake_compiler_dock'
  65. 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"
  66. end
  67. if RUBY_PLATFORM =~ /darwin/
  68. task 'gem:native' do
  69. system "rake genproto"
  70. 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"
  71. end
  72. else
  73. task 'gem:native' => [:genproto, 'gem:windows']
  74. end
  75. end
  76. # Proto for tests.
  77. genproto_output << "tests/generated_code.rb"
  78. genproto_output << "tests/test_import.rb"
  79. file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
  80. sh "../src/protoc --ruby_out=. tests/generated_code.proto"
  81. end
  82. file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
  83. sh "../src/protoc --ruby_out=. tests/test_import.proto"
  84. end
  85. task :genproto => genproto_output
  86. task :clean do
  87. sh "rm -f #{genproto_output.join(' ')}"
  88. end
  89. Gem::PackageTask.new(spec) do |pkg|
  90. end
  91. Rake::TestTask.new(:test => :build) do |t|
  92. t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb")
  93. end
  94. # gc_test needs to be split out to ensure the generated file hasn't been
  95. # imported by other tests.
  96. Rake::TestTask.new(:gc_test => :build) do |t|
  97. t.test_files = FileList["tests/gc_test.rb"]
  98. end
  99. task :build => [:clean, :compile, :genproto]
  100. task :default => [:build]
  101. # vim:sw=2:et