FreeCAD / FreeCAD-Bundle

Stand-alone repo to Build and Deploy installable FreeCAD images. Do not open general FreeCAD issues here.
https://freecad.org
GNU Lesser General Public License v2.1
312 stars 63 forks source link

macOS: Released disk image for arm mac requires rosetta #283

Closed jmgurney closed 1 month ago

jmgurney commented 11 months ago

Is there an existing issue for this?

Problem description

The dmg that claims to support M1/M2 arm Macs does not work w/o Rosetta. It pops open a dialog telling me to install rosetta.

Full version info

I cannot use about box since FreeCAD refuses to run, but I have tried `FreeCAD-0.21.0-mac-arm64.dmg`, `FreeCAD-0.21.1-mac-arm64.dmg` and `FreeCAD-0.21-RC1-mac-arm64.dmg`.

Subproject(s) affected?

None

Anything else?

Machine is a 2021 14-inch MBP w/ an M1 Pro running macOS 14.0 (23A344). It does not have rosetta installed, partly to discover programs which claim to support ARM, but actually do not.

Code of Conduct

jmgurney commented 11 months ago

I also just attempted w/ FreeCAD_weekly-builds-34667-2023-10-15-conda-macOS-arm64-py310.dmg and it also prompts to require Rosetta.

klokik commented 11 months ago

Workaround: launching executable directly from terminal works

FreeCAD_0.21.1_arm64 % ./FreeCAD.app/Contents/MacOS/FreeCAD

felipebalbi commented 9 months ago

I believe the issue is because of the shell script runner. Perhaps the environment variables set by the script should be moved to Info.plist and the binary should be placed in MacOS/FreeCAD instead.

dansharkey commented 1 month ago

I believe the issue is because of the shell script runner. Perhaps the environment variables set by the script should be moved to Info.plist and the binary should be placed in MacOS/FreeCAD instead.

I can confirm this is the issue. The "executable" in /Applications/FreeCAD.app/Contents/MacOS is actually a bash script that sets some environment variables and then calls the true executable which is in /Applications/FreeCAD.app/Contents/Resources/bin/freecad. Since the MacOS directory doesn't contain the arm executable, then Mac OS incorrectly assumes that the package requires Rosetta 2.

By moving the true exe into the MacOS/ directory it is now showing as "Application (Apple silicon)" when FreeCAD.app is right-clicked and Get Info is selected, and the Rosetta 2 requirement disappears.

The problem now is that since the exe has moved then all of the dynamically linked libraries can no longer be found, which I guess is what some of the environment variables (LD_LIBRARY_PATH) are attempting to do in the original bash script. Looking at FreeCAD-Bundle/blob/main/conda/scripts/fix_macos_lib_paths.py and FreeCAD-Bundle/blob/main/conda/osx/APP/FreeCAD.app/Contents/MacOS/FreeCAD seems to indicate that @adrianinsaval and @looooo have some experience in this area?

After moving the executable to MacOS, I get the error

dyld[8043]: Library not loaded: @rpath/libFreeCADGui.dylib
  Referenced from: <51373041-D1BF-37DE-8F04-E1B6A0CB9ACE> /Applications/FreeCAD.app/Contents/MacOS/freecad
  Reason: tried: '/Applications/FreeCAD.app/Contents/MacOS/../lib/libFreeCADGui.dylib' (no such file), '/Applications/FreeCAD.app/Contents/MacOS/../lib/libFreeCADGui.dylib' (no such file), '/usr/lib/libFreeCADGui.dylib' (no such file, not in dyld cache)
zsh: abort      /Applications/FreeCAD.app/Contents/MacOS/freecad

which I can work around by also moving all of the contents of Resources up into the top level of FreeCAD.app (this lets it run by double-clicking, with no Rosetta warning, after a bit of xattr -dr com.apple.quarantine /Applications/FreeCAD.app trickery)

I'm afraid that's as far as I've been able to get - actually fixing the issue may be as simple as running a tool like install_name_tool after moving the exe, and adding the remaining environment vars to Info.plist as @felipebalbi suggests. Or it may be best to tweak the aforementioned fix_macos_lib_paths.py script, or even resolve the CMake scripts so the correct dynamic library paths are created during the build.

JohnOCFII commented 1 month ago

@oursland may also be able to suggest a way to move forward with re-architecting the macOS .app

oursland commented 1 month ago

I am somewhat familiar with the packaging system, although it is indeed maintained by @adrianinsaval and @looooo who are far more familiar. I believe until now, none of us knew the reason for requiring Rosetta 2, but with this investigation there's a path forward.

adrianinsaval commented 1 month ago

one can just do a symlink instead of copying the executable, the problem with this is that we can't properly set the env variables without the bash script. I tried now adding a value to Info.plist that should tell mac what architecture the bundle supports so hopefully it won't try to run with rosetta anymore. Could you please test the latest weekly?

JohnOCFII commented 1 month ago

Could you please test the latest weekly?

That seems to have resolved this issue. I normally have Rosetta run as needed, but by looking at Activity Monitor when launching last weeks' build, I could see that bash ran as Intel. Now with tonight's build (38459) bash is shown as associated with FreeCAD and running as an Apple binary.

Screenshot 2024-08-12 at 8 41 39 PM
OS: macOS 14.6.1
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.38459 (Git)
Build type: Release
Branch: main
Hash: 58729b3ab0060a1525fc45c87beabfd4b3d5e22e
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: C/Default (C)
Installed mods: 
  * FeedsAndSpeeds 0.5.0
  * OpenTheme 2024.8.10
adrianinsaval commented 1 month ago

Great! I'll close the issue then

dansharkey commented 1 month ago

I've just tested the latest weekly (2d5a84e014483d98906486b8266196d000632d614c9e9218129a4cc4a24f0932 FreeCAD_weekly-builds-38459-conda-macOS-arm64-py311.dmg) and it is still requesting Rosetta even with LSArchitecturePriority=arm64 in the Plist file.

I think the best way to check with Rosetta installed is to look at the "Get Info" output after right-clicking on the .app file. Under "Kind" it should show as "Application (Apple silicon)" (as per this screenshot contrasting FreeCAD with Blender):

image

This is my system monitor after running the bash script directly from the command line (cd /Applications/FreeCAD.app/Contents; ./MacOS/FreeCAD)

image

Voting to re-open this issue (sorry!)

feheragoston commented 1 month ago

It works for me, I'm on Ventura 13.6.4. I don't have Rosetta installed and for the first time I was able to run FreeCAD without using the terminal.

@dansharkey is correct that on the info screen the Kind is Application where for other apps it is either Application (Universal) or Application (Apple silicon).

oursland commented 1 month ago

A possible solution would be to create a universal binary by installing both the x86-64 and arm64 conda packages as FreeCAD.app/Resources/${arch}/, then create a simple C++ launcher to replace the shell script that configures the environment and launches FreeCAD. CMake can and build the launcher for both platforms and generate the output as a Universal Binary.

References:

saraelsa commented 1 month ago

I am also unable to launch the latest weekly build (38459) without Rosetta. I'm on Sonoma 14.6.1.