PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
45.54k stars 7.3k forks source link

Rosetta still required for M1 Mac #17130

Open ghost opened 2 years ago

ghost commented 2 years ago

Prerequisites

Steps to reproduce

Installed the latest 7.3.0 preview 3 (powershell-7.3.0-preview.3-osx-arm64.pkg) on my M1 Mac and I'm still being prompted to install Rosetta when starting PowerShell-preview from the launch pad, even though the installation says it was successful. Writing pwsh in the console just returns "command not found".

Tried the latest stable 7.2.2 release as well, but it won't even start the installer without Rosetta.

Expected behavior

Expect macOS ARM64 build to work natively without Rosetta layer.

Actual behavior

Prompted to install Rosetta after installation. pwsh command not found in terminal.

Error details

No response

Environment data

Not applicable.

Visuals

No response

ghost commented 2 years ago

So I figured out the issue: the preview version uses pwsh-preview instead of just pwsh to start powershell. I also managed to install the stable 7.2.2 version by installing the binary archives instead of the .pkg installer. This however doesn't include the launch pad Powershell entry.

What exactly does launching Powershell from launch pad do and why does it require Rosetta? And also, the documentation mentions that dependencies have to be manually installed when installing using the binary archive method. Which dependencies are missing that are included with the .pkg installer?

thezim commented 2 years ago

The launcher app is just a shell script. In its current form it configured to use bash and use the open command.

Try opening bash first then use this to see if you get the same behavior.

open pwsh-preview

There is a possibility that the plist file in the launcher may need to be updated to account for the new arm architecture. It’s possible Mac OS is seeing something in there and thinking it a legacy x86 app. I can’t verify any of this as I do not have an arm Mac.

ghost commented 2 years ago

Tried executing open pwsh-preview in bash terminal and got: The file /Users/<username>/pwsh-preview does not exist.

Where is the shell script and plist file for the launcher located?

Edit: Found both files inside the PowerShell-preview.app/Contents folder. The .sh script runs open /usr/local/bin/pwsh-preview Running this from terminal works correctly and starts a PS session. The plist.info file contains the following:

<?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>CFBundleExecutable</key>
    <string>PowerShell.sh</string>
    <key>CFBundleGetInfoString</key>
    <string>7.3.0-preview.3</string>
    <key>CFBundleIconFile</key>
    <string>Powershell-preview</string>
    <key>CFBundleIdentifier</key>
    <string>com.microsoft.powershell-preview</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>PowerShell</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>7.3.0-preview.3</string>
    <key>CFBundleSupportedPlatforms</key>
    <array>
        <string>MacOSX</string>
    </array>
    <key>CFBundleVersion</key>
    <string>7.3.0-preview.3</string>
</dict>
</plist>

Could something in this file be missing or misconfigured?

francisceril commented 2 years ago

I get the same issue when installing latest version (7.2.3 as of writing) via Homebrew. It doesn't complete and requires installation of Rosetta 2. At this point I'm not sure if it's an issue with Homebrew or with PowerShell for M1 Macs.

nixtar commented 2 years ago

I got this on an M1 device using powershell-7.2.4-osx-arm64.pkg and just double clicking on it and using the installer GUI.

I think there may be something in the PKGs thats indicating that is contains some x86 requirements.

nixtar commented 2 years ago

Did a big of a dig into this an I believe its due to 2 files in the ARM64 package still being compiled as Intel x64 only. My original assumption about the PKG having some kind of flag appears to be false. The macos installer process must scan over binaries within the pkg to detect any that require Rosetta.

Looking at powershell-7.2.4-osx-arm64.pkg with the app "Suspicious Package" I was able to query for executables/libraries based on Apple Silicon support and found that the following files are not ARM64:

/usr/local/microsoft/powershell/7/libmi.dylib /usr/local/microsoft/powershell/7/libpsrpclient.dylib

image image

nixtar commented 2 years ago

FYI recently released powershell-7.2.5-osx-arm64.pkg also affected: image

thezim commented 2 years ago

Are these files still required?

2631

cathode911 commented 2 years ago

Still not fixed and causes sight inconvenience for those who do not use rosetta emulated apps at all.

rhubarb-geek-nz commented 2 years ago

see discussion

Have created package of 7.2.6 for macOS ARM64 without Rosetta, required change to both installer and the macOS application icon app.

thezim commented 2 years ago

see discussion

Have created package of 7.2.6 for macOS ARM64 without Rosetta, required change to both installer and the macOS application icon

I see you are repackaging and signing it with your personal certificate. While your fix addresses the issue this type of cert swap is typically frowned upon. You may even get a take down notice. You should do an official pull request for this repo.

rhubarb-geek-nz commented 2 years ago

The certificate is purely to show that the package has not been tampered with. It is not an assertion of copyright over any of the packaged contents. The original licenses are all in place.

The source of my changes is at https://sourceforge.net/p/rhubarb-pi/code/HEAD/tree/branches/darwin/pkg/powershell/ and you are more than welcome to use whatever fix is appropriate.

I don't have a pull request for your build system and will leave that up to you.

My intention is certainly to remove my package once there is an official package that fixes the problem.

However I can take it down now if that solves the problem.

rhubarb pi / Code / [r199] /branches/darwin/pkg/powershell
rhubarb-geek-nz commented 2 years ago

I see you are repackaging and signing it with your personal certificate. While your fix addresses the issue this type of cert swap is typically frowned upon. You may even get a take down notice. You should do an official pull request for this repo.

Just a clarification, the PowerShell Core project is covered by the MIT license.

https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt

I have fully complied with this license and more.

GitHub
PowerShell/LICENSE.txt at master · PowerShell/PowerShell
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
cathode911 commented 2 years ago

Still not fixed in official repo?

Nova-Logic commented 1 year ago

how many years would be spent to replace just 2 libraries?!

AntoineHus commented 11 months ago

Hello

Are you open to correct it ? if yes, Can we PR the change ?

rhubarb-geek-nz commented 11 months ago

Are you open to correct it ? if yes, Can we PR the change ?

I am not in a position to make a PR because I don't understand the project's release procedures and how it creates a deliverable package.

That said, I am maintaining my patch script and still able to create a working package from the contents of the official one by making some small changes.

https://github.com/PowerShell/PowerShell/issues/18548

rhubarb-geek-nz commented 11 months ago

I have just unpacked the published powershell-7.4.0-osx-arm64.pkg to validate the contents

Use xar to unpack the package, then cpio to extract the contents, see my package.sh for the arguments.

As I have described in my README the Applications/PowerShell.app/Contents/MacOS/PowerShell.sh is a script file with the contents

#!/usr/bin/env bash
open /usr/local/bin/pwsh

I replace this with a compiled ARM64 application still with the same name using the following source

#include <stdlib.h>
#include <unistd.h>

int main(int argc,char **argv)
{
    char *args[]={
        "/usr/bin/open",
        "/usr/local/bin/pwsh",
        NULL
    };

    execv(args[0],args);

    return 1;
}

This is all in my git repository.

The important part of testing this fix is using an ARM Mac which has never had Rosetta installed.