Does Homebrew-cask Support Architecture Based Distribution for Apple Silicon and Intel Processors?

105 Views Asked by At

I am trying to distribute my app through homebrew-cask, but I have encountered an issue. The problem is that homebrew-cask doesn't support separate builds for Apple silicon and Intel processor macOS. Instead, we need a universal binary. My question is, does homebrew-cask provide architecture-based distribution support for the same app?

A solution except for universal binary and asking for help in creating the cask file.

1

There are 1 best solutions below

0
On

I read at "Cask Cookbook / Conditional statements":

Handling different system configurations

Casks can deliver specific versions of artifacts depending on the current macOS release or CPU architecture by either tailoring the URL / SHA-256 hash / version, using the on_<system> syntax (which replaces conditional statements using MacOS.version or Hardware::CPU), or both.

If your cask's artifact is offered as separate downloads for Intel and Apple Silicon architectures, they will presumably be downloadable at distinct URLs that differ only slightly. To adjust the URL depending on the current CPU architecture, supply a hash for each to the arm: and intel: parameters of sha256, and use the special arch stanza to define the unique components of the respective URLs for substitution in the url. Additional substitutions can be defined by calling on_arch_conditional directly.

So try and create a Cask file with architecture conditional: you can specify different URLs and SHA-256 hashes for ARM (Apple Silicon) and Intel architectures.

cask "your-app" do
    arch arm: "arm64", intel: "x86_64"
    version "1.0.0"

    sha256 arm:   "sha256_arm64_version",
        intel: "sha256_x86_64_version"

    url "https://yourappdomain.com/downloads/YourApp_#{version}_#{arch}.dmg"
    name "YourApp"
    homepage "https://yourappdomain.com/"

    app 'YourApp.app'
end

Replace sha256_arm64_version and sha256_x86_64_version with the actual SHA-256 hashes of your ARM and Intel builds.
Adjust the url to point to where your different architecture builds are hosted.
Test the cask locally to make sure it works correctly on both architectures. Once tested, you can submit your cask to the Homebrew-Cask repository for inclusion.


An alternative approach would be to use the lipo tool to combine your separate Apple Silicon and Intel builds into a single universal binary.

lipo -create -output YourAppUniversal YourAppIntel YourAppAppleSilicon
lipo -info YourAppUniversal

Then fork the homebrew-cask repository on GitHub, and create a new cask file in the Casks directory.

cask 'your-app' do
    version '1.0.0'
    sha256 'your_app_sha256_hash'

    url 'https://yourappdomain.com/YourAppUniversal.dmg'
    name 'YourApp'
    homepage 'https://yourappdomain.com/'

    app 'YourApp.app'
end