'Application reports different architecture depending on launch method

I have made a native build (see https://www.utc.fr/~mottelet/scilab_for_macOS.html) of Scilab for M1 Macs and the application seems to trigger Rosetta2 when launched by double-clicking its icon and as a result its overall environment is erroneously reported as x86_64 instead of arm64. For example, from Scilab command line you can launch shell commands and get the output. For example uname -m yields

--> unix_g("uname -m")
 ans  =

  "x86_64

when Scilab has been launched from its icon or by using open from the terminal.

However, when the application main script is directly launched from a terminal, i.e. here by typing

me@mac-M1 ~ % /Applications/scilab-branch-6.1.app/Contents/MacOS/scilab

the same unix command from within Scilab yields the expected result since the application has been compiled for the arm64 architecture:

--> unix_g("uname -m")
 ans  =

  "arm64"

1/6/2021 update:

Running the application always calls the the main scilab script (which later calls the actual scilab-bin native binary). When the app has been double-clicked the process list obtained by ps yields

 501   643 ??         0:00.35 /bin/sh /Users/mottelet/Desktop/scilab-branch-6.1.app/Contents/MacOS/scilab
 501   708 ??         0:04.23 scilab-bin

and the Activity monitor shows the matching processes as: enter image description here enter image description here

As you guessed the shell has the wrong architecture. I have tried using

<key>LSRequiresNativeExecution</key>
<true/>

in the Info.plist but it does not change anything.

How this problem could be debugged ? It is not so easy to provide a more compact example. If some experts among the readers could help me, you just have to download the Scilab arm64 build (see the link above) and get the app from the dmg archive (notarized by Apple). At first run a native Java 8 JRE will be downloaded by Scilab. Thanks for your help and insights !

S.



Solution 1:[1]

I finally found this explanation @ https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary :

If an app doesn’t contain an executable binary, the system may run it under Rosetta translation as a precautionary measure to prevent potential runtime issues. For example, the system runs script-only apps under Rosetta translation. If you verified that your app runs correctly on both Apple silicon and Intel-based Mac computers, add the LSArchitecturePriority key to your app’s Info.plist file and list the arm64 architecture first.

However, adding LSRequiresNativeExecution or LSArchitecturePriority in Info.plist does not change anything. I thought I had something wrong inside, but even with this minimal Property List

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LSArchitecturePriority</key>
    <array>
        <string>arm64</string>
    </array>
    <key>LSRequiresNativeExecution</key>
    <true/>
    <key>CFBundleExecutable</key>
    <string>scilab</string>
</dict>
</plist>

the application starts under Rosetta.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1