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

Build ARM compatible CLI binaries #717

Closed
RobertCraigie opened this issue Jan 29, 2022 · 14 comments · Fixed by #740
Closed

Build ARM compatible CLI binaries #717

RobertCraigie opened this issue Jan 29, 2022 · 14 comments · Fixed by #740

Comments

@RobertCraigie
Copy link

I've recently switched to an M1 mac and the currently binaries provided are not compatible with this chipset.

I do not know of the best solution for this as GitHub does not yet provide runners (actions/runner-images#2187) so cross compilation is probably the only real possibility unless someone on the Prisma team would be willing to compile and publish the binaries themselves.

From having a look at the pkg README it sounds like it should be possible with something like the following command however I have not tested it.

npx pkg -t node17-darwin-arm64 --no-bytecode --public-packages "*" --public node_modules/prisma

This is relevant for Prisma Client Python as there is work being done to support ARM compiled engines: RobertCraigie/prisma-client-py#233

@RobertCraigie
Copy link
Author

This can actually be disregarded, I didn't know of Rosetta 2 which automatically translates the code from intel to M1.

Providing specific binaries for M1 would improve performance but is not strictly necessary.

@steebchen
Copy link
Owner

I have an M1 MacBook now. I can try to build arm64 Prisma CLI builds with pkg

@steebchen
Copy link
Owner

https://github.com/vercel/pkg

macos-arm64 is experimental. Be careful about the mandatory code signing requirement. The final executable has to be signed (ad-hoc signature is sufficient) with codesign utility of macOS (or ldid utility on Linux). Otherwise, the executable will be killed by kernel and the end-user has no way to permit it to run at all. pkg tries to ad-hoc sign the final executable. If necessary, you can replace this signature with your own trusted Apple Developer ID.

If this is true though, it might get more complicated...

@steebchen
Copy link
Owner

steebchen commented Feb 11, 2022

I think it worked :D I'm wondering if you @RobertCraigie have any input on how the binaries should be named. I can also build linux arm64 binaries while I'm at it I guess. Or since there will be lots of targets anyway, in theory I could also upload builds with different node versions

Just needs to be adapted here

https://github.com/prisma/prisma-client-go/blob/main/binaries/publish.sh#L20

and maybe some more code to put the targets in a variable and just loop through it for gzip+s3 upload

@RobertCraigie
Copy link
Author

Linux arm64 binaries would be great too, thank you :D

in theory I could also upload builds with different node versions

I don't think we're going to support binaries with different node versions any time soon but that would be a welcome change too :)

you @RobertCraigie have any input on how the binaries should be named

If you're wanting to stick to one node version I'd say to just try and stick to a similar naming scheme to the engine binaries, e.g.

M1 -> darwin-arm64
Linux aarch64 -> linux-arm64
Linux arm -> linux-arm (is this supported?)

And if you want to support multiple node versions you could use a similar naming schema to the OpenSSL engine versioning, e.g. linux-arm64-node12, darwin-arm64-node16

@RobertCraigie
Copy link
Author

I've also been looking into automating the CLI binary building process, would that still be possible when targeting ARM?

@janpio
Copy link
Collaborator

janpio commented Mar 2, 2022

Usually you can cross compile these, but sometimes you actually need a machine of the platform/architecture.

@steebchen
Copy link
Owner

steebchen commented Mar 2, 2022

EDIT: Unfortunately, cross compiling with arm indeed seems to be a bit tricky

@steebchen
Copy link
Owner

Actually it is not at all :D

I published the binaries in the existing bucket with this scheme:

# x64
prisma-cli-$version-darwin-x64.gz
prisma-cli-$version-linux-x64.gz
prisma-cli-$version-windows-x64.exe.gz

# arm64
prisma-cli-$version-darwin-arm64.gz
prisma-cli-$version-linux-arm64.gz
prisma-cli-$version-windows-arm64.exe.gz

where $version is at least 3.13.0

I didn't test them though, so please let me know if they don't work.

@steebchen
Copy link
Owner

From 3.14.0 I will probably stop uploading the binaries like in the old scheme, and will use the scheme above

@RobertCraigie
Copy link
Author

Thank you so much! @steebchen

Unfortunately I'm not sure if I can really test the new binaries on my machine as I have Rosetta 2 installed and I can't find a reasonable method for uninstalling it :/

But it seems to work, thank you again :D

@steebchen
Copy link
Owner

steebchen commented May 10, 2022

You can check if it's using the apple binaries by checking if the QE/CLI binary says 'Kind': 'Apple' in activitiy monitor. Note that the Go client is not using these yet though.

@Brendonovich
Copy link

Brendonovich commented May 12, 2022

@steebchen FWIW I've been using the x64 macOS and arm64 linux binaries with Prisma Client Rust and they seem to be working fine!

@steebchen
Copy link
Owner

Awesome! Thanks for letting me know @Brendonovich

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 a pull request may close this issue.

4 participants