blob: fa29c3151fa6b06ce6ab1dea1d420fa26fe89d81 [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
Nicolas "Pixel" Noble1f8b6da2016-04-29 20:00:43 +02008well_known_protos = %w[
9 google/protobuf/any.proto
10 google/protobuf/api.proto
11 google/protobuf/duration.proto
12 google/protobuf/empty.proto
13 google/protobuf/field_mask.proto
14 google/protobuf/source_context.proto
15 google/protobuf/struct.proto
16 google/protobuf/timestamp.proto
17 google/protobuf/type.proto
18 google/protobuf/wrappers.proto
19]
20
21# These are omitted for now because we don't support proto2.
22proto2_protos = %w[
23 google/protobuf/descriptor.proto
24 google/protobuf/compiler/plugin.proto
25]
26
27genproto_output = []
28
Nicolas "Pixel" Noble236b9392016-04-30 02:14:18 +020029# We won't have access to .. from within docker, but the proto files
30# will be there, thanks to the :genproto rule dependency for gem:native.
Nicolas "Pixel" Noble1f8b6da2016-04-29 20:00:43 +020031unless ENV['IN_DOCKER'] == 'true'
32 well_known_protos.each do |proto_file|
33 input_file = "../src/" + proto_file
Colin Crossdc384472018-11-04 17:34:26 -080034 output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb")
Nicolas "Pixel" Noble1f8b6da2016-04-29 20:00:43 +020035 genproto_output << output_file
36 file output_file => input_file do |file_task|
37 sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
38 end
39 end
40end
41
Isaiah Peng27e2b572014-12-24 15:48:41 +010042if RUBY_PLATFORM == "java"
Adam Greened55733c2015-05-01 11:54:29 -070043 if `which mvn` == ''
44 raise ArgumentError, "maven needs to be installed"
45 end
Isaiah Peng27e2b572014-12-24 15:48:41 +010046 task :clean do
Colin Crossdc384472018-11-04 17:34:26 -080047 system("mvn clean")
Isaiah Peng27e2b572014-12-24 15:48:41 +010048 end
49
50 task :compile do
Colin Crossdc384472018-11-04 17:34:26 -080051 system("mvn package")
Isaiah Peng27e2b572014-12-24 15:48:41 +010052 end
53else
54 Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
55 ext.ext_dir = "ext/google/protobuf_c"
56 ext.lib_dir = "lib/google"
Nicolas "Pixel" Noblebbb188a2016-02-06 00:55:45 +010057 ext.cross_compile = true
58 ext.cross_platform = [
59 'x86-mingw32', 'x64-mingw32',
60 'x86_64-linux', 'x86-linux',
61 'universal-darwin'
62 ]
Isaiah Peng27e2b572014-12-24 15:48:41 +010063 end
Josh Habermanaf4aa9b2016-02-04 10:44:22 -080064
65 task 'gem:windows' do
66 require 'rake_compiler_dock'
Colin Crossdc384472018-11-04 17:34:26 -080067 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"
Josh Habermanaf4aa9b2016-02-04 10:44:22 -080068 end
Isaiah Peng27e2b572014-12-24 15:48:41 +010069
Nicolas "Pixel" Noble236b9392016-04-30 02:14:18 +020070 if RUBY_PLATFORM =~ /darwin/
71 task 'gem:native' do
Nicolas "Pixel" Nobleedd29492016-05-04 02:29:17 +020072 system "rake genproto"
Colin Crossdc384472018-11-04 17:34:26 -080073 system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0"
Nicolas "Pixel" Noble236b9392016-04-30 02:14:18 +020074 end
75 else
76 task 'gem:native' => [:genproto, 'gem:windows']
77 end
Josh Haberman513875d2016-03-03 14:08:54 -080078end
79
80
81# Proto for tests.
82genproto_output << "tests/generated_code.rb"
Josh Haberman513875d2016-03-03 14:08:54 -080083file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
84 sh "../src/protoc --ruby_out=. tests/generated_code.proto"
85end
86
Josh Haberman513875d2016-03-03 14:08:54 -080087task :genproto => genproto_output
88
89task :clean do
90 sh "rm -f #{genproto_output.join(' ')}"
91end
92
Isaiah Peng27e2b572014-12-24 15:48:41 +010093Gem::PackageTask.new(spec) do |pkg|
Chris Fallin973f4252014-11-18 14:19:58 -080094end
95
96Rake::TestTask.new(:test => :build) do |t|
Colin Crossdc384472018-11-04 17:34:26 -080097 t.test_files = FileList["tests/*.rb"]
Chris Fallin973f4252014-11-18 14:19:58 -080098end
99
Josh Haberman513875d2016-03-03 14:08:54 -0800100task :build => [:clean, :compile, :genproto]
Chris Fallin973f4252014-11-18 14:19:58 -0800101task :default => [:build]
102
103# vim:sw=2:et