Rakefile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if RUBY_PLATFORM == "java"
  7. if `which mvn` == ''
  8. raise ArgumentError, "maven needs to be installed"
  9. end
  10. task :clean do
  11. system("mvn clean")
  12. end
  13. task :compile do
  14. system("mvn package")
  15. end
  16. else
  17. Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
  18. ext.ext_dir = "ext/google/protobuf_c"
  19. ext.lib_dir = "lib/google"
  20. ext.cross_compile = true
  21. ext.cross_platform = [
  22. 'x86-mingw32', 'x64-mingw32',
  23. 'x86_64-linux', 'x86-linux',
  24. 'universal-darwin'
  25. ]
  26. end
  27. task 'gem:windows' do
  28. require 'rake_compiler_dock'
  29. RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6"
  30. end
  31. end
  32. well_known_protos = %w[
  33. google/protobuf/any.proto
  34. google/protobuf/api.proto
  35. google/protobuf/duration.proto
  36. google/protobuf/empty.proto
  37. google/protobuf/field_mask.proto
  38. google/protobuf/source_context.proto
  39. google/protobuf/struct.proto
  40. google/protobuf/timestamp.proto
  41. google/protobuf/type.proto
  42. google/protobuf/wrappers.proto
  43. ]
  44. # These are omitted for now because we don't support proto2.
  45. proto2_protos = %w[
  46. google/protobuf/descriptor.proto
  47. google/protobuf/compiler/plugin.proto
  48. ]
  49. genproto_output = []
  50. well_known_protos.each do |proto_file|
  51. input_file = "../src/" + proto_file
  52. output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb")
  53. genproto_output << output_file
  54. file output_file => input_file do |file_task|
  55. sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
  56. end
  57. end
  58. # Proto for tests.
  59. genproto_output << "tests/generated_code.rb"
  60. file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
  61. sh "../src/protoc --ruby_out=. tests/generated_code.proto"
  62. end
  63. task :genproto => genproto_output
  64. task :clean do
  65. sh "rm -f #{genproto_output.join(' ')}"
  66. end
  67. Gem::PackageTask.new(spec) do |pkg|
  68. end
  69. Rake::TestTask.new(:test => :build) do |t|
  70. t.test_files = FileList["tests/*.rb"]
  71. end
  72. task :build => [:clean, :compile, :genproto]
  73. task :default => [:build]
  74. # vim:sw=2:et