• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2015 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -ex
17
18rm -rf ~/.rake-compiler
19
20CROSS_RUBY="$(pwd)/$(mktemp tmpfile.XXXXXXXX)"
21
22curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/v1.1.1/tasks/bin/cross-ruby.rake > "$CROSS_RUBY"
23
24# See https://github.com/grpc/grpc/issues/12161 for verconf.h patch details
25patch "$CROSS_RUBY" << EOF
26--- cross-ruby.rake	2021-03-05 12:04:09.898286632 -0800
27+++ patched	2021-03-05 12:05:35.594318962 -0800
28@@ -111,10 +111,11 @@
29     "--host=#{MINGW_HOST}",
30     "--target=#{MINGW_TARGET}",
31     "--build=#{RUBY_BUILD}",
32-    '--enable-shared',
33+    '--enable-static',
34+    '--disable-shared',
35     '--disable-install-doc',
36+    '--without-gmp',
37     '--with-ext=',
38-    'LDFLAGS=-pipe -s',
39   ]
40 
41   # Force Winsock2 for Ruby 1.8, 1.9 defaults to it
42@@ -130,6 +131,7 @@
43 # make
44 file "#{build_dir}/ruby.exe" => ["#{build_dir}/Makefile"] do |t|
45   chdir File.dirname(t.prerequisites.first) do
46+    sh "test -s verconf.h || rm -f verconf.h"  # if verconf.h has size 0, make sure it gets re-built by make
47     sh MAKE
48   end
49 end
50EOF
51
52MAKE="make -j8"
53
54# Install ruby 3.0.0 for rake-compiler
55# Download ruby 3.0.0 sources outside of the cross-ruby.rake file, since the
56# latest rake-compiler/v1.1.1 cross-ruby.rake file requires tar.bz2 source
57# files.
58# TODO(apolcyn): remove this hack when tar.bz2 sources are available for ruby
59# 3.0.0 in https://ftp.ruby-lang.org/pub/ruby/3.0/. Also see
60# https://stackoverflow.com/questions/65477613/rvm-where-is-ruby-3-0-0.
61set +x # rvm commands are very verbose
62source ~/.rvm/scripts/rvm
63echo "rvm use 3.0.0"
64rvm use 3.0.0
65set -x
66RUBY_3_0_0_TAR="${HOME}/.rake-compiler/sources/ruby-3.0.0.tar.gz"
67mkdir -p "$(dirname $RUBY_3_0_0_TAR)"
68curl -L "https://ftp.ruby-lang.org/pub/ruby/3.0/$(basename $RUBY_3_0_0_TAR)" -o "$RUBY_3_0_0_TAR"
69ccache -c
70ruby --version | grep 'ruby 3.0.0'
71rake -f "$CROSS_RUBY" cross-ruby VERSION=3.0.0 HOST=x86_64-darwin11 MAKE="$MAKE" SOURCE="$RUBY_3_0_0_TAR"
72echo "installed ruby 3.0.0 build targets"
73# Install ruby 2.7.0 for rake-compiler
74set +x
75echo "rvm use 2.7.0"
76rvm use 2.7.0
77set -x
78ruby --version | grep 'ruby 2.7.0'
79ccache -c
80rake -f "$CROSS_RUBY" cross-ruby VERSION=2.7.0 HOST=x86_64-darwin11 MAKE="$MAKE"
81echo "installed ruby 2.7.0 build targets"
82# Install ruby 2.4-2.6 for rake-compiler
83set +x
84echo "rvm use 2.5.0"
85rvm use 2.5.0
86set -x
87ruby --version | grep 'ruby 2.5.0'
88for v in 2.6.0 2.5.0 2.4.0 ; do
89  ccache -c
90  rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin11 MAKE="$MAKE"
91  echo "installed ruby $v build targets"
92done
93
94sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yml > "$CROSS_RUBY"
95mv "$CROSS_RUBY" ~/.rake-compiler/config.yml
96