Skip to content

[macOS] Add Architecture Priority to Info.plist #3727

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

Merged
merged 3 commits into from
Dec 29, 2023

Conversation

shinra-electric
Copy link
Contributor

@shinra-electric shinra-electric commented Dec 21, 2023

This allows the app bundle to be launched natively on Arm without the need for Rosetta.

On macOS, when launching an app bundle with a script (like soh does) it currently defaults to running the script with x64, though the app will actually launch using arm64. What this means is that Rosetta must be installed in order to launch the app, which is not optimal.

The solution is to add the LSArchitecturePriority key to the info.plist, and specify for arm64 to be run first. This will not affect Intel Macs, as if the first on the list is not available, the next will be used.

See here and here for details.

Testing:

  • See if the app launches on an Arm Mac without Rosetta installed
  • See if the app runs on an Arm Mac under Rosetta
  • See if the app launches on an Intel Mac

Edit: The information came from issue #1553

Build Artifacts

This allows the app bundle to be launched natively on Arm without the need for Rosetta.
@shinra-electric shinra-electric changed the title Add Architecture Priority to Info.plist [macOS] Add Architecture Priority to Info.plist Dec 21, 2023
@nlordell
Copy link

nlordell commented Dec 21, 2023

nit: I would also get rid of

arch_name="$(uname -m)"
launch_arch="arm64"
if [ "${arch_name}" = "x86_64" ] && [ "$(sysctl -in sysctl.proc_translated)" != "1" ]; then
launch_arch="x86_64"
fi
arch -${launch_arch} "$RESPATH"/soh-macos

As (if this works) forcing a specific architecture with arch should no longer be needed (and in fact, I would argue that it is slightly incorrect, as it ignores application bundle architecture settings - i.e. you can't force launch soh with rosetta).

Shouldn't be necessary now...
@Archez
Copy link
Contributor

Archez commented Dec 21, 2023

You removed the arch stuff but didn't retain opening the actual soh binary soh-macOS.
You can refer to the git history for how the binary was executed prior to arch being added.

Accidentally removed launching the binary from the script.
@nlordell
Copy link

Are the binaries uploaded anywhere for testing, or should I build and test locally? (I have a Rosetta-free Apple Silicon Mac to test the changes on).

@Archez
Copy link
Contributor

Archez commented Dec 21, 2023

Are the binaries uploaded anywhere for testing, or should I build and test locally? (I have a Rosetta-free Apple Silicon Mac to test the changes on).

Binaries are in the PR description.

I tested on my M1 with rosetta installed and it seemed to have the "Open with Rosetta" toggle automatically checked in the .app "Get Info" after downloading/extracting (unless macOS carried this over from the previous app install).

@shinra-electric
Copy link
Contributor Author

shinra-electric commented Dec 21, 2023

... it seemed to have the "Open with Rosetta" toggle automatically checked in the .app "Get Info" after downloading/extracting

I got that too, but if I toggle it off, delete the builds and redownload then the option is off. So it might be from a saved setting somewhere...

Edit: The preferences are saved in ~/Library/Preferences/com.apple.LaunchServices/com.apple.LaunchServices.plist with the Architectures for arm64 key

@Archez
Copy link
Contributor

Archez commented Dec 21, 2023

Confirmed the following scenarios:

Silicon Mac with Rosetta installed - SoH with "Open with Rosetta": ✅ Runs in Rosetta mode as expected
Silicon Mac with Rosetta installed - SoH without "Open with Rosetta": ✅ Runs in native mode as expected

(both the main process and the shell script/app run in the appropriate mode)

Confirmed via comparing the running PIDs against fuser /usr/libexec/rosetta/runtime

@nlordell
Copy link

Binaries are in the PR description.

🙈 - oops, that's embarrassing, don't know how I missed that.

Silicon Mac without Rosetta installed: ✅ launches without prompting to install Rosetta (and obviously runs in native mode)

@nlordell
Copy link

Another useful test for those with Rosetta would be to toggle the "Open with Rosetta" option and see if it actually runs in Rosetta (as it theoretically should).

Might be worth a mention in the release notes, as some may need to manually uncheck the "Open with Rosetta" option as @Archez did.

@shinra-electric
Copy link
Contributor Author

Another useful test for those with Rosetta would be to toggle the "Open with Rosetta" option and see if it actually runs in Rosetta (as it theoretically should).

Archez confirmed that above. I added confirmation in the OP just now.

@nlordell
Copy link

nlordell commented Dec 22, 2023

Archez confirmed that above. I added confirmation in the OP just now.

What I mean is to check that "force running with Rosetta" (i.e. run x86_64 binary on Apple Silicon) works as expected. I don't think anyone would ever do this, but it should work.

@shinra-electric
Copy link
Contributor Author

What I mean is to check that "force running with Rosetta" (i.e. run x86_64 binary on Apple Silicon) works as expected. I don't think anyone would ever do this, but it should work.

From his two tests, that's what I understand the first one to be:
Silicon Mac with Rosetta installed - SoH with "Open with Rosetta": ✅ Runs in Rosetta mode as expected

@shinra-electric
Copy link
Contributor Author

I tested this on an Intel Mac, and it works fine.

Ready for review.

@Archez Archez merged commit b7342a7 into HarbourMasters:develop Dec 29, 2023
@shinra-electric shinra-electric deleted the macos-plist branch December 30, 2023 00:23
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.

3 participants