BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Porting to Apple Silicon: Firefox Case

Porting to Apple Silicon: Firefox Case

This item in japanese

With the introduction of Apple Silicon, macOS developers will need to port their programs to the new CPU. For complex programs, this may be no small feat, though, as Firefox engineer manager Gian-Carlo Pascotto recounted.

While Apple Rosetta 2 binary translation technology ensures that most existing programs for macOS will be able to run on the new platform without any modifications, this will not enable them to take full advantage of the new CPU characteristics. Furthermore, when Apple considers the transition to the M1 complete, they will remove Rosetta 2 from their new OSes, as was the case with the original Rosetta used for transitioning from the PowerPC to the Intel platform a few years ago.

In general, the first step in the transition to Apple Silicon for any program is to compile the code for the ARM 64 platform. Usually, this is no major issue for programs that support both macOS and iOS, since all iOS devices from Apple use the ARM64 architecture. This was not the case with Firefox, though, since its iOS version is little more than a wrapper around WebKit and does not use Firefox's own engine due to restrictions imposed by Apple. Yet, Firefox already had an ARM64 version for Android and Linux, so this was not a major concern.

So with 64-bit ARM support already in the codebase, the first pass of work was to go through all the Firefox code, dependencies, and various third-party build systems to see if they correctly dealt with the novel idea that a Mac could have an ARM chip inside.

One key concern, explains Pascotto, was the availability of a working Rust compiler for Apple Silicon, which is required by core parts of Firefox, including Servo and other key parts. When the Rust compiler became available, the Firefox team could adapt and fix all low-level details of Firefox codebase, as well as of the crates it required, that had to do with calling conventions and interfaces with other languages, including JavaScript and C++.

One area of major complexity in Firefox is dealing with video streaming formats used by services such as Hulu, Disney+, or Amazon Prime, which require using closed source, proprietary DRM software that is downloaded on demand when the user visits any of those services. For the port to Apple Silicon, Firefox could not rely on those codecs to be ready on time, so they resorted to a specific approach to enable the use of the existing x64 codecs under Rosetta emulation:

We ended up leveraging a technique that we are also using for the Windows on ARM version of Firefox. The DRM video decoder already executes in a separate process so we can sandbox the proprietary code from the user’s system.

A final area that required some work was adapting to macOS Big Sur, the latest version of macOS, which included many deprecations and backward incompatibilities.

With this, Mozilla engineers had tackled all major technical hurdles in the transition to Apple Silicon and were among the first to announce Apple Silicon support. But the road to a stable release has not proved to be easy in spite of this. As Pascotto explains, the app update process also revealed additional hurdles that Firefox engineers had to overcome and the WebRender was disabled in the first version to work around some graphics driver bugs in Big Sur. Finally, Native support for Apple Silicon became officially available in Firefox 84, released last December.

Pascotto adds much more detail in his writing than can be addressed here, including future plans for Firefox on Apple Silicon and performance considerations, so you may want to make sure you read his story, too, if you are interested.

Rate this Article

Adoption
Style

BT