[windows] Generate syso file for windows builds

This commit is contained in:
Lea Anthony
2021-05-17 19:51:43 +10:00
parent 7591b45ffa
commit 8be2a39daf
2 changed files with 37 additions and 3 deletions

View File

@@ -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: ")

View File

@@ -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
}