From bb696e22cf952b7a167ccaa339e9859ebdde7eff Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Sun, 3 Dec 2023 16:17:49 +0100 Subject: [PATCH 1/2] Test installation on ARM Mac --- .circleci/config.yml | 105 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a85416b..eac0bbb5 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -99,8 +99,8 @@ jobs: - restore_cache: name: restore ports cache keys: - - ports-<< parameters.ruby_version >>-{{ checksum ".ports_versions" }} - - ports-<< parameters.ruby_version >>- + - ports-<< parameters.ruby_version >>-{{ arch }}-{{ checksum ".ports_versions" }} + - ports-<< parameters.ruby_version >>-{{ arch }}- - run: name: compile ports @@ -126,7 +126,7 @@ jobs: name: save ports cache paths: - ./ports - key: ports-<< parameters.ruby_version >>-{{ checksum ".ports_versions" }} + key: ports-<< parameters.ruby_version >>-{{ arch }}-{{ arch }}-{{ checksum ".ports_versions" }} - store_test_results: path: test/reports @@ -155,9 +155,9 @@ jobs: - restore_cache: name: restore gem cache keys: - - v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} - - v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}- - - v1-bundle-<< parameters.ruby_version >>- + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}- + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}- - run: name: bundle install gems @@ -169,7 +169,7 @@ jobs: name: save gem cache paths: - ./vendor/bundle - key: v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + key: v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} - attach_workspace: at: artifacts @@ -261,8 +261,8 @@ jobs: - restore_cache: name: restore ports cache keys: - - ports-win-{{ checksum ".ports_versions" }} - - ports-win- + - ports-win-{{ arch }}-{{ checksum ".ports_versions" }} + - ports-win-{{ arch }}- - run: name: Build gem @@ -288,7 +288,7 @@ jobs: name: save ports cache paths: - ./ports - key: ports-win-{{ checksum ".ports_versions" }} + key: ports-win-{{ arch }}-{{ checksum ".ports_versions" }} - persist_to_workspace: name: save gems into workspace @@ -333,9 +333,9 @@ jobs: - restore_cache: name: restore gem cache keys: - - v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} - - v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}- - - v1-bundle-<< parameters.ruby_version >>- + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}- + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}- - run: name: bundle install gems @@ -347,7 +347,7 @@ jobs: name: save gem cache paths: - ./vendor/bundle - key: v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + key: v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} - run: name: build gem @@ -369,6 +369,72 @@ jobs: ruby -e "require 'tiny_tds'; puts TinyTds::Gem.root_path" exit $LASTEXITCODE + install_mac_silicon: + parameters: + ruby_version: + description: "version tag for rubydev environment" + type: string + + # the XCode version on Mac OS also determines the Mac OS version you get + # so for 15.0, we get 13.5.1 + macos: + xcode: "15.0.0" + resource_class: macos.m1.medium.gen1 + + steps: + - run: + name: Install rbenv and freetds from Homebrew + command: | + brew install freetds rbenv + + - run: + name: Install Ruby + command: | + latest_version=$(rbenv install --list-all | grep "<< parameters.ruby_version >>" | grep -v - | tail -1) + rbenv install --skip-existing $latest_version + rbenv global $latest_version + + - run: + name: Install bundler + command: | + gem install bundler -v 2.3.26 + + - checkout + + - restore_cache: + name: restore gem cache + keys: + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}- + - v1-bundle-<< parameters.ruby_version >>-{{ arch }}- + + - run: + name: bundle install gems + command: | + bundle install --path vendor/bundle + + - save_cache: + name: save gem cache + paths: + - ./vendor/bundle + key: v1-bundle-<< parameters.ruby_version >>-{{ arch }}-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }} + + - run: + name: build gem + command: | + gem build tiny_tds.gemspec + + - run: + name: Install gem + command: | + gemVersion=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' < VERSION) + gem install --local "tiny_tds-$gemVersion.gem" + + - run: + name: Check if gem loads correctly + command: | + ruby -e "require 'tiny_tds'; puts TinyTds::Gem.root_path" + workflows: test_supported_ruby_versions: jobs: @@ -405,3 +471,14 @@ workflows: - '3.0' - '3.1' - '3.2' + + - install_mac_silicon: + matrix: + parameters: + # Ruby 2.4 and Ruby 2.5 do not build on Silicon anymore + ruby_version: + - '2.6' + - '2.7' + - '3.0' + - '3.1' + - '3.2' From 8011a960c54720c7c092e65d579ef25886c76eba Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Sun, 3 Dec 2023 16:51:38 +0100 Subject: [PATCH 2/2] Add `/opt/homebrew` to search path on Apple Silicon This is default directory for Homebrew on Apple Silicon. Intel Mac installs into `/usr/local`, which is in our default path. Co-authored-by: Caleb Land --- CHANGELOG.md | 1 + ext/tiny_tds/extconf.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 394e1b3f..7350886c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix segfault when asking if client was dead after closing it. Fixes #519. * Mark `alloc` function as undefined on `TinyTds::Result`. Fixes #515. * Fix Gem installation on Windows by adding default freetds msys path. Fixes #522 +* Search for `freetds` in `/opt/homebrew` when installing on Apple Silicon. Fixes #484, #492 and #508. ## 2.1.5 diff --git a/ext/tiny_tds/extconf.rb b/ext/tiny_tds/extconf.rb index 9b7db299..47473d17 100644 --- a/ext/tiny_tds/extconf.rb +++ b/ext/tiny_tds/extconf.rb @@ -35,6 +35,19 @@ def do_help /usr/local ) +if RbConfig::CONFIG['host_os'] =~ /darwin/i + # Ruby below 2.7 seems to label the host CPU on Apple Silicon as aarch64 + # 2.7 and above print is as ARM64 + target_host_cpu = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7') ? 'aarch64' : 'arm64' + + if RbConfig::CONFIG['host_cpu'] == target_host_cpu + # Homebrew on Apple Silicon installs into /opt/hombrew + # https://docs.brew.sh/Installation + # On Intel Macs, it is /usr/local, so no changes necessary to DIRS + DIRS.unshift("/opt/homebrew") + end +end + if ENV["RI_DEVKIT"] && ENV["MINGW_PREFIX"] # RubyInstaller Support DIRS.unshift(File.join(ENV["RI_DEVKIT"], ENV["MINGW_PREFIX"])) end