From 8be2a39dafd9d0121f73bd1c4acf4c4a574d5dbe Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 17 May 2021 19:51:43 +1000 Subject: [PATCH] [windows] Generate syso file for windows builds --- v2/pkg/commands/build/build.go | 24 +++++++++++++++++++++-- v2/pkg/commands/build/packager_windows.go | 16 ++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index 9ee38419..96000314 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -2,6 +2,7 @@ package build import ( "fmt" + "log" "os" "path/filepath" "runtime" @@ -121,6 +122,25 @@ func Build(options *Options) (string, error) { return "", err } + // 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 + if options.Pack && options.Platform == "windows" { + outputLogger.Print("Generating bundle assets: ") + err := packageApplication(options) + if err != nil { + return "", err + } + outputLogger.Println("Done.") + + // When we finish, we will want to remove the syso file + defer func() { + err := os.Remove(filepath.Join(options.ProjectData.Path, options.ProjectData.Name+"-res.syso")) + if err != nil { + log.Fatal(err) + } + }() + } + // Compile the application outputLogger.Print("Compiling application: ") @@ -178,8 +198,8 @@ func Build(options *Options) (string, error) { } } - // Do we need to pack the app? - if options.Pack { + // Do we need to pack the app for non-windows? + if options.Pack && options.Platform != "windows" { outputLogger.Print("Packaging application: ") diff --git a/v2/pkg/commands/build/packager_windows.go b/v2/pkg/commands/build/packager_windows.go index 92521794..79fa2ffa 100644 --- a/v2/pkg/commands/build/packager_windows.go +++ b/v2/pkg/commands/build/packager_windows.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/leaanthony/winicon" "github.com/wailsapp/wails/v2/internal/fs" + "github.com/wailsapp/wails/v2/internal/shell" "github.com/wailsapp/wails/v2/pkg/buildassets" "os" "path/filepath" @@ -28,7 +29,12 @@ func packageApplication(options *Options) error { if err != nil { return err } - // Run + + // Create syso file + err = compileResources(options) + if err != nil { + return err + } return nil } @@ -76,3 +82,11 @@ func generateIcoFile(options *Options) error { } return nil } + +func compileResources(options *Options) error { + windowsBuildDir := filepath.Join(options.ProjectData.Path, "build", "windows") + sourcefile := filepath.Join(options.ProjectData.BuildDir, "windows", options.ProjectData.Name+".rc") + targetFile := filepath.Join(options.ProjectData.Path, options.ProjectData.Name+"-res.syso") + _, _, err := shell.RunCommand(windowsBuildDir, "windres", "-o", targetFile, sourcefile) + return err +}