aboutsummaryrefslogtreecommitdiffhomepage
path: root/ruby/Rakefile
blob: 8eb7a2df3d2f5b992d1e6a777ef0d4fb9e5da700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require "rubygems"
require "rubygems/package_task"
require "rake/extensiontask" unless RUBY_PLATFORM == "java"
require "rake/testtask"

spec = Gem::Specification.load("google-protobuf.gemspec")

if RUBY_PLATFORM == "java"
  if `which mvn` == ''
    raise ArgumentError, "maven needs to be installed"
  end
  task :clean do
    system("mvn clean")
  end

  task :compile do
    system("mvn package")
  end
else
  Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
    ext.ext_dir = "ext/google/protobuf_c"
    ext.lib_dir = "lib/google"
    ext.cross_compile = true
    ext.cross_platform = [
      'x86-mingw32', 'x64-mingw32',
      'x86_64-linux', 'x86-linux',
      'universal-darwin'
    ]
  end

  task 'gem:windows' do
    require 'rake_compiler_dock'
    RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6"
  end
end

well_known_protos = %w[
  google/protobuf/any.proto
  google/protobuf/api.proto
  google/protobuf/duration.proto
  google/protobuf/empty.proto
  google/protobuf/field_mask.proto
  google/protobuf/source_context.proto
  google/protobuf/struct.proto
  google/protobuf/timestamp.proto
  google/protobuf/type.proto
  google/protobuf/wrappers.proto
]

# These are omitted for now because we don't support proto2.
proto2_protos = %w[
  google/protobuf/descriptor.proto
  google/protobuf/compiler/plugin.proto
]

genproto_output = []

well_known_protos.each do |proto_file|
  input_file = "../src/" + proto_file
  output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb")
  genproto_output << output_file
  file output_file => input_file do |file_task|
    sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
  end
end


# Proto for tests.
genproto_output << "tests/generated_code.rb"
file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
  sh "../src/protoc --ruby_out=. tests/generated_code.proto"
end

task :genproto => genproto_output

task :clean do
  sh "rm -f #{genproto_output.join(' ')}"
end

Gem::PackageTask.new(spec) do |pkg|
end

Rake::TestTask.new(:test => :build) do |t|
  t.test_files = FileList["tests/*.rb"]
end

task :build => [:clean, :compile, :genproto]
task :default => [:build]

# vim:sw=2:et