Skip to content

Commit

Permalink
fix: deno binary arch
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Jul 4, 2023
1 parent 673a480 commit 4330ef6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
24 changes: 7 additions & 17 deletions internal/utils/deno.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,14 @@ func InstallOrUpgradeDeno(ctx context.Context, fsys afero.Fs) error {
}

// 1. Determine OS triple
var assetFilename string
assetFilename, err := getDenoAssetFileName()
if err != nil {
return err
}
assetRepo := "denoland/deno"
{
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
assetFilename = "deno-x86_64-apple-darwin.zip"
} else if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
assetFilename = "deno-aarch64-apple-darwin.zip"
} else if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
assetFilename = "deno-x86_64-unknown-linux-gnu.zip"
} else if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
// TODO: version pin to official release once available https://github.com/denoland/deno/issues/1846
assetRepo = "LukeChannings/deno-arm64"
assetFilename = "deno-linux-arm64.zip"
} else if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
assetFilename = "deno-x86_64-pc-windows-msvc.zip"
} else {
return errors.New("Platform " + runtime.GOOS + "/" + runtime.GOARCH + " is currently unsupported for Functions.")
}
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
// TODO: version pin to official release once available https://github.com/denoland/deno/issues/1846
assetRepo = "LukeChannings/deno-arm64"
}

// 2. Download & install Deno binary.
Expand Down
28 changes: 28 additions & 0 deletions internal/utils/deno_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build darwin

package utils

import (
"fmt"
"syscall"
)

func getDenoAssetFileName() (string, error) {
// Simple runtime.GOARCH detection doesn't work if the CLI is
// running under Rosetta:
// https://github.com/supabase/cli/issues/1266. So as a workaround
// we use Apple Silicon detection:
// https://www.yellowduck.be/posts/detecting-apple-silicon-via-go.
_, err := syscall.Sysctl("sysctl.proc_translated")
if err != nil {
if err.Error() == "no such file or directory" {
// Running on Intel Mac.
return "deno-x86_64-apple-darwin.zip", nil
} else {
return "", fmt.Errorf("failed to determine OS triple: %w", err)
}
} else {
// Running on Apple Silicon.
return "deno-aarch64-apple-darwin.zip", nil
}
}
21 changes: 21 additions & 0 deletions internal/utils/deno_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !darwin

package utils

import (
"errors"
"runtime"
)

func getDenoAssetFileName() (string, error) {
if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
return "deno-x86_64-unknown-linux-gnu.zip", nil
} else if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
// TODO: version pin to official release once available https://github.com/denoland/deno/issues/1846
return "deno-linux-arm64.zip", nil
} else if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
return "deno-x86_64-pc-windows-msvc.zip", nil
} else {
return "", errors.New("Platform " + runtime.GOOS + "/" + runtime.GOARCH + " is currently unsupported for Functions.")
}
}

0 comments on commit 4330ef6

Please sign in to comment.