5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:20:51 +08:00

[v2] Target ARM on Apple Silicon, even if CLI is compiled for AMD64

This commit is contained in:
Lea Anthony 2021-07-03 16:32:47 +10:00
parent 1f3351ffa5
commit 642c1d5ec5
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 32 additions and 4 deletions

View File

@ -4,11 +4,14 @@ import (
"fmt"
"io"
"os"
"os/exec"
"runtime"
"strings"
"text/tabwriter"
"time"
"github.com/wailsapp/wails/v2/internal/system"
"github.com/wailsapp/wails/v2/internal/shell"
"github.com/leaanthony/clir"
@ -121,6 +124,12 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
compress = false
}
// Lookup compiler path
compilerPath, err := exec.LookPath(compilerCommand)
if err != nil {
return fmt.Errorf("unable to find compiler: %s", compilerCommand)
}
// Tags
userTags := []string{}
for _, tag := range strings.Split(tags, " ") {
@ -176,11 +185,17 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
// Calculate platform and arch
platformSplit := strings.Split(platform, "/")
buildOptions.Platform = platformSplit[0]
buildOptions.Arch = runtime.GOARCH
if system.IsAppleSilicon() {
buildOptions.Arch = "arm64"
} else {
buildOptions.Arch = runtime.GOARCH
}
if len(platformSplit) == 2 {
buildOptions.Arch = platformSplit[1]
}
println("Build arch =", buildOptions.Arch)
// Start a new tabwriter
w := new(tabwriter.Writer)
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
@ -195,7 +210,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
fmt.Fprintf(w, "App Type: \t%s\n", buildOptions.OutputType)
fmt.Fprintf(w, "Platform: \t%s\n", buildOptions.Platform)
fmt.Fprintf(w, "Arch: \t%s\n", buildOptions.Arch)
fmt.Fprintf(w, "Compiler: \t%s\n", buildOptions.Compiler)
fmt.Fprintf(w, "Compiler: \t%s\n", compilerPath)
fmt.Fprintf(w, "Compress: \t%t\n", buildOptions.Compress)
fmt.Fprintf(w, "Build Mode: \t%s\n", buildModeText)
fmt.Fprintf(w, "Package: \t%t\n", buildOptions.Pack)

View File

@ -1,10 +1,12 @@
package system
import (
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
"os/exec"
"strings"
"syscall"
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
)
// Info holds information about the current operating system,
@ -105,3 +107,14 @@ func checkDocker() *packagemanager.Dependancy {
External: false,
}
}
// IsAppleSilicon returns true if the app is running on Apple Silicon
// Credit: https://www.yellowduck.be/posts/detecting-apple-silicon-via-go/
func IsAppleSilicon() bool {
r, err := syscall.Sysctl("sysctl.proc_translated")
if err != nil {
return false
}
return r == "\x00\x00\x00" || r == "\x01\x00\x00"
}