Skip to content

Commit

Permalink
add static binary name
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Jun 18, 2023
1 parent 6371fd6 commit 3835e01
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion binaries/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 22 additions & 3 deletions binaries/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions engine/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions generator/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3835e01

Please sign in to comment.