From ab0f36249d1397c5b87de4d12d1975f23e0f9af1 Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Fri, 16 Jun 2023 15:53:33 -0400 Subject: [PATCH 1/5] feat: add arch arg to CLI url --- binaries/binaries.go | 5 +++-- binaries/platform/platform.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index b1a1af2e..357b362f 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -22,7 +22,7 @@ const PrismaVersion = "4.15.0" 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") diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index b5195f2c..db85ec8e 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -44,6 +44,17 @@ func Name() string { return runtime.GOOS } +func Arch() string { + // should be x86 or arm64 + if runtime.GOARCH == "amd64" { + return "x64" + } else if runtime.GOARCH == "arm64" { + return "arm64" + } else { + panic(fmt.Errorf("unsupported arch: %s", runtime.GOARCH)) + } +} + // CheckForExtension adds a .exe extension on windows (e.g. .gz -> .exe.gz) func CheckForExtension(platform, path string) string { if platform == "windows" { From c59b4310f6dc768ce045d78c3c3830d0fdbf4b12 Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Fri, 16 Jun 2023 16:05:46 -0400 Subject: [PATCH 2/5] fix: add arch --- binaries/binaries.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 357b362f..df4dac79 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -141,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) From f8a7cf4f14c92e0c5c0870f4be57297c49d48d1e Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Fri, 16 Jun 2023 16:06:57 -0400 Subject: [PATCH 3/5] chore: address CR --- binaries/platform/platform.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index db85ec8e..9efd781c 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -45,13 +45,14 @@ func Name() string { } func Arch() string { - // should be x86 or arm64 - if runtime.GOARCH == "amd64" { + switch runtime.GOARCH { + case "amd64": return "x64" - } else if runtime.GOARCH == "arm64" { + case "arm64": return "arm64" - } else { - panic(fmt.Errorf("unsupported arch: %s", runtime.GOARCH)) + default: + log.Printf("warning: unsupported architecture %s, falling back to x64", runtime.GOARCH) + return "x64" } } From ebddfe83b7b7149fc282bcb86295cb0f4c1e83f5 Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Fri, 16 Jun 2023 16:16:33 -0400 Subject: [PATCH 4/5] chore: fix --- binaries/binaries.go | 2 +- binaries/platform/platform.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index df4dac79..edba1b2d 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -18,7 +18,7 @@ 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. diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index 9efd781c..ed84b961 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -3,6 +3,7 @@ package platform import ( "fmt" + "log" "os/exec" "regexp" "runtime" From 315f81da4bcfcb2e96bdbbcbd80b85c3db8d0b0c Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Fri, 16 Jun 2023 16:21:41 -0400 Subject: [PATCH 5/5] chore: update BinaryPlatformName with architecture --- binaries/platform/platform.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index ed84b961..2600ea47 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -20,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()