blob: 013bc99a404ace6d7cb3245ad3230c8aef985400 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001require "rubygems"
2require "rubygems/package_task"
3require "rake/extensiontask" unless RUBY_PLATFORM == "java"
4require "rake/testtask"
5
6spec = Gem::Specification.load("google-protobuf.gemspec")
7
Austin Schuh40c16522018-10-28 20:27:54 -07008well_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
29# 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.
31unless ENV['IN_DOCKER'] == 'true'
32 well_known_protos.each do |proto_file|
33 input_file = "../src/" + proto_file
34 output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
35 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
Brian Silverman9c614bc2016-02-15 20:20:02 -050042if RUBY_PLATFORM == "java"
43 if `which mvn` == ''
44 raise ArgumentError, "maven needs to be installed"
45 end
46 task :clean do
Austin Schuh40c16522018-10-28 20:27:54 -070047 system("mvn --batch-mode clean")
Brian Silverman9c614bc2016-02-15 20:20:02 -050048 end
49
50 task :compile do
Austin Schuh40c16522018-10-28 20:27:54 -070051 system("mvn --batch-mode package")
Brian Silverman9c614bc2016-02-15 20:20:02 -050052 end
53else
54 Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
Austin Schuh40c16522018-10-28 20:27:54 -070055 unless RUBY_PLATFORM =~ /darwin/
56 # TODO: also set "no_native to true" for mac if possible. As is,
57 # "no_native" can only be set if the RUBY_PLATFORM doing
58 # cross-compilation is contained in the "ext.cross_platform" array.
59 ext.no_native = true
60 end
Brian Silverman9c614bc2016-02-15 20:20:02 -050061 ext.ext_dir = "ext/google/protobuf_c"
62 ext.lib_dir = "lib/google"
63 ext.cross_compile = true
64 ext.cross_platform = [
65 'x86-mingw32', 'x64-mingw32',
66 'x86_64-linux', 'x86-linux',
67 'universal-darwin'
68 ]
69 end
70
71 task 'gem:windows' do
72 require 'rake_compiler_dock'
Austin Schuh40c16522018-10-28 20:27:54 -070073 RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0"
Brian Silverman9c614bc2016-02-15 20:20:02 -050074 end
Austin Schuh40c16522018-10-28 20:27:54 -070075
76 if RUBY_PLATFORM =~ /darwin/
77 task 'gem:native' do
78 system "rake genproto"
79 system "rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0"
80 end
81 else
82 task 'gem:native' => [:genproto, 'gem:windows']
83 end
84end
85
86
87# Proto for tests.
88genproto_output << "tests/generated_code.rb"
89genproto_output << "tests/test_import.rb"
90genproto_output << "tests/test_ruby_package.rb"
91file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
92 sh "../src/protoc --ruby_out=. tests/generated_code.proto"
93end
94
95file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
96 sh "../src/protoc --ruby_out=. tests/test_import.proto"
97end
98
99file "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task|
100 sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto"
101end
102
103task :genproto => genproto_output
104
105task :clean do
106 sh "rm -f #{genproto_output.join(' ')}"
Brian Silverman9c614bc2016-02-15 20:20:02 -0500107end
108
109Gem::PackageTask.new(spec) do |pkg|
110end
111
112Rake::TestTask.new(:test => :build) do |t|
Austin Schuh40c16522018-10-28 20:27:54 -0700113 t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb")
Brian Silverman9c614bc2016-02-15 20:20:02 -0500114end
115
Austin Schuh40c16522018-10-28 20:27:54 -0700116# gc_test needs to be split out to ensure the generated file hasn't been
117# imported by other tests.
118Rake::TestTask.new(:gc_test => :build) do |t|
119 t.test_files = FileList["tests/gc_test.rb"]
120end
121
122task :build => [:clean, :compile, :genproto]
Brian Silverman9c614bc2016-02-15 20:20:02 -0500123task :default => [:build]
124
125# vim:sw=2:et