mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 14:42:03 +08:00
[v2] Target ARM on Apple Silicon, even if CLI is compiled for AMD64
This commit is contained in:
parent
1f3351ffa5
commit
642c1d5ec5
@ -4,11 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/wailsapp/wails/v2/internal/system"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/internal/shell"
|
"github.com/wailsapp/wails/v2/internal/shell"
|
||||||
|
|
||||||
"github.com/leaanthony/clir"
|
"github.com/leaanthony/clir"
|
||||||
@ -121,6 +124,12 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
compress = false
|
compress = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lookup compiler path
|
||||||
|
compilerPath, err := exec.LookPath(compilerCommand)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to find compiler: %s", compilerCommand)
|
||||||
|
}
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
userTags := []string{}
|
userTags := []string{}
|
||||||
for _, tag := range strings.Split(tags, " ") {
|
for _, tag := range strings.Split(tags, " ") {
|
||||||
@ -176,11 +185,17 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
// Calculate platform and arch
|
// Calculate platform and arch
|
||||||
platformSplit := strings.Split(platform, "/")
|
platformSplit := strings.Split(platform, "/")
|
||||||
buildOptions.Platform = platformSplit[0]
|
buildOptions.Platform = platformSplit[0]
|
||||||
buildOptions.Arch = runtime.GOARCH
|
if system.IsAppleSilicon() {
|
||||||
|
buildOptions.Arch = "arm64"
|
||||||
|
} else {
|
||||||
|
buildOptions.Arch = runtime.GOARCH
|
||||||
|
}
|
||||||
if len(platformSplit) == 2 {
|
if len(platformSplit) == 2 {
|
||||||
buildOptions.Arch = platformSplit[1]
|
buildOptions.Arch = platformSplit[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Build arch =", buildOptions.Arch)
|
||||||
|
|
||||||
// Start a new tabwriter
|
// Start a new tabwriter
|
||||||
w := new(tabwriter.Writer)
|
w := new(tabwriter.Writer)
|
||||||
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
|
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, "App Type: \t%s\n", buildOptions.OutputType)
|
||||||
fmt.Fprintf(w, "Platform: \t%s\n", buildOptions.Platform)
|
fmt.Fprintf(w, "Platform: \t%s\n", buildOptions.Platform)
|
||||||
fmt.Fprintf(w, "Arch: \t%s\n", buildOptions.Arch)
|
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, "Compress: \t%t\n", buildOptions.Compress)
|
||||||
fmt.Fprintf(w, "Build Mode: \t%s\n", buildModeText)
|
fmt.Fprintf(w, "Build Mode: \t%s\n", buildModeText)
|
||||||
fmt.Fprintf(w, "Package: \t%t\n", buildOptions.Pack)
|
fmt.Fprintf(w, "Package: \t%t\n", buildOptions.Pack)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"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,
|
// Info holds information about the current operating system,
|
||||||
@ -105,3 +107,14 @@ func checkDocker() *packagemanager.Dependancy {
|
|||||||
External: false,
|
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"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user