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

feat(binaries): support arm64 CLI & engine binaries #874

Merged
merged 5 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions binaries/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
22 changes: 21 additions & 1 deletion binaries/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package platform

import (
"fmt"
"log"
"os/exec"
"regexp"
"runtime"
Expand All @@ -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()
Expand All @@ -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" {
Expand Down