Categories:
Loading... Search articles

Search for articles

Sorry, but we couldn't find any matches...

But perhaps we can interest you in one of our more popular articles?
Updating your dependencies for M1 Macs and CI/CD.

Updating your dependencies for M1 Macs and CI/CD

May 18, 2022

Written by Rudrank Riyam.

Use M1 Mac mini VMs by default with Codemagic🚀 Build faster

TL;DR: This article covers how to update dependencies for Homebrew, CocoaPods, Carthage, Ruby, and more if you are using M1 Macs. However, for the M1 Mac minis available on Codemagic, you don’t have to do anything described in this article — everything is already preinstalled and preconfigured, so you can just use them right away.

We’ve already started talking about migrating your CI/CD to M1 Macs and covered the basics, such as requirements and updating basic dependencies — you can read the blog post on this here. It also covers the reasons why you should even care about migrating to M1s. In this article, we’ll dive somewhat deeper into the topic of updating dependencies and package managers for M1 Macs.

This article covers the following topics:

  • Updating Homebrew
  • Updating Ruby
  • Updating RubyGems
  • Updating CocoaPods
  • Updating Carthage

Let’s get started!

Updating Homebrew

Homebrew is a popular package manager that helps you to simplify installing tools and software on your Mac machine. You can use it to install Ruby, dependency managers like CocoaPods and Carthage, or the popular automation tool fastlane.

Homebrew is one of the recommended dependency managers. You may require versions of tools built specifically for arm64 architecture, e.g., Ruby.

The default path for Homebrew has changed for the new M1 machines, and you may need to update the path for Homebrew in your local machine and the path in your Codemagic workflow if you are using hard-coded paths. This was announced back in January 2021, when /opt/homebrew became the default directory for Apple silicon instead of /usr/local on the Intel machines.

At the time of writing this article (May 2022), most of the popular tools that use Homebrew already support the arm64 architecture, so it’s easier to update different software using Homebrew.

The default shell in macOS Big Sur and Monterey is zsh. You can check which shell program is running in your terminal with the following command:

echo $SHELL

If you do not have Homebrew installed, you can run the following command in the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Homebrew is already installed on the M1 Mac minis and other machines available on Codemagic. You are not required to add this command to your workflow configuration file for it.

The command above will install Homebrew — however, you’ll get a warning:

Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the “Next steps” section below.
==> Installation successful!

You will be instructed to run two commands in your terminal to add Homebrew to your PATH:

echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> ~/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)

The path has already been updated for the M1 Mac mini build machines available on Codemagic, so you do not have to explicitly write a command or script.

After running these two commands, make sure to either restart the terminal app or execute the following:

source ~/.zshrc

You can confirm that the new path has been set by running the following command:

which brew

The output should look something similar to this:

rudrankriyam@Rudrank-2 ~ % which brew
/opt/homebrew/bin/brew

For Intel machines, the path looks something like this:

rudrankriyam@Rudrank ~ % which brew
/usr/local/bin/brew

To confirm that everything is ready for your Apple silicon machine, run the following command:

brew doctor

If everything is working fine, the output should be similar to this:

rudrankriyam@Rudrank-2 ~ % brew doctor                                                  
Your system is ready to brew.

Note that if you forget to change the path for Homebrew, it will still allow you to install some other packages, but they will have the wrong path too. This may result in them not working correctly.

With Homebrew set up for your M1 machine, updating other packages is going to be a breeze!

Updating Ruby

Ruby is a dynamic, high-level programming language that focuses on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. More often than not, the tools you use for your iOS projects are written in Ruby. Hence, it’s important to update Ruby to the latest version that supports the arm64 architecture.

Homebrew is a package manager that is commonly used on macOS for installing Ruby:

brew install ruby

This command installs the latest Ruby version.

Make sure you have already updated the path mentioned in the previous section on Updating Homebrew.

Then you can check the version of Ruby installed on your machine:

ruby -v

You will get the following response:

rudrankriyam@Rudrank-2 ~ % ruby -v          
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

As you can see, arm64-compatible Ruby is installed for the current device.

Ensure that Ruby is installed in the correct path:

which ruby

The output should look something like this:

rudrankriyam@Rudrank-2 ~ % which ruby
/opt/homebrew/opt/ruby/bin/ruby

The path on an Intel machine used to look like this:

rudrankriyam@Rudrank ~ % which ruby
/usr/local/opt/ruby/bin/ruby

Ruby is already installed on the M1 Mac minis and other machines available on Codemagic. If you require the latest version of Ruby, you can add the install script into your workflow configuration file.

Updating RubyGems

RubyGems is a package management framework for Ruby. If you already installed Ruby in the previous step, you can check if it is installed correctly in the correct path with the following command:

which gem 

The output should look something like the following:

rudrankriyam@Rudrank-2 ~ % which gem                                           
/opt/homebrew/opt/ruby/bin/gem

As Ruby is already installed on the M1 Mac minis and other machines available on Codemagic, RubyGems is also installed.

If you want to update RubyGems to the latest version, run the following command:

gem update --system

This package manager for Ruby can be used to install different gems (Ruby packages). For example, Ruby-FFI is a gem for programmatically loading dynamically linked native libraries, binding functions within them, and calling them from Ruby code. You may use this gem for libraries in your iOS projects.

To install it correctly on your Apple silicon machine, you have to use the following command:

gem install --user-install ffi -- --enable-libffi-alloc

Using the install option --enable-libffi-alloc forces closure allocation by libffi. If you were getting errors or segmentation faults earlier while working with this popular gem, installing it this way is a potential solution for machines with arm64 architecture.

For example, Jazzy is a command-line utility that generates documentation for Swift or Objective-C code. You install it using RubyGems, and the utility uses Ruby-FFI. Developers were facing issues with fii, and installing it using the command above fixed it.

Updating CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. You may be using it in your iOS project, so updating it correctly for M1 machines is essential. If you have followed the process above to update Homebrew and Ruby, then installing CocoaPods is a one-line command:

brew install cocoapods

The latest version of CocoaPods is already installed on the M1 Mac mini and other machines available on Codemagic. You are not required to add this command to your workflow configuration file.

Then you can ensure that it is installed in the correct path:

which pod

The output should look something like this:

rudrankriyam@Rudrank-2 ~ % which pod
/opt/homebrew/lib/ruby/gems/3.1.0/bin/pod

For an Intel machine, the path looks like this:

rudrankriyam@Rudrank ~ % which pod
/usr/local/bin/pod

Then, you can install the pods in your projects for the arm64 architecture:

pod install

You can easily use pods in your project now when running on an Apple silicon Mac! If you have issues updating particular pods, look at the section on updating third-party dependencies in this article.

Updating Carthage

Carthage is a simple dependency manager for your iOS and macOS projects. It builds third-party dependencies and provides you with binary frameworks, giving you total control over the project structure.

Similar to CocoaPods, you can use Homebrew to install Carthage:

brew install carthage

Then you can ensure that it is installed in the correct path:

which carthage

The output should look similar to the following:

rudrankriyam@Rudrank-2 ~ % which carthage
/opt/homebrew/bin/carthage

For an Intel machine, the path looks like this:

rudrankriyam@Rudrank ~ % which carthage
/usr/local/bin/carthage

At this point, you will find that third-party libraries and frameworks offer XCFrameworks, which is required when building on an Apple silicon Mac. You can use XCFrameworks by running the following command:

carthage update --use-xcframeworks

If you are switching from discrete framework bundles to XCFrameworks, follow the migration steps mentioned by Carthage here.

Conclusion

Updating the tools and packages ensures that you are taking advantage of the raw power of Apple silicon instead of using Rosetta 2 emulation.

Apple silicon chips are the future of Mac hardware, and it only gets better from here on out. Most package managers and tools already support the new chips, so the transition is much easier than it was a year ago.

Reminder: M1 Mac mini build machines are already available on Codemagic. If you’re on the Pay-as-you-go plan, use instance_type: mac_mini_m1 to try them out. If you’re on the Professional plan and want to set up a trial for the Mac mini M1, reach out to our customer engineering team using the form below to help you get fast green builds on the new machines!

Embrace the powerful Mac M1 build machines in Codemagic CI/CD
Fill in the form to get a personal demo
Failed to submit
Thank you!
Your request has been sent and we will contact you as soon as possible!

How did you like this article?

Oops, your feedback wasn't sent

Related articles

Latest articles

Show more posts