DEV Community

Nevenka Lukic
Nevenka Lukic

Posted on

Solving Azure Functions Compatibility Challenges on Mac M1: A Step-by-Step Guide

Introduction

While working on a new project that involves Azure Functions and Python, I faced an unexpected roadblock. I was surprised to discover that Azure Functions didn't seamlessly support my Macbook Pro with an M1 CPU. Two significant constraints became apparent:

1. Incompatibility with Apple M1/2 CPUs

Azure Functions, as of my initial research, did not have native support for Apple's M1/2 CPUs, causing a hiccup in my development journey.

2. Dependency on Older Python 3.9

Another challenge arose when I realized that Azure Functions required an older Python version, specifically Python 3.9, instead of the more recent Python 3.11.

Overcoming these roadblocks demanded substantial time and research. Today, I want to share the solution I found, hoping to assist anyone else fighting with this issue.

The Path to Compatibility: A Three-Part Journey

My quest to make Azure Functions work on my Mac M1 led me through a series of steps, which I've broken down into three parts for your convenience. By following these steps in order, you can ensure a smooth setup and overcome the compatibility obstacles.

Part 1: Setting Up x86 Emulation on ARM64 with Rosetta

The first phase of our journey involves setting up x86 emulation on ARM64 architecture with Rosetta. This step is crucial for ensuring compatibility between your Mac M1 and Azure Functions.

Part 2: Installing Required Packages and Tools

In the second part, we'll delve into the installation of necessary packages and tools that will enable Azure Functions to work seamlessly with Python 3.9. This step bridges the gap between the platform's requirements and the tools you need to build your project.

Part 3: Configuring .zshrc and Visual Studio Code Settings

The final leg of our journey focuses on configuring your .zshrc file and fine-tuning Visual Studio Code settings to ensure a smooth development experience. This step will help you make the most of your development environment and optimize your workflow.

In conclusion, solving issues with Azure Functions on a Mac M1 might seem hard at first, but with the right guidance, you can overcome the compatibility challenges. By following these three parts in order you should be able to solve this very quickly.

STEPS:

  1. Install Rosetta

    • To run older non-native Intel x86 apps on your Apple Silicon Mac (M1), you'll need to install Rosetta. Use the command: /usr/sbin/softwareupdate --install-rosetta --agree-to-license This step is specific to Apple Silicon ARM Macs and is not required for Intel Macs.
  2. Duplicate iTerm for Rosetta

    • Open Finder and duplicate your iTerm Terminal application. Rename the copied application to something like "iTerm rosetta."
  3. Enable Rosetta in Terminal

    • Right-click on your iTerm Rosetta copy and select "Get Info."
    • In the Get Info window, select "Open using Rosetta."
    • Open this new terminal and type arch. It should now show i386 or x86_64.
  4. Install Homebrew in an Emulated Environment

    • If you've previously installed Homebrew on your computer, you'll need to do it again within the Rosetta terminal.
    • The following blog post was very useful.
      • Create a ~/Downloads/homebrew directory and download the Homebrew tarball, then extract it to the ~/Downloads/Homebrew directory.
      • Run these commands to move the Homebrew directory to /usr/local/Homebrew and add the path to your .zshrc file:
       sudo mv homebrew /usr/local/Homebrew
       export PATH=$HOME/bin:/usr/local/Homebrew/bin:$PATH
    
  • You can now use arch -x86_64 /usr/local/Homebrew/bin/brew to install apps to the /usr/local/Homebrew/Cellar directory.
  1. Create an Alias for New Homebrew

    • Add an alias and path to your ~/.zshrc file to make working with this new Homebrew environment easier. Here's an example:
     # need this for x86_64 brew
     export PATH=$HOME/bin:/usr/local/Homebrew/bin:$PATH
     # for Intel x86_64 brew
     alias axbrew='arch -x86_64 /usr/local/Homebrew/bin/brew'
    
  2. Install Azure Functions under Alias

    • You can use the alias you created to install Azure Functions:
     axbrew tap azure/functions
     axbrew install azure-functions-core-tools@4
     # if upgrading on a machine that has 2.x or 3.x installed:
     axbrew link --overwrite azure-functions-core-tools@4
    
  3. Install Python under Alias

    • To use Azure Functions, you need to install Python version 3.9 using pyenv:
     axbrew install pyenv
     pyenv install 3.9
     pyenv global 3.9
    
  • Add the following to your .zshrc to make Python 3.9 the default in this environment:

     if command -v pyenv 1>/dev/null 2>&1; then
       eval "$(pyenv init -)"
     fi
    
  1. Set Up Visual Studio Code Terminal Profile to Use Rosetta

    • In Visual Studio Code, open settings.json:
      • Click on "Code" at the top left.
      • Then select "Settings" and "Settings" again.
      • On the top right side, you'll find the "settings.json" icon. Click to open and add the following:
     "terminal.external.osxExec": "iTerm rosetta.app",
     "terminal.integrated.profiles.osx": {
         "x86 zsh": {
             "path": "/usr/bin/arch",
             "args": ["-arch", "x86_64", "/bin/zsh"]
         }
     }
    

Conclusion

By following these steps, you can successfully configure your Mac M1 to work with Azure Functions and Python, and overcome the hardware compatibility issues. And now when you have the right setup, you can continue working on your Azure development projects with your favorite Macbook Pro.

Top comments (0)