Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 1 | require "rubygems" |
| 2 | require "rubygems/package_task" |
| 3 | require "rake/extensiontask" unless RUBY_PLATFORM == "java" |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 4 | require "rake/testtask" |
| 5 | |
Chris Fallin | 91473dc | 2014-12-12 15:58:26 -0800 | [diff] [blame] | 6 | spec = Gem::Specification.load("google-protobuf.gemspec") |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 7 | |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [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 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 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. |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 31 | unless ENV['IN_DOCKER'] == 'true' |
| 32 | well_known_protos.each do |proto_file| |
| 33 | input_file = "../src/" + proto_file |
Josh Haberman | 4f19797 | 2016-07-25 01:47:50 -0700 | [diff] [blame] | 34 | output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb") |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 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 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 42 | if RUBY_PLATFORM == "java" |
Adam Greene | d55733c | 2015-05-01 11:54:29 -0700 | [diff] [blame] | 43 | if `which mvn` == '' |
| 44 | raise ArgumentError, "maven needs to be installed" |
| 45 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 46 | task :clean do |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 47 | system("mvn --batch-mode clean") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 48 | end |
| 49 | |
| 50 | task :compile do |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 51 | system("mvn --batch-mode package") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 52 | end |
| 53 | else |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame^] | 54 | unless ENV['IN_DOCKER'] == 'true' |
| 55 | # We need wyhash in-tree. |
| 56 | FileUtils.mkdir_p("ext/google/protobuf_c/third_party/wyhash") |
| 57 | FileUtils.cp("../third_party/wyhash/wyhash.h", "ext/google/protobuf_c/third_party/wyhash/wyhash.h") |
| 58 | end |
| 59 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 60 | Rake::ExtensionTask.new("protobuf_c", spec) do |ext| |
Jisi Liu | 9972e16 | 2018-04-25 09:52:30 -0700 | [diff] [blame] | 61 | unless RUBY_PLATFORM =~ /darwin/ |
| 62 | # TODO: also set "no_native to true" for mac if possible. As is, |
| 63 | # "no_native" can only be set if the RUBY_PLATFORM doing |
| 64 | # cross-compilation is contained in the "ext.cross_platform" array. |
| 65 | ext.no_native = true |
| 66 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 67 | ext.ext_dir = "ext/google/protobuf_c" |
| 68 | ext.lib_dir = "lib/google" |
Nicolas "Pixel" Noble | bbb188a | 2016-02-06 00:55:45 +0100 | [diff] [blame] | 69 | ext.cross_compile = true |
| 70 | ext.cross_platform = [ |
| 71 | 'x86-mingw32', 'x64-mingw32', |
| 72 | 'x86_64-linux', 'x86-linux', |
| 73 | 'universal-darwin' |
| 74 | ] |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 75 | end |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 76 | |
| 77 | task 'gem:windows' do |
| 78 | require 'rake_compiler_dock' |
Masaki Hara | 64f6c59 | 2020-04-17 15:31:47 +0900 | [diff] [blame] | 79 | ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| |
| 80 | RakeCompilerDock.sh <<-"EOT", platform: plat |
| 81 | bundle && \ |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame^] | 82 | IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 |
Masaki Hara | 64f6c59 | 2020-04-17 15:31:47 +0900 | [diff] [blame] | 83 | EOT |
| 84 | end |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 85 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 86 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 87 | if RUBY_PLATFORM =~ /darwin/ |
| 88 | task 'gem:native' do |
Nicolas "Pixel" Noble | edd2949 | 2016-05-04 02:29:17 +0200 | [diff] [blame] | 89 | system "rake genproto" |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame^] | 90 | system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 91 | end |
| 92 | else |
| 93 | task 'gem:native' => [:genproto, 'gem:windows'] |
| 94 | end |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 95 | end |
| 96 | |
| 97 | |
| 98 | # Proto for tests. |
| 99 | genproto_output << "tests/generated_code.rb" |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 100 | genproto_output << "tests/generated_code_proto2.rb" |
Josh Haberman | 6d92233 | 2016-07-25 00:29:47 -0700 | [diff] [blame] | 101 | genproto_output << "tests/test_import.rb" |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 102 | genproto_output << "tests/test_import_proto2.rb" |
Paul Yang | 9ccc3e5 | 2018-05-17 17:11:06 -0700 | [diff] [blame] | 103 | genproto_output << "tests/test_ruby_package.rb" |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 104 | genproto_output << "tests/test_ruby_package_proto2.rb" |
| 105 | genproto_output << "tests/basic_test.rb" |
| 106 | genproto_output << "tests/basic_test_proto2.rb" |
Joe Bolinger | e4bbca1 | 2019-03-27 09:44:43 -0700 | [diff] [blame] | 107 | genproto_output << "tests/wrappers.rb" |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 108 | file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| |
| 109 | sh "../src/protoc --ruby_out=. tests/generated_code.proto" |
| 110 | end |
| 111 | |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 112 | file "tests/generated_code_proto2.rb" => "tests/generated_code_proto2.proto" do |file_task| |
| 113 | sh "../src/protoc --ruby_out=. tests/generated_code_proto2.proto" |
| 114 | end |
| 115 | |
Josh Haberman | 6d92233 | 2016-07-25 00:29:47 -0700 | [diff] [blame] | 116 | file "tests/test_import.rb" => "tests/test_import.proto" do |file_task| |
| 117 | sh "../src/protoc --ruby_out=. tests/test_import.proto" |
| 118 | end |
| 119 | |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 120 | file "tests/test_import_proto2.rb" => "tests/test_import_proto2.proto" do |file_task| |
| 121 | sh "../src/protoc --ruby_out=. tests/test_import_proto2.proto" |
| 122 | end |
| 123 | |
Paul Yang | 9ccc3e5 | 2018-05-17 17:11:06 -0700 | [diff] [blame] | 124 | file "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task| |
| 125 | sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto" |
| 126 | end |
| 127 | |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 128 | file "tests/test_ruby_package_proto2.rb" => "tests/test_ruby_package_proto2.proto" do |file_task| |
| 129 | sh "../src/protoc --ruby_out=. tests/test_ruby_package_proto2.proto" |
| 130 | end |
| 131 | |
| 132 | file "tests/basic_test.rb" => "tests/basic_test.proto" do |file_task| |
Joshua Haberman | 6b75968 | 2020-04-23 12:54:25 -0700 | [diff] [blame] | 133 | sh "../src/protoc --experimental_allow_proto3_optional -I../src -I. --ruby_out=. tests/basic_test.proto" |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 134 | end |
| 135 | |
| 136 | file "tests/basic_test_proto2.rb" => "tests/basic_test_proto2.proto" do |file_task| |
Joe Bolinger | 7f14ea9 | 2019-02-27 20:26:14 -0800 | [diff] [blame] | 137 | sh "../src/protoc -I../src -I. --ruby_out=. tests/basic_test_proto2.proto" |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 138 | end |
| 139 | |
Joe Bolinger | e4bbca1 | 2019-03-27 09:44:43 -0700 | [diff] [blame] | 140 | file "tests/wrappers.rb" => "../src/google/protobuf/wrappers.proto" do |file_task| |
| 141 | sh "../src/protoc -I../src -I. --ruby_out=tests ../src/google/protobuf/wrappers.proto" |
| 142 | end |
| 143 | |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 144 | task :genproto => genproto_output |
| 145 | |
| 146 | task :clean do |
| 147 | sh "rm -f #{genproto_output.join(' ')}" |
| 148 | end |
| 149 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 150 | Gem::PackageTask.new(spec) do |pkg| |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 151 | end |
| 152 | |
| 153 | Rake::TestTask.new(:test => :build) do |t| |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 154 | t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb", "tests/common_tests.rb") |
Paul Yang | cd5f49d | 2017-10-03 17:28:49 -0700 | [diff] [blame] | 155 | end |
| 156 | |
| 157 | # gc_test needs to be split out to ensure the generated file hasn't been |
| 158 | # imported by other tests. |
| 159 | Rake::TestTask.new(:gc_test => :build) do |t| |
| 160 | t.test_files = FileList["tests/gc_test.rb"] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 161 | end |
| 162 | |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 163 | task :build => [:clean, :compile, :genproto] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 164 | task :default => [:build] |
| 165 | |
| 166 | # vim:sw=2:et |