From 62806c8c3e87f472002663d35d61e156f11f3ad3 Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Sat, 17 Jun 2023 20:31:40 -0400 Subject: [PATCH] feat(binaries): support arm64 CLI & engine binaries (#874) --- binaries/binaries.go | 9 +++++---- binaries/platform/platform.go | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index b1a1af2e..edba1b2d 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -18,11 +18,11 @@ import ( const PrismaVersion = "4.15.0" // EngineVersion is a hardcoded version of the Prisma Engine. -// The versions can be found under https://github.com/prisma/prisma-engines/commits/master +// The versions can be found under https://github.com/prisma/prisma-engines/commits/main const EngineVersion = "70a9adfd11f836696eca398396544fe07a8d8edb" // PrismaURL points to an S3 bucket URL where the CLI binaries are stored. -var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-x64.gz" +var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-%s.gz" // EngineURL points to an S3 bucket URL where the Prisma engines are stored. var EngineURL = "https://binaries.prisma.sh/all_commits/%s/%s/%s.gz" @@ -54,7 +54,8 @@ func init() { // PrismaCLIName returns the local file path of where the CLI lives func PrismaCLIName() string { variation := platform.Name() - return fmt.Sprintf("prisma-cli-%s-x64", variation) + arch := platform.Arch() + return fmt.Sprintf("prisma-cli-%s-%s", variation, arch) } var baseDirName = path.Join("prisma", "binaries") @@ -140,7 +141,7 @@ func FetchNative(toDir string) error { func DownloadCLI(toDir string) error { cli := PrismaCLIName() to := platform.CheckForExtension(platform.Name(), path.Join(toDir, cli)) - url := platform.CheckForExtension(platform.Name(), fmt.Sprintf(PrismaURL, "prisma-cli", PrismaVersion, platform.Name())) + url := platform.CheckForExtension(platform.Name(), fmt.Sprintf(PrismaURL, "prisma-cli", PrismaVersion, platform.Name(), platform.Arch())) logger.Debug.Printf("ensuring CLI %s from %s to %s", cli, url, to) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index b5195f2c..2600ea47 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -3,6 +3,7 @@ package platform import ( "fmt" + "log" "os/exec" "regexp" "runtime" @@ -19,15 +20,22 @@ func BinaryPlatformName() string { } platform := Name() + arch := Arch() + // other supported platforms are darwin and windows if platform != "linux" { + // special case for darwin arm64 + if platform == "darwin" && arch == "arm64" { + return "darwin-arm64" + } + // otherwise, return `darwin` or `windows` return platform } distro := getLinuxDistro() if distro == "alpine" { - return "linux-static-x64" + return fmt.Sprintf("linux-static-%s", arch) } ssl := getOpenSSL() @@ -44,6 +52,18 @@ func Name() string { return runtime.GOOS } +func Arch() string { + switch runtime.GOARCH { + case "amd64": + return "x64" + case "arm64": + return "arm64" + default: + log.Printf("warning: unsupported architecture %s, falling back to x64", runtime.GOARCH) + return "x64" + } +} + // CheckForExtension adds a .exe extension on windows (e.g. .gz -> .exe.gz) func CheckForExtension(platform, path string) string { if platform == "windows" {