Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 1 | require "rubygems" |
| 2 | require "rubygems/package_task" |
| 3 | require "rake/extensiontask" unless RUBY_PLATFORM == "java" |
| 4 | require "rake/testtask" |
| 5 | |
| 6 | spec = Gem::Specification.load("google-protobuf.gemspec") |
| 7 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 8 | well_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. |
| 22 | proto2_protos = %w[ |
| 23 | google/protobuf/descriptor.proto |
| 24 | google/protobuf/compiler/plugin.proto |
| 25 | ] |
| 26 | |
| 27 | genproto_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. |
| 31 | unless 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 |
| 40 | end |
| 41 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 42 | if RUBY_PLATFORM == "java" |
| 43 | if `which mvn` == '' |
| 44 | raise ArgumentError, "maven needs to be installed" |
| 45 | end |
| 46 | task :clean do |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 47 | system("mvn --batch-mode clean") |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 48 | end |
| 49 | |
| 50 | task :compile do |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 51 | system("mvn --batch-mode package") |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 52 | end |
| 53 | else |
| 54 | Rake::ExtensionTask.new("protobuf_c", spec) do |ext| |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 55 | 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 Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 61 | 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 Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 73 | 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 Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 74 | end |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 75 | |
| 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 |
| 84 | end |
| 85 | |
| 86 | |
| 87 | # Proto for tests. |
| 88 | genproto_output << "tests/generated_code.rb" |
| 89 | genproto_output << "tests/test_import.rb" |
| 90 | genproto_output << "tests/test_ruby_package.rb" |
| 91 | file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| |
| 92 | sh "../src/protoc --ruby_out=. tests/generated_code.proto" |
| 93 | end |
| 94 | |
| 95 | file "tests/test_import.rb" => "tests/test_import.proto" do |file_task| |
| 96 | sh "../src/protoc --ruby_out=. tests/test_import.proto" |
| 97 | end |
| 98 | |
| 99 | file "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task| |
| 100 | sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto" |
| 101 | end |
| 102 | |
| 103 | task :genproto => genproto_output |
| 104 | |
| 105 | task :clean do |
| 106 | sh "rm -f #{genproto_output.join(' ')}" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 107 | end |
| 108 | |
| 109 | Gem::PackageTask.new(spec) do |pkg| |
| 110 | end |
| 111 | |
| 112 | Rake::TestTask.new(:test => :build) do |t| |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 113 | t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb") |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 114 | end |
| 115 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 116 | # gc_test needs to be split out to ensure the generated file hasn't been |
| 117 | # imported by other tests. |
| 118 | Rake::TestTask.new(:gc_test => :build) do |t| |
| 119 | t.test_files = FileList["tests/gc_test.rb"] |
| 120 | end |
| 121 | |
| 122 | task :build => [:clean, :compile, :genproto] |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 123 | task :default => [:build] |
| 124 | |
| 125 | # vim:sw=2:et |