From 1062aeb13628d18f8a754749993d2da06cb3600e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 22 Jun 2020 20:11:56 +1000 Subject: [PATCH] Add `ldflags` option to build --- cmd/helpers.go | 5 +++++ cmd/project.go | 1 + cmd/wails/4_build.go | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/helpers.go b/cmd/helpers.go index 1a8d56144..7bbf97758 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -561,6 +561,11 @@ func ldFlags(po *ProjectOptions, buildMode string) string { ldflags += "-X github.com/wailsapp/wails.BuildMode=" + buildMode + // Add additional ldflags passed in via the `ldflags` cli flag + if len(po.LdFlags) > 0 { + ldflags += " " + po.LdFlags + } + // If we wish to generate typescript if po.typescriptDefsFilename != "" { cwd, err := os.Getwd() diff --git a/cmd/project.go b/cmd/project.go index 47b472ddb..889fb63d0 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -161,6 +161,7 @@ type ProjectOptions struct { CrossCompile bool Platform string Architecture string + LdFlags string } // Defaults sets the default project template diff --git a/cmd/wails/4_build.go b/cmd/wails/4_build.go index 5abdb8f55..453d858da 100644 --- a/cmd/wails/4_build.go +++ b/cmd/wails/4_build.go @@ -29,6 +29,7 @@ func init() { var typescriptFilename = "" var verbose = false var platform = "" + var ldflags = "" buildSpinner := spinner.NewSpinner() buildSpinner.SetSpinSpeed(50) @@ -40,7 +41,8 @@ func init() { BoolFlag("f", "Force rebuild of application components", &forceRebuild). BoolFlag("d", "Build in Debug mode", &debugMode). BoolFlag("verbose", "Verbose output", &verbose). - StringFlag("t", "Generate Typescript definitions to given file (at runtime)", &typescriptFilename) + StringFlag("t", "Generate Typescript definitions to given file (at runtime)", &typescriptFilename). + StringFlag("ldflags", "Extra options for -ldflags", &ldflags) var b strings.Builder for _, plat := range getSupportedPlatforms() { @@ -84,7 +86,7 @@ func init() { } } if !supported { - return fmt.Errorf("Unsupported platform '%s' specified.\nPlease run `wails build -h` to see the supported platform/architecture options.", platform) + return fmt.Errorf("unsupported platform '%s' specified.\nPlease run `wails build -h` to see the supported platform/architecture options", platform) } projectOptions.CrossCompile = true @@ -93,6 +95,9 @@ func init() { projectOptions.Architecture = plat[1] } + // Add ldflags + projectOptions.LdFlags = ldflags + // Validate config // Check if we have a frontend err = cmd.ValidateFrontendConfig(projectOptions)