Skip to content

Instantly share code, notes, and snippets.

@beatfactor
Last active March 14, 2022 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatfactor/230a40e27632caeb053ca6616d9bead2 to your computer and use it in GitHub Desktop.
Save beatfactor/230a40e27632caeb053ca6616d9bead2 to your computer and use it in GitHub Desktop.
Installing azure-cli on MacOS M1

Building Azure CLI on Apple Silicon MacOS (M1)

First, install homebrew.

Build cffi

To build and install cffi follow these steps:

  1. Install libffi
brew install pkg-config libffi
  1. Download and extract the cffi sources from https://pypi.org/project/cffi/#files
curl -OL https://files.pythonhosted.org/packages/00/9e/92de7e1217ccc3d5f352ba21e52398372525765b2e0c4530e6eb2ba9282a/cffi-1.15.0.tar.gz
tar -xzvf cffi-1.15.0.tar.gz
cd cffi-1.15.0
  1. Edit setup.py and add the path for libffi.pc to include_dirs:

Get the path for libffi.pc:

find /opt/homebrew/ | grep "Cellar.*libffi.pc"

And the result should be something like:

/opt/homebrew//Cellar/libffi/3.4.2/lib/pkgconfig/libffi.pc

Edit setup.py:

sources = ['c/_cffi_backend.c']
libraries = ['ffi']
include_dirs = ['/usr/include/ffi',
               '/usr/include/libffi',
               '/opt/homebrew//Cellar/libffi/3.4.2/lib/pkgconfig/libffi.pc']
# ...
  1. Run setup.py
sudo python3 setup.py install

Build cryptography

azure-cli requires an older version (<3.0.0) of cryptography, which in turn needs the OpenSSL library 1.1. We also need a Rust toolchain.

brew install openssl@1.1 rust

Now install version 2.9.2 and reference the OpenSSL lib and include folders:

env LDFLAGS="-L$(brew --prefix openssl@1.1)/lib" CFLAGS="-I$(brew --prefix openssl@1.1)/include" pip3 install cryptography==2.9.2

Install azure-cli

pip3 install azure-cli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment