How to add Mac-specific gems to bundle on Mac but not on Linux?
Gemfile actually is a regular ruby file, so you can use something like
case RUBY_PLATFORM
when /darwin/
gem 'foo'
when /win32/
gem 'bar'
end
Rails: Handling different gem versions for different operating systems
If anyone running into this. This was a known bug that was fixed in bundler version v2.2.11
From: How to change the version of bundler used in Cloud Functions deployment?
This is bundler's regression since bundler v2.2.8. https://github.com/rubygems/rubygems/issues/4366
Fix is here: https://github.com/rubygems/rubygems/pull/3655
How to clone a gem, fix it, add it to repo, bundle, and deploy with Rails
Steps
Fork the project under your account on Github
Make the changes you want
Use
gem 'gem_name', git: 'your_forked_project', branch: 'the_branch_you_working_on'
Run
bundle install
Bundler and Heroku with offline gems
Ok I figured out the issue. The Chilkat gem I'm using has OS-specific versions, and the version I unbundled in vendor/gems is for OSx won't work on Heroku/AWS. So even if the path would have worked correctly in Heroku, the gem itself would not.
The problem I face now is because the Chilkat gem is OS-specific, Bundler will generate a Gemfile.lock file specific to the OS on which bundle install was called (OSx in my case). That OSx-specific Gemfile.lock is incompatible with AWS's machines, so Heroku complains that I can't push the code since the Gemfile.lock is inconsistent with what is expected.
This appears to be a known issue with Bundler (How to add Mac-specific gems to bundle on Mac but not on Linux?). I could just avoid committing Gemfile.lock, but we rely on the version dependency management that Gemfile.lock provides. And I don't want to get all the developers on my team to switch to developing on Linux/Unix. Anyway that's a separate issue so I'm closing this for now. Thanks to the people who commented!
Related Topics
Millisecond Resolution of Datetime in Ruby
How to Test If a Div Has a Certain CSS Style in Rspec/Capybara
Is It a Bad Practice to List Ruby Version in Both Gemfile and .Ruby-Version Dotfile
Safely Assign Value to Nested Hash Using Hash#Dig or Lonely Operator(&.)
Heroku Rails 4 Could Not Connect to Server: Connection Refused
Suppressing the Output of a Command Run Using 'System' Method While Running It in a Ruby Script
How to Specify Output File Encoding in Ruby
Ruby: Compare 2 Arrays for Matches, and Count the Number of Match Instances
Silencing Deprecation Warnings in Rails 3
Ruby - Iterate Over Parsed JSON
Emacs Ruby-Mode Indentation Behavior
Ruby Koan: Constants Become Symbols
How to Compile Ruby with Rvm on a Low Memory System
Dynamic Rails Routes Based on Database Models
Verify Client Certificate Using Sslserver in Ruby
Could Not Find 'Cocoapods' (>= 0) Among N Total Gem(S) (Gem::Loaderror)
Cannot Load Such File -- Readline (Loaderror) When Running Heroku Create --Stack Cedar