From e6ce3de7dda791e74ebf1278e654ccef2cdf4313 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 20 Sep 2020 11:11:02 -0400 Subject: [PATCH 1/3] dev: ignore mac-specific files --- .gitignore | 1 + .hoerc | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d8ece1227e..f33cb22c36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store *.gemspec *.tmproj *~ diff --git a/.hoerc b/.hoerc index 21b93e7b13..e0e7af8011 100644 --- a/.hoerc +++ b/.hoerc @@ -6,6 +6,7 @@ exclude: !ruby/regexp '/ \.github| \.vagrant| \.yardoc| + \.DS_Store| concourse| gems| patches| From b134f8aa95a4576344d0cb47fd0258a325813a4a Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 20 Sep 2020 11:09:30 -0400 Subject: [PATCH 2/3] gem(native): assert on rubygems native darwin platforms related to #2079 --- test/test_gem_platform.rb | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/test_gem_platform.rb diff --git a/test/test_gem_platform.rb b/test/test_gem_platform.rb new file mode 100644 index 0000000000..f6383ef65b --- /dev/null +++ b/test/test_gem_platform.rb @@ -0,0 +1,69 @@ +require "helper" + +class TestGemPlatform < Nokogiri::TestCase + # These tests were written to help me better understand the behavior + # of Rubygems's platform-matching behavior. They don't exercise code + # in Nokogiri, but do express the expectations we have of Rubygems + # and `gem install` behavior for our native darwin gem. + # + # More specifically, the grpc gem ships a native darwin gem with + # platform string `universal-darwin` which I *think* refers to the + # fact that it supports i386-and-x86_64 architectures (and not that + # it supports x86_64-and-arm64 architectures). + # + # With ARM support imminent [1] I'm a little worried about using + # `universal` until I understand better whether ARM support will be + # implied by `universal` or `universal2` or what. From + # https://en.wikipedia.org/wiki/Universal_binary: + # + # > The new Universal 2 binary format was introduced at the 2020 + # > Worldwide Developers Conference. Universal 2 allows applications + # > to run on both Intel x86-64-based and ARM64-based Macintosh + # > computers, for the Mac transition to Apple Silicon. + # + # [1]: https://arstechnica.com/gadgets/2020/06/this-is-apples-roadmap-for-moving-the-first-macs-away-from-intel/ + # + # There seems to be a lot of uncertainty right now, so I'm writing + # some tests to express my expectations, and we're gonig to + # conservatively use `x86_64-darwin` as the platform name for the + # native gem. + let(:darwin_gem_platform) { Gem::Platform.new("x86_64-darwin") } + + describe "darwin" do + it "builds a gem that works on all darwin x86+64 platforms" do + assert_match darwin_gem_platform, + Gem::Platform.new(["universal", "darwin", "19"]), + "gem should match system-installed ruby on catalina" + assert_match darwin_gem_platform, + Gem::Platform.new(["x86_64", "darwin", "19"]), + "gem should match user-installed ruby on catalina" + assert_match darwin_gem_platform, + Gem::Platform.new(["x86_64", "darwin", "18"]), + "gem should match user-installed ruby on mojave" + + # The intention here is to test that the x86_64 platform gems + # won't match a future ruby that is compiled on arm64/aarch64. + # + # I don't know what the future platform will call itself, but at + # least one of these should be right and none of them should + # match, so here are all the tests I can reasonably imagine. + # + # Feel free to delete assertions for clarity once we know more. + assert_no_match darwin_gem_platform, + Gem::Platform.new(["arm64", "darwin", "19"]), + "gem should not match an arm64 ruby" + assert_no_match darwin_gem_platform, + Gem::Platform.new(["arm", "darwin", "19"]), + "gem should not match an arm ruby" + assert_no_match darwin_gem_platform, + Gem::Platform.new(["aarch64", "darwin", "19"]), + "gem should not match an aarch64 ruby" + assert_no_match darwin_gem_platform, + Gem::Platform.new(["universal2", "darwin", "19"]), + "gem should not match an aarch64 ruby" + assert_no_match darwin_gem_platform, + Gem::Platform.new(["universal_2", "darwin", "19"]), + "gem should not match an aarch64 ruby" + end + end +end From a7e93f15fb5af05230cdc996de581d855fe2da70 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 13 Sep 2020 12:13:06 -0400 Subject: [PATCH 3/3] gem(native): package a gem that supports all darwin versions related to #2079 --- .cross_rubies | 8 ++++---- rakelib/cross-ruby.rake | 12 ++++++------ scripts/setup-osx-native-builders | 14 +++++++++----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.cross_rubies b/.cross_rubies index eecbd327e0..f9828f42a8 100644 --- a/.cross_rubies +++ b/.cross_rubies @@ -2,19 +2,19 @@ 2.7.0:x86_64-w64-mingw32 2.7.0:i686-linux-gnu 2.7.0:x86_64-linux-gnu -2.7.0:x86_64-darwin19 +2.7.0:x86_64-darwin 2.6.0:i686-w64-mingw32 2.6.0:x86_64-w64-mingw32 2.6.0:i686-linux-gnu 2.6.0:x86_64-linux-gnu -2.6.0:x86_64-darwin19 +2.6.0:x86_64-darwin 2.5.0:i686-w64-mingw32 2.5.0:x86_64-w64-mingw32 2.5.0:i686-linux-gnu 2.5.0:x86_64-linux-gnu -2.5.0:x86_64-darwin19 +2.5.0:x86_64-darwin 2.4.0:i686-w64-mingw32 2.4.0:x86_64-w64-mingw32 2.4.0:i686-linux-gnu 2.4.0:x86_64-linux-gnu -2.4.0:x86_64-darwin19 +2.4.0:x86_64-darwin diff --git a/rakelib/cross-ruby.rake b/rakelib/cross-ruby.rake index 9b91898f67..2a6d7dfc65 100644 --- a/rakelib/cross-ruby.rake +++ b/rakelib/cross-ruby.rake @@ -46,8 +46,8 @@ CrossRuby = Struct.new(:version, :host) do "x86_64-linux" when /\Ai[3-6]86.*linux/ "x86-linux" - when /\Ax86_64-darwin19/ - "x86_64-darwin19" + when /\Ax86_64-darwin/ + "x86_64-darwin" else raise "CrossRuby.platform: unsupported host: #{host}" end @@ -63,8 +63,8 @@ CrossRuby = Struct.new(:version, :host) do "x86_64-linux-gnu-" when "x86-linux" "i686-linux-gnu-" - when /darwin/ - "" + # when /darwin/ + # "" else raise "CrossRuby.tool: unmatched platform: #{platform}" end) + name @@ -80,8 +80,8 @@ CrossRuby = Struct.new(:version, :host) do "elf64-x86-64" when "x86-linux" "elf32-i386" - when "x86_64-darwin19" - "Mach-O 64-bit x86-64" + when "x86_64-darwin" + "Mach-O 64-bit x86-64" # hmm else raise "CrossRuby.target_file_format: unmatched platform: #{platform}" end diff --git a/scripts/setup-osx-native-builders b/scripts/setup-osx-native-builders index bc276fe061..9dc8e3c822 100755 --- a/scripts/setup-osx-native-builders +++ b/scripts/setup-osx-native-builders @@ -4,6 +4,9 @@ # - https://github.com/rake-compiler/rake-compiler/blob/master/tasks/bin/cross-ruby.rake # - https://github.com/apolcyn/grpc/blob/master/tools/distrib/build_ruby_environment_macos.sh +# see test/test_gem_platform.rb for context +gem_platform_name="x86_64-darwin" + # chosen so chruby will see it, should you be a user of chruby RUBIES_DIR=${HOME}/.rubies @@ -18,11 +21,12 @@ set -o pipefail CROSS_FILE=".cross_rubies" RUBIES=$(cat $CROSS_FILE | fgrep darwin | cut -d. -f1,2 | sort -u) + RAKE_COMPILER_CONFIG_DIR=${HOME}/.rake-compiler RAKE_COMPILER_CONFIG=${RAKE_COMPILER_CONFIG_DIR}/config.yml +TMP_CONFIG=$(mktemp /tmp/rake-compiler-config.XXXXXXXX) -mkdir -p $RAKE_COMPILER_CONFIG_DIR -echo "---" > $RAKE_COMPILER_CONFIG +echo "---" > $TMP_CONFIG for ruby in $RUBIES ; do ruby_fullname="native-builder-${ruby}" @@ -42,9 +46,9 @@ for ruby in $RUBIES ; do echo "ruby $ruby_fullname is installed" fi - platform=$(basename $(dirname $rbconfig)) - - echo "rbconfig-${platform}-${ruby_minor}: \"${rbconfig}\"" >> $RAKE_COMPILER_CONFIG + echo "rbconfig-${gem_platform_name}-${ruby_minor}: \"${rbconfig}\"" >> $TMP_CONFIG done +mkdir -p $RAKE_COMPILER_CONFIG_DIR +cp $TMP_CONFIG $RAKE_COMPILER_CONFIG cat $RAKE_COMPILER_CONFIG