2

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.

Stéphane Mottelet
  • 2,853
  • 1
  • 9
  • 26
  • I don't know scilab, but doesn't `unix_g()` run things as a subprocess, which means its architecture isn't particularly related to the parent process? Check your process's architecture in the Activity Monitor app (in the Type column, look for "Apple" vs "Intel") and see what that says. – Gordon Davisson Jun 30 '21 at 19:14
  • I have updated the question. The final launch of the `scilab-bin` native arm64 (not fat) binary in the shell script can be forced by `arch -arm64 scilab-bin`, and the later call of `uname -m` yields `arm64`. However, I would like to understand why double-clicking the application icon uses the wrong mode when calling `/bin/sh`. – Stéphane Mottelet Jul 01 '21 at 06:42
  • This potentially looks relevant: https://developer.apple.com/forums/thread/672372 – Att Righ Jun 05 '23 at 23:04

2 Answers2

2

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.

Stéphane Mottelet
  • 2,853
  • 1
  • 9
  • 26
0

Related to the question, you can also use arch and ARCHPREFERENCES to set a "priority list" for arch to use. For example:

# launch with arm64 if possible, or fall back to x86_64
ARCHPREFERENCES=arm64,x86_64 arch /Applications/scilab-branch-6.1.app/Contents/MacOS/scilab

Documentation: https://www.unix.com/man-page/osx/1/arch/#~:~ARCHPREFERENCE

Zach Bloomquist
  • 5,309
  • 29
  • 44