How to build on macOS ARM?

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

Well somewhere I got chocolate in the peanut butter and wound up with a working compiled FreeCAD on macOS for ARM64.

When attempting to reproduce the success, I was met with failure. Thankfully, keeping the several build directories I was able to diff the CMakeCache.txt from the working to the broken builds and what I found was that the successful build was, for whatever reason, using the CMake files from Homebrew for OpenCASCADE as seen in this segment of the diff from working to broken builds:

Code: Select all

//The directory containing a CMake configuration file for OpenCASCADE.
-OpenCASCADE_DIR:PATH=/opt/homebrew/lib/cmake/opencascade
+OpenCASCADE_DIR:PATH=/opt/homebrew/Caskroom/mambaforge/base/envs/freecad_dev/lib/cmake/opencascade
 
After diffing the various CMake files, I can see there's considerable configuration and build differences between the versions. I'm going to look at synchronizing the OCCT conda configuration with that of Homebrew Core and see if it resolves the problem.
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

I managed to understand my problems. When packages are built with conda, they dynamically link to @rpath/libc++.1.dylib, but when they are built using the normal compiler they are linked against /usr/lib/libc++.1.dylib. These are incompatible builds of LLVM's libc++, so when an istream or ostream are handed from one library to the next we get horrible surprises that are challenging to understand.

The solution is to make the local CMake build absolutely identical to the conda build. This also means that you must install the binaries to get them to execute correctly, and I'm uncertain if this will impact the ability to run the debugger easily.

My updated build steps are on the following GitHub gist: https://gist.github.com/oursland/e1dc94 ... e6c573d711

I'll work on getting the changes prepared in a PR so that the conda weekly builds can be made for ARM64, but I think getting the Homebrew tap realigned may prove more valuable for rapid development.

On Linux, it took all of an hour to get the ci/Dockerfile updated and a .devcontainer/ configured for a standard VS Code development environment complete with compilation and interactive IDE debugging. On macOS it's taken a week to get it built, and I'm uncertain if the artifacts are suitable for interactive IDE debugging.
JohnOCFII
Posts: 112
Joined: Sun Sep 20, 2020 5:46 pm
Location: Minnesota, USA

Re: How to build on macOS ARM?

Post by JohnOCFII »

Alright! Build completed successfully. I was able to open existing documents, edit them, export as 3MF. All looking really good!
Here's my build info:

Code: Select all

OS: macOS 13.2
Word size of FreeCAD: 64-bit
Version: 0.21.0.32370 (Git)
Build type: Release
Branch: master
Hash: c585a9f4306e4707e36c5a4c2c68a2f987a66a21
Python 3.11.0, Qt 5.15.6, Coin 4.0.0, Vtk 9.2.2, OCC 7.6.3
Locale: English/United States (en_US)
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

Thanks for everyone's assistance!

I have completed a guide and video walkthrough on how to set up Visual Studio Code to build and debug FreeCAD for both C++ and Python. The approach uses conda to manage the environment, and integrates with Visual Studio Code's code completion and interactive debugging facilities.

After testing and updating for Linux and Windows I'll create a PR to see if the team at large would be interested in having a fairly turn-key approach to getting up and running with a complete cross-platform development environment.

FreeCAD Build Notes: https://github.com/oursland/FreeCAD-Build-Notes

Video Walkthrough: https://youtu.be/2ujlBmywx5g
User avatar
adrianinsaval
Veteran
Posts: 5534
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to build on macOS ARM?

Post by adrianinsaval »

What do you intend to include in such PR? If it's just instructions then a wiki page would be better than a PR to the main repo, I've seen many instances of documentation or helper tools rotting on the main github repo, nobody maintains them there.
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

What do you intend to include in such PR?
The `.vscode/` directory that sets up the environment with tooling for compilation and debugging c++ and python.
User avatar
chennes
Veteran
Posts: 3868
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How to build on macOS ARM?

Post by chennes »

Sounds great, PR away.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
JohnOCFII
Posts: 112
Joined: Sun Sep 20, 2020 5:46 pm
Location: Minnesota, USA

Re: How to build on macOS ARM?

Post by JohnOCFII »

oursland wrote: Tue Mar 21, 2023 6:35 pm FreeCAD Build Notes: https://github.com/oursland/FreeCAD-Build-Notes
I tested the process today on my M1 MacBook Pro. It worked amazingly well!

Basic testing in PartDesign/Sketcher/Spreadsheet and exporting as 3MF worked fine.
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

Awesome, JohnOCFII! Thanks for checking!

I tried running the process on Linux, and unfortunately it didn't build due to differences in system dependencies for toolchains and OpenGL implementations. Unfortunately the conda env create -f <filename> does not go through templating, so one cannot specialize it per platform.

I am evaluating the use of conda-devenv which implements templating, but isn't as complete as the conda-build system, as well as creating a package that brings in the necessary build dependencies for all platforms.
fpetzold
Posts: 20
Joined: Tue Mar 28, 2023 1:48 pm

Re: How to build on macOS ARM?

Post by fpetzold »

I tried the procedure yesterday and again today on an M1 MacBook Pro, but failed unfortunately.Maybe this is because I do not use homebrew but MacPorts.

I will try to also install homebrew and try again. My goal is to have an ARM version that supports my SpaceMouse, which is not supportzerd by the prebuilt binary.

I also opened an issue on GitHub detailing some of my difficulties on compiling.

Thanks for all the work!
Post Reply