Rakefile 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. unless ENV['IN_DOCKER'] == 'true'
  25. well_known_protos.each do |proto_file|
  26. input_file = "../src/" + proto_file
  27. output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb")
  28. genproto_output << output_file
  29. file output_file => input_file do |file_task|
  30. sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
  31. end
  32. end
  33. end
  34. if RUBY_PLATFORM == "java"
  35. if `which mvn` == ''
  36. raise ArgumentError, "maven needs to be installed"
  37. end
  38. task :clean do
  39. system("mvn clean")
  40. end
  41. task :compile do
  42. system("mvn package")
  43. end
  44. else
  45. Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
  46. ext.ext_dir = "ext/google/protobuf_c"
  47. ext.lib_dir = "lib/google"
  48. ext.cross_compile = true
  49. ext.cross_platform = [
  50. 'x86-mingw32', 'x64-mingw32',
  51. 'x86_64-linux', 'x86-linux',
  52. 'universal-darwin'
  53. ]
  54. end
  55. task 'gem:windows' do
  56. require 'rake_compiler_dock'
  57. RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0"
  58. end
  59. task 'gem:native' => [:genproto, 'gem:windows']
  60. end
  61. # Proto for tests.
  62. genproto_output << "tests/generated_code.rb"
  63. file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
  64. sh "../src/protoc --ruby_out=. tests/generated_code.proto"
  65. end
  66. task :genproto => genproto_output
  67. task :clean do
  68. sh "rm -f #{genproto_output.join(' ')}"
  69. end
  70. Gem::PackageTask.new(spec) do |pkg|
  71. end
  72. Rake::TestTask.new(:test => :build) do |t|
  73. t.test_files = FileList["tests/*.rb"]
  74. end
  75. task :build => [:clean, :compile, :genproto]
  76. task :default => [:build]
  77. # vim:sw=2:et