mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 03:40:45 +08:00
Support multiple targets for windows
This commit is contained in:
parent
99ca6d5e77
commit
c2fa4b6103
@ -3,6 +3,8 @@ package build
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/wailsapp/wails/v2/internal/colour"
|
"github.com/wailsapp/wails/v2/internal/colour"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/project"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/system"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -15,8 +17,6 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/cmd/wails/internal"
|
"github.com/wailsapp/wails/v2/cmd/wails/internal"
|
||||||
"github.com/wailsapp/wails/v2/internal/gomod"
|
"github.com/wailsapp/wails/v2/internal/gomod"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/internal/system"
|
|
||||||
|
|
||||||
"github.com/leaanthony/clir"
|
"github.com/leaanthony/clir"
|
||||||
"github.com/leaanthony/slicer"
|
"github.com/leaanthony/slicer"
|
||||||
"github.com/wailsapp/wails/v2/pkg/clilogger"
|
"github.com/wailsapp/wails/v2/pkg/clilogger"
|
||||||
@ -50,7 +50,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
|
|
||||||
// Setup Platform flag
|
// Setup Platform flag
|
||||||
platform := runtime.GOOS
|
platform := runtime.GOOS
|
||||||
command.StringFlag("platform", "Platform to target", &platform)
|
command.StringFlag("platform", "Platform to target. Comma separate multiple platforms", &platform)
|
||||||
|
|
||||||
// Verbosity
|
// Verbosity
|
||||||
verbosity := 1
|
verbosity := 1
|
||||||
@ -103,28 +103,6 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
app.PrintBanner()
|
app.PrintBanner()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check platform
|
|
||||||
validPlatformArch := slicer.String([]string{
|
|
||||||
"darwin",
|
|
||||||
"darwin/amd64",
|
|
||||||
"darwin/arm64",
|
|
||||||
"darwin/universal",
|
|
||||||
"linux",
|
|
||||||
//"linux/amd64",
|
|
||||||
//"linux/arm-7",
|
|
||||||
"windows",
|
|
||||||
"windows/amd64",
|
|
||||||
"windows/arm64",
|
|
||||||
})
|
|
||||||
if !validPlatformArch.Contains(platform) {
|
|
||||||
return fmt.Errorf("platform %s is not supported. Platforms supported: %s", platform, validPlatformArch.Join(","))
|
|
||||||
}
|
|
||||||
|
|
||||||
if compress && platform == "darwin/universal" {
|
|
||||||
logger.Println("Warning: compress flag unsupported for universal binaries. Ignoring.")
|
|
||||||
compress = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup compiler path
|
// Lookup compiler path
|
||||||
compilerPath, err := exec.LookPath(compilerCommand)
|
compilerPath, err := exec.LookPath(compilerCommand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,6 +152,10 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
modeString = "Debug"
|
modeString = "Debug"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var targets slicer.StringSlicer
|
||||||
|
targets.AddSlice(strings.Split(platform, ","))
|
||||||
|
targets.Deduplicate()
|
||||||
|
|
||||||
// Create BuildOptions
|
// Create BuildOptions
|
||||||
buildOptions := &build.Options{
|
buildOptions := &build.Options{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
@ -194,18 +176,6 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
WebView2Strategy: wv2rtstrategy,
|
WebView2Strategy: wv2rtstrategy,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate platform and arch
|
|
||||||
platformSplit := strings.Split(platform, "/")
|
|
||||||
buildOptions.Platform = platformSplit[0]
|
|
||||||
if system.IsAppleSilicon {
|
|
||||||
buildOptions.Arch = "arm64"
|
|
||||||
} else {
|
|
||||||
buildOptions.Arch = runtime.GOARCH
|
|
||||||
}
|
|
||||||
if len(platformSplit) == 2 {
|
|
||||||
buildOptions.Arch = platformSplit[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
||||||
@ -213,8 +183,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
// Write out the system information
|
// Write out the system information
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
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, "Platforms: \t%s\n", platform)
|
||||||
fmt.Fprintf(w, "Arch: \t%s\n", buildOptions.Arch)
|
|
||||||
fmt.Fprintf(w, "Compiler: \t%s\n", compilerPath)
|
fmt.Fprintf(w, "Compiler: \t%s\n", compilerPath)
|
||||||
fmt.Fprintf(w, "Build Mode: \t%s\n", modeString)
|
fmt.Fprintf(w, "Build Mode: \t%s\n", modeString)
|
||||||
fmt.Fprintf(w, "Skip Frontend: \t%t\n", skipFrontend)
|
fmt.Fprintf(w, "Skip Frontend: \t%t\n", skipFrontend)
|
||||||
@ -223,7 +192,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
fmt.Fprintf(w, "Clean Build Dir: \t%t\n", buildOptions.CleanBuildDirectory)
|
fmt.Fprintf(w, "Clean Build Dir: \t%t\n", buildOptions.CleanBuildDirectory)
|
||||||
fmt.Fprintf(w, "LDFlags: \t\"%s\"\n", buildOptions.LDFlags)
|
fmt.Fprintf(w, "LDFlags: \t\"%s\"\n", buildOptions.LDFlags)
|
||||||
fmt.Fprintf(w, "Tags: \t[%s]\n", strings.Join(buildOptions.UserTags, ","))
|
fmt.Fprintf(w, "Tags: \t[%s]\n", strings.Join(buildOptions.UserTags, ","))
|
||||||
if len(buildOptions.OutputFile) > 0 {
|
if len(buildOptions.OutputFile) > 0 && targets.Length() == 1 {
|
||||||
fmt.Fprintf(w, "Output File: \t%s\n", buildOptions.OutputFile)
|
fmt.Fprintf(w, "Output File: \t%s\n", buildOptions.OutputFile)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
@ -234,30 +203,102 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return doBuild(buildOptions)
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
projectOptions, err := project.Load(cwd)
|
||||||
|
|
||||||
|
// Check platform
|
||||||
|
validPlatformArch := slicer.String([]string{
|
||||||
|
"darwin",
|
||||||
|
"darwin/amd64",
|
||||||
|
"darwin/arm64",
|
||||||
|
"darwin/universal",
|
||||||
|
"linux",
|
||||||
|
//"linux/amd64",
|
||||||
|
//"linux/arm-7",
|
||||||
|
"windows",
|
||||||
|
"windows/amd64",
|
||||||
|
"windows/arm64",
|
||||||
|
})
|
||||||
|
|
||||||
|
targets.Each(func(platform string) {
|
||||||
|
|
||||||
|
if !validPlatformArch.Contains(platform) {
|
||||||
|
buildOptions.Logger.Println("platform '%s' is not supported - skipping. Supported platforms: %s", platform, validPlatformArch.Join(","))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
desiredFilename := projectOptions.OutputFilename
|
||||||
|
if desiredFilename == "" {
|
||||||
|
desiredFilename = projectOptions.Name
|
||||||
|
}
|
||||||
|
desiredFilename = strings.TrimSuffix(desiredFilename, ".exe")
|
||||||
|
|
||||||
|
// Calculate platform and arch
|
||||||
|
platformSplit := strings.Split(platform, "/")
|
||||||
|
buildOptions.Platform = platformSplit[0]
|
||||||
|
if system.IsAppleSilicon {
|
||||||
|
buildOptions.Arch = "arm64"
|
||||||
|
} else {
|
||||||
|
buildOptions.Arch = runtime.GOARCH
|
||||||
|
}
|
||||||
|
if len(platformSplit) == 2 {
|
||||||
|
buildOptions.Arch = platformSplit[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
banner := "Building target: " + platform
|
||||||
|
logger.Println(banner)
|
||||||
|
logger.Println(strings.Repeat("-", len(banner)))
|
||||||
|
|
||||||
|
if compress && platform == "darwin/universal" {
|
||||||
|
logger.Println("Warning: compress flag unsupported for universal binaries. Ignoring.")
|
||||||
|
compress = false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch buildOptions.Platform {
|
||||||
|
case "linux":
|
||||||
|
if runtime.GOOS != "linux" {
|
||||||
|
logger.Println("Crosscompiling to Linux not currently supported.\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "darwin":
|
||||||
|
if runtime.GOOS != "darwin" {
|
||||||
|
logger.Println("Crosscompiling to Mac not currently supported.\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if targets.Length() > 1 {
|
||||||
|
// target filename
|
||||||
|
switch buildOptions.Platform {
|
||||||
|
case "windows":
|
||||||
|
desiredFilename = fmt.Sprintf("%s-%s.exe", desiredFilename, buildOptions.Arch)
|
||||||
|
default:
|
||||||
|
desiredFilename = fmt.Sprintf("%s-%s-%s", desiredFilename, buildOptions.Platform, buildOptions.Arch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildOptions.OutputFile = desiredFilename
|
||||||
|
|
||||||
|
// Start Time
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
outputFilename, err := build.Build(buildOptions)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("Error: ", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
buildOptions.IgnoreFrontend = true
|
||||||
|
|
||||||
|
// Output stats
|
||||||
|
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.\n", outputFilename, time.Since(start).Round(time.Millisecond).String()))
|
||||||
|
|
||||||
|
})
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// doBuild is our main build command
|
|
||||||
func doBuild(buildOptions *build.Options) error {
|
|
||||||
|
|
||||||
// Start Time
|
|
||||||
start := time.Now()
|
|
||||||
|
|
||||||
outputFilename, err := build.Build(buildOptions)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output stats
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
buildOptions.Logger.Println("")
|
|
||||||
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.", outputFilename, elapsed.Round(time.Millisecond).String()))
|
|
||||||
buildOptions.Logger.Println("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkGoModVersion(logger *clilogger.CLILogger, updateGoMod bool) error {
|
func checkGoModVersion(logger *clilogger.CLILogger, updateGoMod bool) error {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -548,7 +548,7 @@ func (b *BaseBuilder) BuildFrontend(outputLogger *clilogger.CLILogger) error {
|
|||||||
outputLogger.Println("No Install command. Skipping.")
|
outputLogger.Println("No Install command. Skipping.")
|
||||||
} else {
|
} else {
|
||||||
// Do install if needed
|
// Do install if needed
|
||||||
outputLogger.Print("Installing frontend dependencies: ")
|
outputLogger.Print(" - Installing frontend dependencies: ")
|
||||||
if verbose {
|
if verbose {
|
||||||
outputLogger.Println("")
|
outputLogger.Println("")
|
||||||
outputLogger.Println(" Install command: '" + b.projectData.InstallCommand + "'")
|
outputLogger.Println(" Install command: '" + b.projectData.InstallCommand + "'")
|
||||||
@ -576,7 +576,7 @@ func (b *BaseBuilder) BuildFrontend(outputLogger *clilogger.CLILogger) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
outputLogger.Print("Compiling frontend: ")
|
outputLogger.Print(" - Compiling frontend: ")
|
||||||
cmd := strings.Split(buildCommand, " ")
|
cmd := strings.Split(buildCommand, " ")
|
||||||
if verbose {
|
if verbose {
|
||||||
outputLogger.Println("")
|
outputLogger.Println("")
|
||||||
|
@ -117,7 +117,7 @@ func Build(options *Options) (string, error) {
|
|||||||
// If we are building for windows, we will need to generate the asset bundle before
|
// If we are building for windows, we will need to generate the asset bundle before
|
||||||
// compilation. This will be a .syso file in the project root
|
// compilation. This will be a .syso file in the project root
|
||||||
if options.Pack && options.Platform == "windows" {
|
if options.Pack && options.Platform == "windows" {
|
||||||
outputLogger.Print("Generating bundle assets: ")
|
outputLogger.Print(" - Generating bundle assets: ")
|
||||||
err := packageApplicationForWindows(options)
|
err := packageApplicationForWindows(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -134,7 +134,7 @@ func Build(options *Options) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile the application
|
// Compile the application
|
||||||
outputLogger.Print("Compiling application: ")
|
outputLogger.Print(" - Compiling application: ")
|
||||||
|
|
||||||
if options.Platform == "darwin" && options.Arch == "universal" {
|
if options.Platform == "darwin" && options.Arch == "universal" {
|
||||||
outputFile := builder.OutputFilename(options)
|
outputFile := builder.OutputFilename(options)
|
||||||
|
Loading…
Reference in New Issue
Block a user