blob: 8eb7a2df3d2f5b992d1e6a777ef0d4fb9e5da700 [file] [log] [blame]
Isaiah Peng27e2b572014-12-24 15:48:41 +01001require "rubygems"
2require "rubygems/package_task"
3require "rake/extensiontask" unless RUBY_PLATFORM == "java"
Chris Fallin973f4252014-11-18 14:19:58 -08004require "rake/testtask"
5
Chris Fallin91473dc2014-12-12 15:58:26 -08006spec = Gem::Specification.load("google-protobuf.gemspec")
Chris Fallin973f4252014-11-18 14:19:58 -08007
Isaiah Peng27e2b572014-12-24 15:48:41 +01008if RUBY_PLATFORM == "java"
Adam Greened55733c2015-05-01 11:54:29 -07009 if `which mvn` == ''
10 raise ArgumentError, "maven needs to be installed"
11 end
Isaiah Peng27e2b572014-12-24 15:48:41 +010012 task :clean do
13 system("mvn clean")
14 end
15
16 task :compile do
17 system("mvn package")
18 end
19else
20 Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
21 ext.ext_dir = "ext/google/protobuf_c"
22 ext.lib_dir = "lib/google"
Nicolas "Pixel" Noblebbb188a2016-02-06 00:55:45 +010023 ext.cross_compile = true
24 ext.cross_platform = [
25 'x86-mingw32', 'x64-mingw32',
26 'x86_64-linux', 'x86-linux',
27 'universal-darwin'
28 ]
Isaiah Peng27e2b572014-12-24 15:48:41 +010029 end
Josh Habermanaf4aa9b2016-02-04 10:44:22 -080030
31 task 'gem:windows' do
32 require 'rake_compiler_dock'
Nicolas "Pixel" Noblebbb188a2016-02-06 00:55:45 +010033 RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6"
Josh Habermanaf4aa9b2016-02-04 10:44:22 -080034 end
Isaiah Peng27e2b572014-12-24 15:48:41 +010035end
36
Josh Haberman513875d2016-03-03 14:08:54 -080037well_known_protos = %w[
38 google/protobuf/any.proto
39 google/protobuf/api.proto
40 google/protobuf/duration.proto
41 google/protobuf/empty.proto
42 google/protobuf/field_mask.proto
43 google/protobuf/source_context.proto
44 google/protobuf/struct.proto
45 google/protobuf/timestamp.proto
46 google/protobuf/type.proto
47 google/protobuf/wrappers.proto
48]
49
50# These are omitted for now because we don't support proto2.
51proto2_protos = %w[
52 google/protobuf/descriptor.proto
53 google/protobuf/compiler/plugin.proto
54]
55
56genproto_output = []
57
58well_known_protos.each do |proto_file|
59 input_file = "../src/" + proto_file
60 output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb")
61 genproto_output << output_file
62 file output_file => input_file do |file_task|
63 sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
64 end
65end
66
67
68# Proto for tests.
69genproto_output << "tests/generated_code.rb"
70file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
71 sh "../src/protoc --ruby_out=. tests/generated_code.proto"
72end
73
74task :genproto => genproto_output
75
76task :clean do
77 sh "rm -f #{genproto_output.join(' ')}"
78end
79
Isaiah Peng27e2b572014-12-24 15:48:41 +010080Gem::PackageTask.new(spec) do |pkg|
Chris Fallin973f4252014-11-18 14:19:58 -080081end
82
83Rake::TestTask.new(:test => :build) do |t|
84 t.test_files = FileList["tests/*.rb"]
85end
86
Josh Haberman513875d2016-03-03 14:08:54 -080087task :build => [:clean, :compile, :genproto]
Chris Fallin973f4252014-11-18 14:19:58 -080088task :default => [:build]
89
90# vim:sw=2:et