Developing for Slicer on Apple Silicon (build targeting x86_64)

arhowe00
Fri, 13 Dec 2024 22:44:12 +0000
Development

The developer docs may need a minor update addressing development on the newer Macs (M-series chips). Here is a sufficient-for-development build from source on arm64 MacOS without requiring niche workarounds for specific libraries. The following steps explain how to build Slicer from source on M-chip computers. Note that the Slicer build still targets x86_64 (i.e. run through Rosetta 2), but native arm64 builds may be rolled out at a future date. To summarize the steps:

1. Install Qt5 with x86_64 brew

2. Use x86_64 bash to build Slicer

3. Turn off SimpleITK

4. There were a few libraries which could not compile using later versions of clang. This discussion post is coupled with PR#8097, which cherry picks a few patches in files within libarchive.

This is an attempt to partially address #6811.

Step-by-step:

1. Install the latest Xcode SDKs:

xcode-select --install

2. Checkout Slicer source files

git clone https://github.com/Slicer/Slicer.git

3. Setup the development environment

cd Slicer
./Utilities/SetupForDevelopment.sh

4. Install x86_64 Homebrew. You can install “x86_64 Homebrew” if you run the shell with Rosetta 2:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

5. Launch /bin/bash with Rosetta 2. x86_64 Homebrew is in /usr/local/bin/brew, and it installs binaries in /usr/local/bin. /usr/local/bin is added to PATH by default on MacOS, so all binaries are accessible without any custom profiles (e.g. .bash_profile, .bashrc). You should remain in the x86_64 /bin/bash for the rest of the build.

exec /usr/bin/arch -x86_64 /bin/bash --norc --noprofile

export PATH="/usr/local/bin:$PATH"
brew install qt5

Be aware: On MacOS, /etc/paths configures your PATH such that binaries installed by Homebrew will be preferred over those in /bin. For example, if you install an x86_64 bash with /usr/local/bin/brew install bash, Homebrew-installed x86_64 /usr/local/bin/bash will be resolved when typing bash, not /bin/bash. For native arm64 Homebrew, be careful to set PATH=/opt/homebrew/bin:$PATH in custom profiles, or x86_64 binaries will always be resolved first, including brew.

6. Configure and build Slicer (from x86_64 /bin/bash). Note that arm64 cmake here is permissible:

cd ..

cmake_build_type=Debug

cmake \
  -DQt5_DIR:PATH=/usr/local/opt/qt@5/lib/cmake/Qt5 \
  -DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
  -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=13.0 \
  -DCMAKE_BUILD_TYPE:STRING=$cmake_build_type \
  -DSlicer_USE_SYSTEM_QT:BOOL=ON \
  -DSlicer_USE_SimpleITK:BOOL=OFF \
  -B ./Slicer-$cmake_build_type \
  -S ./Slicer

cmake --build ./Slicer-$cmake_build_type

Happy developing!

Not all the tests pass, but you should be able to launch Slicer with ./Slicer-Debug/Slicer-build/Slicer. This should make it easier to develop and iterate over 3DSlicer on Apple Silicon devices. Thank you to @Jared_Vicory for helpful input and @jcfr for the invaluable support.

6 posts - 2 participants