Build and test Metal Xcode projects with Anka

In this blog, we’d like to show you how to build and test Metal Xcode projects with Anka.

Modern iOS and macOS applications use Apple Metal APIs to access GPU for graphics or intensive calculations. Starting in Anka version 2.3.2, Anka VMs support the Apple Metal framework in order to leverage the host’s GPU. Developers can not only utilize Metal APIs in their simulator testing but will also notice a much richer and more performant graphics experience.

This is currently only supported on Anka Big Sur VMs running on Big Sur Hosts. 

One of the strengths of Anka is the ability to build and test your applications inside of an isolated/sandboxed macOS VM. This eliminates the need for managing dependencies for multiple projects on your laptop and potentially causes dependency collision, false-positive tests, and headaches. You can create your VM Templates from multiple macOS versions with specific dependencies installed and quickly switch between them or even revert them back to a clean version.

Recommendation: Alongside the Anka Virtualization technology, our Anka VM Github Action allows you to easily request a clone from a VM Template and automatically execute certain commands inside of it to run your builds and tests. This ensures consistency and eliminates potential human error which is all common after late nights and long hours.

Install the Anka Virtualization Package

To begin, you’ll need to install the Anka Virtualization package on your local machine. You can copy and paste the following into your terminal:

ANKA_VIRT_PKG_FILE_NAME=$(echo $(curl -Ls -r 0-1 -o /dev/null -w %{url_effective} https://veertu.com/downloads/anka-develop-latest) | cut -d/ -f4);
curl -S -L -o $ANKA_VIRT_PKG_FILE_NAME https://veertu.com/downloads/anka-develop-latest
sudo installer -pkg $ANKA_VIRT_PKG_FILE_NAME -tgt /

Once installed, you can confirm the Anka Develop license is available:

❯ anka license show
+--------------+-------------------------+
| license_type | com.veertu.anka.develop |
+--------------+-------------------------+
| status       | valid                   |
+--------------+-------------------------+

If you do not see the Anka Develop license, ensure that you’re using the required hardware: Macbook, Macbook Pro, or Macbook Air. If you do not have one of these hardware models, please obtain your trial license from https://veertu.com/getting-started-anka-trials/ or by contacting [email protected].

Create your Big Sur VM Template

Under your /Application directory or LaunchPad, find Anka and launch it. Once it’s open, you’ll find the “Create new VM” button. This will open a window allowing you to choose the Name and the Installer .app.

If you do not have the macOS installer, you have several options available to obtain it detailed in our documentation.

Once created, you will see the VM/Template available in the Anka window.

You can now start and stop the VM as many times as you wish. However, each start will create changes in the layering. What we want to do instead is keep this Template clean by first cloning it before we start or use it. Click on the VM Template name on the sidebar and then under the VM option on the menu bar, click on Clone.

Once cloned, you can click on the VM name to change it to something that helps you identify it from the original VM Template.

Prepare your VM Template for Xcode and Metal

In order to install dependencies, you’ll need to double click on the cloned VM. This will start it and launch the Anka Viewer window. You’ll then be able to open the terminal and/or install apps from the App store. Here are the dependencies we need to install for running Metal apps:

  1. Ensure you have Big Sur for your OS version. Metal/PG does not work without it running on both the host machine and guest VM.
  2. Install the latest Xcode through the App Store.
  3. Open the terminal and execute the following:
sudo xcodebuild -license accept
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install watch jq

The installation of watch and jq is optional, but I often use both of them while troubleshooting.

Once you’ve got your dependencies install and the VM ready to use, you’ll want to stop the VM and create another clone. However, before you do create another clone, you’ll need to enable ParaVirtualized Graphics (“PG”) with a terminal command:

anka modify 12.2-xcode12.4-metal-example set display -c pg

To disable, set display -c fbuf

Suspending VMs is not available once PG is enabled

This ensures that Apple Metal APIs are available inside of the VM and you get the best simulator/graphics performance.

We’re now ready to create the clone. The new clone will be what you work from to build and test that your app runs properly. Otherwise, if something is wrong, we need to modify the clone’s source VM Template and make sure the dependencies are set up properly before we clone and test again. If you’re curious, you can read over our detailed documentation about how VM Templates and Tags work.

We’re going to use the Custom Metal View example code from Apple to test Metal and PG. The following video will show you how we start a VM, download the Xcode project, and then build/test the Xcode project for Metal:

Share this post

anka-or-1
Anka vs Orka in 2024
It has been several years since we made our first side by side comparison between Anka and Orka. A lot has changed, and we believe it’s important to make sure the information out there is accurate. We’ll be specifically addressing a newer...
Read More
networking-performancev1
Unlocking Superior macOS VM Network Performance: Introducing Anka's new networking mode for Apple Silicon
Large and complex enterprises using Anka have many different demands, and we have worked to continue to develop innovative technology to meet these demands. Enterprise infrastructure hardware is often on the cutting edge, and they need advanced capabilities...
Read More
gitlab-with-anka
Anka Cloud Gitlab Executor
Veertu’s Anka and the new Anka Cloud Gitlab Executor Veertu’s Anka is a suite of software tools built on the macOS virtualization platform. It enables the execution of single or multi-use macOS virtual machines (VMs) in a manner similar to Docker....
Read More
mac-scan-v1
Real-Time CVE Scanning of your macOS Build Systems
It’s common that an organization’s macOS build system will download thousands, sometimes tens of thousands of third-party dependencies every hour. When building and testing iOS applications, it typically downloads and installs third-party...
Read More
anka-on-silicon-v1
The ONLY Fully Automated Apple Silicon macOS VM Creation Solution
Starting in Anka 3.1 we announced that Anka is now able to fully automate the macOS installation processes, disabling SIP, and enabling VNC — all previously manual steps users had to perform inside o the VM. At the time of writing this article,...
Read More
anka_click
Scripting macOS UI User Actions With Anka Click
Starting in Anka 3.2, we’ve introduced a solution for scripting macOS UI user actions. You may ask, “Why would I want to do that?”. Well, often macOS configuration and applications do not have a CLI allowing you to perform certain actions...
Read More
mac-scan-fullscan-shells-v3
Real-time, continuous scan of file downloads on macOS for security vulnerabilities
Today, we are announcing the Beta availability of the Mac Scan solution. Mac Scan software runs on macOS systems (bare metal, virtual, EC2 Mac) and scans downloads in real time for security vulnerabilities. There are multiple scenarios why you would...
Read More
Screen Shot 2022-10-17 at 10.13
Anka 3.1- Fully automated VM macOS installation & The Behavior-Driven macOS UI Automation Framework
We are very happy to announce the General Availability of Anka 3.1 for Apple Silicon / ARM macs. In this release, we are taking our approach to iOS CI automation one step further by introducing a Behavior-Driven macOS UI Automation Framework in Anka,...
Read More
ankam1v2
Migrating from Anka on Intel to Anka on M1 Mac for iOS CI
In this blog, we will cover the key topics for migrating from Anka on Intel to Anka on M1/M2 Macs. Anka is an IaaC solution from Veertu to set up an agile Container like CI for iOS CI using macOS VMs. Anka for Intel uses Apple’s Hypervisor.Framework virtualization...
Read More
ami-scanner-featured-v2
World's first Security Vulnerability scanner for EC2 Mac AMIs
We are excited to announce the General Availability of the world’s first security vulnerability scanner for EC2 Mac AMIs. EC2 Mac AMI Scan scans Intel and Apple Silicon macOS EC2 AMIs, detects security vulnerabilities in third-party packages, dependencies,...
Read More