Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS launcher app. #293

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Conversation

oursland
Copy link
Collaborator

FreeCAD uses argv[0] to determine PREFIX information, not the environment variables. This commit corrects argv[0] to match the FreeCAD binary.

FreeCAD uses argv[0] to determine PREFIX information, not the environment variables.
This commit corrects argv[0] to match the FreeCAD binary.
@oursland
Copy link
Collaborator Author

@adrianinsaval FreeCAD uses argv[0] to determine the home environment. None of the environment variables seems to have a significant effect on the ability to launch.

I confirmed that this worked with the weekly build by:

  1. installing the weekly build
  2. replacing the FreeCAD.app/Contents/MacOS/FreeCAD with the updated binary
  3. running xattr -cr FreeCAD.app to remove the now invalid signing metadata
  4. running the FreeCAD.app as normal

@luzpaz
Copy link
Collaborator

luzpaz commented Aug 20, 2024

Ubuntu CI build fails:

Create the appimage
appimagetool, continuous build (commit 5735cc5), build <local dev build> built on 2023-03-08 22:52:04 UTC
Error: no such file or directory: FreeCAD_weekly-builds-38495-conda-Linux-x86_64-py311.AppImage

Create hash
shasum: FreeCAD_weekly-builds-38495-conda-Linux-x86_64-py311.AppImage: No such file or directory
Error: Process completed with exit code 1.

@oursland
Copy link
Collaborator Author

Yes, but nothing related to the Ubuntu build was modified in this commit. It should be addressed as a separate issue.

@oursland
Copy link
Collaborator Author

@chennes Could you merge this change?

If you want to build and test the change:

cd conda/osx
bash create_bundle.sh

A file FreeCAD_0.22.0-conda-macOS-arm64-py311.dmg will be generated and should be installable.

After merging, someone will need to manually re-trigger the weekly build to get a working build for macOS.

@oursland
Copy link
Collaborator Author

@adrianinsaval @FreeCAD/maintainers This bug is preventing the macOS weekly builds from running and generating issues on FreeCAD main repo. I request that this change be reviewed and merged to get weekly builds back on track.

@chennes chennes merged commit fb7c60f into FreeCAD:main Aug 23, 2024
5 of 6 checks passed
@oursland
Copy link
Collaborator Author

sigh

This fixed the Intel builds, but not the Apple Silicon builds.

In order to run the Apple Silicon build I had to first execute xattr -cr /Applications/FreeCAD.app to remove attributes related to signing. I will look to see if dmgbuild has options to permit creating unsigned builds.

@oursland
Copy link
Collaborator Author

After some investigation, here's what I have found. Both apps are unsigned, so they prompt the user to permit them to be run. After being granted, the Intel version runs but the Apple Silicon version does not, instead suggesting the program be moved to the Trash. Comparing the attributes on each of the versions reveals the following:

> xattr -l -x /Applications/FreeCAD-intel.app 
com.apple.provenance:
00000000  01 00 00 A8 B7 8A 02 4D A6 08 57                 |.......M..W|
0000000B
com.apple.quarantine:
00000000  30 31 63 31 3B 36 36 63 37 66 39 37 65 3B 43 68  |01c1;66c7f97e;Ch|
00000010  72 6F 6D 65 3B                                   |rome;|
00000015

> xattr -l -x /Applications/FreeCAD-arm.app
com.apple.provenance:
00000000  01 00 00 A8 B7 8A 02 4D A6 08 57                 |.......M..W|
0000000B
com.apple.quarantine:
00000000  30 31 38 31 3B 36 36 63 37 66 39 38 38 3B 43 68  |0181;66c7f988;Ch|
00000010  72 6F 6D 65 3B                                   |rome;|
00000015

Bytes 12 and 13 of the com.apple.quarantine signature differ between the Intel version and the Apple Silicon version. The Apple Silicon version's attributes can be set to match the Intel version using xattr.

> xattr -x -w com.apple.quarantine "30 31 63 31 3B 36 36 63 37 66 39 37 65 3B 43 68 72 6F 6D 65 3B" /Applications/FreeCAD-arm.app

> xattr -l -x /Applications/FreeCAD-arm.app      
com.apple.provenance:
00000000  01 00 00 A8 B7 8A 02 4D A6 08 57                 |.......M..W|
0000000B
com.apple.quarantine:
00000000  30 31 63 31 3B 36 36 63 37 66 39 37 65 3B 43 68  |01c1;66c7f97e;Ch|
00000010  72 6F 6D 65 3B                                   |rome;|
00000015

Now the Apple Silicon version will run.

I am unsure why these attributes differ between the Intel and Apple Silicon version, but whatever the cause is, that's what's preventing the Apple Silicon version from running.

@oursland
Copy link
Collaborator Author

oursland commented Aug 23, 2024

Running wget https://github.com/FreeCAD/FreeCAD-Bundle/releases/download/weekly-builds/FreeCAD_weekly-builds-38495-conda-macOS-arm64-py311.dmg to download the weekly build results in a file that opens without any prompts or error messages.

The issue is tied to the com.apple.quarantine attribute applied to files downloaded from a browser and from what I can tell requires CLI commands to remove the attribute to permit the Apple Silicon version to run.

Signing the image with a valid developer key would eliminate the issue.

@luzpaz
Copy link
Collaborator

luzpaz commented Aug 23, 2024

Signing the image with a valid developer key would eliminate the issue.

Thanks for the sluething @oursland!

@chennes
Copy link
Member

chennes commented Aug 23, 2024

Is it normal for projects to sign their development weeklies? And/or to do it as part of their CI process? I manually sign our releases so that the signing key never leaves my direct control.

@JohnOCFII
Copy link

Is it normal for projects to sign their development weeklies? And/or to do it as part of their CI process? I manually sign our releases so that the signing key never leaves my direct control.

I don't know what "normal" is, but PrusaSlicer signs all their publicly released alpha, beta, and RC releases. They may go months with no release, but then might have releases every 3-7 days for a couple of months as they approach releases. You might be able to nose around their Github to see if they handle it automatically as part of their CI process.

https://github.com/prusa3d/PrusaSlicer/releases

@oursland
Copy link
Collaborator Author

Indeed. It is fairly standard for an organization to sign all artifacts that go out for distribution.

Apple supports different approaches with TestFlight to manage test and beta builds. The more common approach used in applications that are not on the App Store is to provide the signed app as a downloadable file.

GitHub supports the automated import of a signing key with a workflow. This can then be used to sign the application from the command line.

@JohnOCFII
Copy link

Sadly, tonight's build, 38553, for arm still shows as damaged. Running xattr -cr /Applications/FreeCAD.app will allow the app bundle to function.

OS: macOS 14.6.1
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.38553 (Git)
Build type: Release
Branch: main
Hash: 59c1ccec3e6b70f56eeee8f94d361019b84bd850
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.17
  * fasteners 0.5.27

@oursland
Copy link
Collaborator Author

This is due to a difference in behaviors of macOS' Gatekeeper quarantine.

For unknown architectures, as the old shell script launcher was, the application would be assumed to be Intel. For Intel architecture, a quarantined .app would permit the user to right mouse click->Open a file. For ARM64 architecture, macOS no longer permits this option and requires the quarantine attribute be removed from the .app to run it.

The correct approach to resolve this issue would be to sign the weekly images.

I am currently at a robotics conference, but once my role in the conference has concluded I will look at how to employ the GitHub workflow to sign the .app and submit a PR.

@boboxx
Copy link

boboxx commented Sep 5, 2024

For those of you looking for the fix:
sudo xattr -r -d com.apple.quarantine /Applications/FreeCAD.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants