Tuto: compiling PX4 v1.12 with MacOS with Apple Silicon

Hello PX4 community,

I just acquired a MacBook Pro with M4 Apple silicon (Sequoia 15.5) and wanted to document how to compile the older version of PX4 for Nuttx based hardware, namely v1.12. The newer version v1.15 also compiles fine with this setup.

Notes

Note: I’m not able to compile posix SITL, nor Gazebo for now. I’ll update the post if progress is made.

Spoiler alert: to compile an older version version of the code, we need older tools.

Three Major Tools

There are three major tools we need to install: python, arm-none-eabi-gcc compiler, and cmake. And the newest versions did not allow me to compile PX4 v1.12. On my old machine that compiled fine, I had

  • python 3.6.15
  • arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
  • cmake 3.31.2

Step by step

If we jump straight to the documentation for PX4 v1.12 MacOS Development Environment, there is a couple of relevant info and a couple of outdated info.

  1. Open the Terminal using Rosetta: yes we need to do that. (Bummer, I was not able to duplicate the Terminal). Verify this by typing arch in the Terminal which should return i386. Keep the terminal with Rosetta for this entire tutorial and whenever you will compile PX4 from the Terminal.
  2. Homebrew Installation: yes, we’ll need that. /bin/bash -c “$(curl -fsSL ``https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh``)”
  3. Enable more open files: yes, let’s do that. open ~/.zshenv and add at the end of the file ulimit -S -n 2048. (Add an empty line at the end of the file). Then save and close. Then type source ~/.zshenv to apply the changes.
    1. Enforce Python Version: let’s do it so the next step doesn’t crash, although we don’t need that.
      1. open ~/.zshrc
      2. Add alias pip3=/usr/bin/pip3 at the end of the file. Then add an empty line. Save and close the file.
      3. source ~/.zshrc
  4. Common Tools, installing px4-dev from Homebrew… This one will install the newest version of the tools which is not what we want. However, it might also install tools that we need. Some tips from the PX4 dev team would be appreciated.
    1. I personally did install everything using brew tap PX4/px4 and brew install px4-dev, then ended up removing cmake and arm-none-eabi-gcc.
    2. brew uninstall arm-none-eabi-gcc
    3. brew uninstall cmake

Python

  1. Instead of the Python installation, we will follow this tutorial on How to install multiple Python on your Mac. My machine came with Python 3.9.6 which is needed by other apps. So I don’t want to delete it. I also want to install the older version as 3.9.6 does not allow me to compile PX4 v1.12. Here is a little recap if ever the link becomes broken.
    1. brew install pyenv
    2. pyenv install --list, from the list we hopefully see 3.6.15.
    3. pyenv install 3.6.15
    4. pyenv global 3.6.15, to make it global. As I understand, PX4 cannot be compiled in virtual environment, so we need to set it globally.
    5. Let’s try python --version which in my case did not return 3.6.15. A little conversation with my favorite AI friend fixed it by adding these 3 lines to zsh open ~/.zshrc(similar to step 3.)
      1. export PYENV_ROOT=“$HOME/.pyenv”
        export PATH=“$PYENV_ROOT/shims:$PATH”
        eval “$(pyenv init --path)”
      2. Another source ~/.zshrc to apply the changes and python --version now returns Python 3.6.15. Hourrah! Let’s take a deep breath… :partying_face:
    6. To install the python packages, we can use what is proposed in the documentation, with python3 -m pip install --user, I just added a little twist to ensure empy version 3.3.4 otherwise you might run into the RAW_OPT error, see this post. So the full command is python3 -m pip install --user pyserial empy==3.3.4 toml numpy pandas jinja2 pyyaml pyros-genmsg packaging

ARM compiler

  1. Then, I installed arm-none-eabi-gcc 9-2020-q2-update, I downloaded the .pkg Mac OS X 64-bit Package (Signed and notarized). Then double-click and install. Super! But the location was not added to the PATH. I looked for it with the command sudo find / -name "gcc-arm-none-eabi" -type d 2>/dev/null and it turned out is was simply installed under Applications, so I added this line to ~/.zshrc: export PATH=“/Applications/ARM/bin:$PATH”
    1. arm-none-eabi-gcc --version now returns arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)

CMake

  1. Last but not least, we need to install CMake. Actually, I couldn’t find a way to download an older version from Homebrew. Big problem ==> big solution: I recompiled CMake from source using this tutorial (for CMake 3.12, but we want 3.31.2).
    1. Go to the CMake archives, then select cmake-3.31.2.tar.gz to download it. Then extract it once downloaded.
    2. Then open a Terminal pointing to the extracted folder, and select the prefix ./configure --prefix=/usr. In my case, I configured the prefix as ./configure --prefix=/Users/romainchiappinelli. This made more sense on my machine. Check what your directory look like, by typping pwd in the Terminal for instance. The prefix configuration can take a while.
    3. make -j16, this also can take a bit of time.
    4. Then, make install, which might also take its time.
    5. Finally, type cmake --version… if it is not found, look for it in the prefix path you specified and add it to the ~/.zshrc (again). For me it looks like export PATH=“$PATH:/Users/romainchiappinelli/cmake/bin”
    6. Finally, cmake --version returns cmake version 3.31.2

Finally, PX4 compilation

  1. Grand finale, go to your PX4 v1.12 folder, run git submodule update --init --recursive followed by make px4_fmu-v5 and the compilation succeeded for me! :rocket: :rocket: :rocket:
1 Like

I was finally able to compile posix SITL make px4_sitl and unit tests make tests using Parallels virtual machine. Unfortunately Ubuntu desktop exists only for AMD64 which is not compatible with apple silicon. So I installed Ubuntu server 20.04 64-bit ARM (we need AArch64 architecture). We then need to install the Parallels Tools for Linux.

Everything works, but … you know … Ubuntu server is limited to a terminal interface, so no Gazebo for now :upside_down_face: Also, the clipboard doesn’t seem to work :upside_down_face: .