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 |
Joshua Haberman | 16e16eb | 2021-07-31 11:13:08 -0700 | [diff] [blame^] | 11 | google/protobuf/descriptor.proto |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 12 | google/protobuf/duration.proto |
| 13 | google/protobuf/empty.proto |
| 14 | google/protobuf/field_mask.proto |
| 15 | google/protobuf/source_context.proto |
| 16 | google/protobuf/struct.proto |
| 17 | google/protobuf/timestamp.proto |
| 18 | google/protobuf/type.proto |
| 19 | google/protobuf/wrappers.proto |
| 20 | ] |
| 21 | |
Joshua Haberman | dd69a48 | 2021-05-17 22:40:33 -0700 | [diff] [blame] | 22 | test_protos = %w[ |
| 23 | tests/basic_test.proto |
| 24 | tests/basic_test_proto2.proto |
| 25 | tests/generated_code.proto |
| 26 | tests/generated_code_proto2.proto |
| 27 | tests/multi_level_nesting_test.proto |
| 28 | tests/test_import.proto |
| 29 | tests/test_import_proto2.proto |
| 30 | tests/test_ruby_package.proto |
| 31 | tests/test_ruby_package_proto2.proto |
| 32 | ] |
| 33 | |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 34 | # These are omitted for now because we don't support proto2. |
| 35 | proto2_protos = %w[ |
| 36 | google/protobuf/descriptor.proto |
| 37 | google/protobuf/compiler/plugin.proto |
| 38 | ] |
| 39 | |
James D | 68cb69e | 2021-04-12 13:06:44 -0400 | [diff] [blame] | 40 | if system('../src/protoc --version') |
| 41 | protoc_command = '../src/protoc' |
| 42 | else |
| 43 | protoc_command = 'protoc' |
| 44 | end |
| 45 | |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 46 | genproto_output = [] |
| 47 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 48 | # We won't have access to .. from within docker, but the proto files |
| 49 | # 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] | 50 | unless ENV['IN_DOCKER'] == 'true' |
| 51 | well_known_protos.each do |proto_file| |
| 52 | input_file = "../src/" + proto_file |
Josh Haberman | 4f19797 | 2016-07-25 01:47:50 -0700 | [diff] [blame] | 53 | output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb") |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 54 | genproto_output << output_file |
| 55 | file output_file => input_file do |file_task| |
James D | 68cb69e | 2021-04-12 13:06:44 -0400 | [diff] [blame] | 56 | sh "#{protoc_command} -I../src --ruby_out=lib #{input_file}" |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 57 | end |
| 58 | end |
Joshua Haberman | dd69a48 | 2021-05-17 22:40:33 -0700 | [diff] [blame] | 59 | |
| 60 | test_protos.each do |proto_file| |
| 61 | output_file = proto_file.sub(/\.proto$/, "_pb.rb") |
| 62 | genproto_output << output_file |
| 63 | file output_file => proto_file do |file_task| |
| 64 | sh "#{protoc_command} -I../src -I. --ruby_out=. #{proto_file}" |
| 65 | end |
| 66 | end |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 67 | end |
| 68 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 69 | if RUBY_PLATFORM == "java" |
Adam Greene | d55733c | 2015-05-01 11:54:29 -0700 | [diff] [blame] | 70 | if `which mvn` == '' |
| 71 | raise ArgumentError, "maven needs to be installed" |
| 72 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 73 | task :clean do |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 74 | system("mvn --batch-mode clean") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 75 | end |
| 76 | |
| 77 | task :compile do |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 78 | system("mvn --batch-mode package") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 79 | end |
| 80 | else |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame] | 81 | unless ENV['IN_DOCKER'] == 'true' |
| 82 | # We need wyhash in-tree. |
| 83 | FileUtils.mkdir_p("ext/google/protobuf_c/third_party/wyhash") |
| 84 | FileUtils.cp("../third_party/wyhash/wyhash.h", "ext/google/protobuf_c/third_party/wyhash/wyhash.h") |
| 85 | end |
| 86 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 87 | Rake::ExtensionTask.new("protobuf_c", spec) do |ext| |
Jisi Liu | 9972e16 | 2018-04-25 09:52:30 -0700 | [diff] [blame] | 88 | unless RUBY_PLATFORM =~ /darwin/ |
| 89 | # TODO: also set "no_native to true" for mac if possible. As is, |
| 90 | # "no_native" can only be set if the RUBY_PLATFORM doing |
| 91 | # cross-compilation is contained in the "ext.cross_platform" array. |
| 92 | ext.no_native = true |
| 93 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 94 | ext.ext_dir = "ext/google/protobuf_c" |
| 95 | ext.lib_dir = "lib/google" |
Nicolas "Pixel" Noble | bbb188a | 2016-02-06 00:55:45 +0100 | [diff] [blame] | 96 | ext.cross_compile = true |
| 97 | ext.cross_platform = [ |
| 98 | 'x86-mingw32', 'x64-mingw32', |
| 99 | 'x86_64-linux', 'x86-linux', |
| 100 | 'universal-darwin' |
| 101 | ] |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 102 | end |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 103 | |
| 104 | task 'gem:windows' do |
| 105 | require 'rake_compiler_dock' |
Masaki Hara | 64f6c59 | 2020-04-17 15:31:47 +0900 | [diff] [blame] | 106 | ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| |
| 107 | RakeCompilerDock.sh <<-"EOT", platform: plat |
| 108 | bundle && \ |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame] | 109 | 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] | 110 | EOT |
| 111 | end |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 112 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 113 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 114 | if RUBY_PLATFORM =~ /darwin/ |
| 115 | task 'gem:native' do |
Nicolas "Pixel" Noble | edd2949 | 2016-05-04 02:29:17 +0200 | [diff] [blame] | 116 | system "rake genproto" |
Joshua Haberman | 9abf6e2 | 2021-01-13 12:16:25 -0800 | [diff] [blame] | 117 | 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] | 118 | end |
| 119 | else |
| 120 | task 'gem:native' => [:genproto, 'gem:windows'] |
| 121 | end |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 122 | end |
| 123 | |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 124 | task :genproto => genproto_output |
| 125 | |
| 126 | task :clean do |
| 127 | sh "rm -f #{genproto_output.join(' ')}" |
| 128 | end |
| 129 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 130 | Gem::PackageTask.new(spec) do |pkg| |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 131 | end |
| 132 | |
Joshua Haberman | dd69a48 | 2021-05-17 22:40:33 -0700 | [diff] [blame] | 133 | Rake::TestTask.new(:test => [:build, :genproto]) do |t| |
Harshit Chopra | d0535cc | 2017-08-25 12:11:15 -0700 | [diff] [blame] | 134 | 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] | 135 | end |
| 136 | |
| 137 | # gc_test needs to be split out to ensure the generated file hasn't been |
| 138 | # imported by other tests. |
| 139 | Rake::TestTask.new(:gc_test => :build) do |t| |
| 140 | t.test_files = FileList["tests/gc_test.rb"] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 141 | end |
| 142 | |
Joshua Haberman | dd69a48 | 2021-05-17 22:40:33 -0700 | [diff] [blame] | 143 | task :build => [:clean, :genproto, :compile] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 144 | task :default => [:build] |
| 145 | |
| 146 | # vim:sw=2:et |