diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index ba9a8c254..63cbff0e7 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -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) diff --git a/v2/internal/system/system.go b/v2/internal/system/system.go index b7061ea64..8b70b1020 100644 --- a/v2/internal/system/system.go +++ b/v2/internal/system/system.go @@ -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" +}