build_ruby_environment_macos.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. set -ex
  16. rm -rf ~/.rake-compiler
  17. CROSS_RUBY="$(pwd)/$(mktemp tmpfile.XXXXXXXX)"
  18. curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/v1.1.1/tasks/bin/cross-ruby.rake > "$CROSS_RUBY"
  19. # See https://github.com/grpc/grpc/issues/12161 for verconf.h patch details
  20. patch "$CROSS_RUBY" << EOF
  21. --- cross-ruby.rake 2021-03-05 12:04:09.898286632 -0800
  22. +++ patched 2021-03-05 12:05:35.594318962 -0800
  23. @@ -111,10 +111,11 @@
  24. "--host=#{MINGW_HOST}",
  25. "--target=#{MINGW_TARGET}",
  26. "--build=#{RUBY_BUILD}",
  27. - '--enable-shared',
  28. + '--enable-static',
  29. + '--disable-shared',
  30. '--disable-install-doc',
  31. + '--without-gmp',
  32. '--with-ext=',
  33. - 'LDFLAGS=-pipe -s',
  34. ]
  35. # Force Winsock2 for Ruby 1.8, 1.9 defaults to it
  36. @@ -130,6 +131,7 @@
  37. # make
  38. file "#{build_dir}/ruby.exe" => ["#{build_dir}/Makefile"] do |t|
  39. chdir File.dirname(t.prerequisites.first) do
  40. + sh "test -s verconf.h || rm -f verconf.h" # if verconf.h has size 0, make sure it gets re-built by make
  41. sh MAKE
  42. end
  43. end
  44. EOF
  45. MAKE="make -j8"
  46. # Install ruby 3.0.0 for rake-compiler
  47. # Download ruby 3.0.0 sources outside of the cross-ruby.rake file, since the
  48. # latest rake-compiler/v1.1.1 cross-ruby.rake file requires tar.bz2 source
  49. # files.
  50. # TODO(apolcyn): remove this hack when tar.bz2 sources are available for ruby
  51. # 3.0.0 in https://ftp.ruby-lang.org/pub/ruby/3.0/. Also see
  52. # https://stackoverflow.com/questions/65477613/rvm-where-is-ruby-3-0-0.
  53. set +x # rvm commands are very verbose
  54. source ~/.rvm/scripts/rvm
  55. echo "rvm use 3.0.0"
  56. rvm use 3.0.0
  57. set -x
  58. RUBY_3_0_0_TAR="${HOME}/.rake-compiler/sources/ruby-3.0.0.tar.gz"
  59. mkdir -p "$(dirname $RUBY_3_0_0_TAR)"
  60. curl -L "https://ftp.ruby-lang.org/pub/ruby/3.0/$(basename $RUBY_3_0_0_TAR)" -o "$RUBY_3_0_0_TAR"
  61. ccache -c
  62. ruby --version | grep 'ruby 3.0.0'
  63. tools/run_tests/helper_scripts/bundle_install_wrapper.sh
  64. bundle exec rake -f "$CROSS_RUBY" cross-ruby VERSION=3.0.0 HOST=x86_64-darwin11 MAKE="$MAKE" SOURCE="$RUBY_3_0_0_TAR"
  65. echo "installed ruby 3.0.0 build targets"
  66. # Install ruby 2.7.0 for rake-compiler
  67. set +x
  68. echo "rvm use 2.7.0"
  69. rvm use 2.7.0
  70. set -x
  71. ruby --version | grep 'ruby 2.7.0'
  72. ccache -c
  73. tools/run_tests/helper_scripts/bundle_install_wrapper.sh
  74. bundle exec rake -f "$CROSS_RUBY" cross-ruby VERSION=2.7.0 HOST=x86_64-darwin11 MAKE="$MAKE"
  75. echo "installed ruby 2.7.0 build targets"
  76. # Install ruby 2.4-2.6 for rake-compiler
  77. set +x
  78. echo "rvm use 2.5.0"
  79. rvm use 2.5.0
  80. set -x
  81. ruby --version | grep 'ruby 2.5.0'
  82. for v in 2.6.0 2.5.0 2.4.0 ; do
  83. ccache -c
  84. tools/run_tests/helper_scripts/bundle_install_wrapper.sh
  85. bundle exec rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin11 MAKE="$MAKE"
  86. echo "installed ruby $v build targets"
  87. done
  88. sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yml > "$CROSS_RUBY"
  89. mv "$CROSS_RUBY" ~/.rake-compiler/config.yml