diff --git a/binaries/binaries.go b/binaries/binaries.go index edba1b2d..0e2e1ac3 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -165,7 +165,7 @@ func GetEnginePath(dir, engine, binaryName string) string { } func DownloadEngine(name string, toDir string) (file string, err error) { - binaryName := platform.BinaryPlatformName() + binaryName := platform.BinaryPlatformNameDynamic() logger.Debug.Printf("checking %s...", name) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index 2600ea47..3046c5d2 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -12,9 +12,9 @@ import ( var binaryNameWithSSLCache string -// BinaryPlatformName returns the name of the prisma binary which should be used, -// for example "darwin" or "linux-openssl-1.1.x" -func BinaryPlatformName() string { +// BinaryPlatformNameDynamic returns the name of the prisma binary which should be used, +// for example "darwin" or "linux-openssl-1.1.x". This can include dynamically linked binaries. +func BinaryPlatformNameDynamic() string { if binaryNameWithSSLCache != "" { return binaryNameWithSSLCache } @@ -47,6 +47,25 @@ func BinaryPlatformName() string { return name } +// BinaryPlatformNameStatic returns the name of the prisma binary which should be used, +// for example "darwin" or "linux-static-x64". This only includes statically linked binaries. +func BinaryPlatformNameStatic() 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 + } + + return fmt.Sprintf("linux-static-%s", arch) +} + // Name returns the platform name func Name() string { return runtime.GOOS diff --git a/cli/cli.go b/cli/cli.go index 4ea17f47..a156faf8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -28,7 +28,7 @@ func Run(arguments []string, output bool) error { logger.Debug.Printf("running %s %+v", path.Join(dir, prisma), arguments) cmd := exec.Command(path.Join(dir, prisma), arguments...) //nolint:gosec - binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformName()) + binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "PRISMA_HIDE_UPDATE_MESSAGE=true") diff --git a/engine/lifecycle.go b/engine/lifecycle.go index 739c99a4..f2131786 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -72,8 +72,8 @@ func (e *QueryEngine) ensure() (string, error) { binariesPath := binaries.GlobalUnpackDir(binaries.EngineVersion) // check for darwin/windows/linux first - binaryName := platform.CheckForExtension(platform.Name(), platform.Name()) - exactBinaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformName()) + binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameStatic()) + exactBinaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) var file string // forceVersion saves whether a version check should be done, which should be disabled @@ -103,7 +103,7 @@ func (e *QueryEngine) ensure() (string, error) { file = prismaQueryEngineBinary forceVersion = false } else if qe := os.Getenv(unpack.FileEnv); qe != "" { - logger.Debug.Printf("using PRISMA_INTERNAL_QUERY_ENGINE_DIR %s", qe) + logger.Debug.Printf("using unpacked file env %s %s", unpack.FileEnv, qe) file = qe } else { if info, err := os.Stat(localExactPath); err == nil { diff --git a/generator/run.go b/generator/run.go index a4bf8108..8fc7eed5 100644 --- a/generator/run.go +++ b/generator/run.go @@ -176,7 +176,7 @@ func generateBinaries(input *Root) error { // TODO refactor for _, name := range targets { if name == "native" { - name = platform.BinaryPlatformName() + name = platform.BinaryPlatformNameDynamic() } // first, ensure they are actually downloaded @@ -200,7 +200,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err } if name == "native" { - name = platform.BinaryPlatformName() + name = platform.BinaryPlatformNameDynamic() } enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name)