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!
Post Reply
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

How to build on macOS ARM?

Post by oursland »

I am attempting to bring up a development environment on my M2 Macbook Pro suitable for both core and workbench development. After many attempts I do have a procedure for performing a build using a conda environment very similar to the one outlined in the `freecad-feedstock` repository. Unfortunately, the built binary has problems with loading the example FreeCAD files and frequently runs into problems with recomputing the files.

My steps are outlined in the following Gist: https://gist.github.com/oursland/e1dc94 ... e6c573d711

What I would like to do is to try to replicate a build environment that produced the weekly build artifact https://github.com/FreeCAD/FreeCAD-Bund ... -py311.dmg that shows it was uploaded on January 7, 2023.
JohnOCFII
Posts: 112
Joined: Sun Sep 20, 2020 5:46 pm
Location: Minnesota, USA

Re: How to build on macOS ARM?

Post by JohnOCFII »

I too am very interested in being able to regularly build FreeCAD on macOS ARM. I had a build environment about a year ago, but that was never very stable. I'm happy to update the Wiki once we get something repeatable. With help from the OP I was able to get a somewhat working binary. I'm unable to load or save files.

Info from today's build attempt is below:

Thanks,

John

Code: Select all

OS: macOS 13.2
Word size of FreeCAD: 64-bit
Version: 0.21.0.32293 (Git)
Build type: Release
Branch: master
Hash: 4eafedb20fc89b2ffeb78a1ac114ca0f1f870903
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)
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 »

I compile on Mac OS ARM, but not using any of the Conda setup, so I am no help there. I am using a Homebrew-based setup, with a few custom modifications to deal with the fact that Homebrew isn't really designed for developers, so isn't careful about doing atomic upgrades (e.g. it defaults to a version of Python that is too new to use with its own versions of PySide, conflicts with boost-python3, etc.).

I ended up having to make custom packages of several things in order to downgrade them to something that would actually work. I just dumped them into the freecad/freecad tap. These are my current packages, not all of which are in the "official" tap:

Code: Select all

      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/tbb@2020_u3.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/swig@4.0.2.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/elmer.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/opencascade@7.5.0.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/opencamlib.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/freecad@0.20.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/pyside2@5.15.5.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/nglib@6.2.2104.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/nglib@6.2.2105.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/med-file@4.1.1.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/opencascade@7.5.3.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/opencascade@7.6.0.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/boost.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/qwtelmer.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/shiboken2@5.15.5.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/freecad@0.20.1.rb",
      "/opt/homebrew/Library/Taps/freecad/homebrew-freecad/Formula/boost-python3.rb"
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

Unfortunately I cannot build some of these dependencies, such as `med-file`. GitHub Issue #374 describes the problem: https://github.com/FreeCAD/homebrew-freecad/issues/374
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

I have made some additional progress on getting functional builds on Apple Silicon.

A version increase pull request has been made on `netgen-feedstock` to bring in support for Apple Silicon: https://github.com/conda-forge/netgen-feedstock/pull/44

Currently loading of FCStd files fails at PropertyPartShape::loadFromStream() due to a std::istream::failbit exception being thrown by BRepTools::Read(). Commenting out the enabling of exceptions permits the loading of FCStd files, but their BRep components are often positioned incorrectly. The location of the enabling of exceptions: https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L351

I am as yet uncertain why the istream that is passed into BRepTools::Read() ends in a bad state on macOS, but not on Linux. Furthermore, the January 7, 2023 build does not exhibit this issue.

@wmayer I understand you may be familiar with this section of code. Could you assist me in understanding why the istream on Apple Silicon breaks BRepTools::Read()?
wmayer
Founder
Posts: 20203
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to build on macOS ARM?

Post by wmayer »

Could you assist me in understanding why the istream on Apple Silicon breaks BRepTools::Read()?
Here are some points to consider:

Can you exclude that the file is the problem? Does the exact same file work on other OS?

Do you know with which OCC version the file was created? In a recent OCC version (IIRC it was 7.6) the BRep format has been slightly changed so that files created with the newer version won't load with older versions.

It can be a locale specific problem. Does it help to explicitly set the locale of the stream to std::locale::classic()?

Code: Select all

std::istream& str = ...
str.imbue(std::locale::classic());
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

The files tested are the example files. I am running parallel builds under Linux and can confirm that in that environment the same files open correctly.

Unfortunately setting the locale explicitly did not have any effect on the read.
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 »

Is the file something you can post? I'm on an M2 right now, I can try to load it here and see if it works.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

One simple file that does not load is the PartDesign example: https://github.com/FreeCAD/FreeCAD/blob ... mple.FCStd

The BRep files all fail, but the XML files succeed. Consequently a Mark to Recompute followed by a Recompute will properly generate the geometry.
oursland
Posts: 55
Joined: Sat Mar 11, 2023 9:33 pm

Re: How to build on macOS ARM?

Post by oursland »

A little more detail. I've added output of what exception was thrown when opening a file.

Code: Select all

08:25:04  Failed to load BRep file PartShape.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape1.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape2.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape3.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape4.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape5.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape6.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape7.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape8.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape9.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape10.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape11.brp: ios_base::clear: unspecified iostream_category error
08:25:04  Failed to load BRep file PartShape12.brp: ios_base::clear: unspecified iostream_category error
I've enabled Debug builds and the OCCT_DEBUG macros in OpenCascade, however the area of code responsible for parsing BRep files has no debugging logs to indicate where the problem is coming from. Consequently, the error appears to be specific to how macOS iostreams parse the passed in istream.

When ignoring exceptions, the resulting artifact does contain at least parts of the BRep file contents, but it does so at the wrong location. I have confirmed that the istream is valid when being passed into BRepTools::Read()
Post Reply