5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-19 02:19:31 +08:00

Add ldflags option to build

This commit is contained in:
Lea Anthony 2020-06-22 20:11:56 +10:00
parent aa93e5d8d2
commit 1062aeb136
3 changed files with 13 additions and 2 deletions

View File

@ -561,6 +561,11 @@ func ldFlags(po *ProjectOptions, buildMode string) string {
ldflags += "-X github.com/wailsapp/wails.BuildMode=" + buildMode 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 we wish to generate typescript
if po.typescriptDefsFilename != "" { if po.typescriptDefsFilename != "" {
cwd, err := os.Getwd() cwd, err := os.Getwd()

View File

@ -161,6 +161,7 @@ type ProjectOptions struct {
CrossCompile bool CrossCompile bool
Platform string Platform string
Architecture string Architecture string
LdFlags string
} }
// Defaults sets the default project template // Defaults sets the default project template

View File

@ -29,6 +29,7 @@ func init() {
var typescriptFilename = "" var typescriptFilename = ""
var verbose = false var verbose = false
var platform = "" var platform = ""
var ldflags = ""
buildSpinner := spinner.NewSpinner() buildSpinner := spinner.NewSpinner()
buildSpinner.SetSpinSpeed(50) buildSpinner.SetSpinSpeed(50)
@ -40,7 +41,8 @@ func init() {
BoolFlag("f", "Force rebuild of application components", &forceRebuild). BoolFlag("f", "Force rebuild of application components", &forceRebuild).
BoolFlag("d", "Build in Debug mode", &debugMode). BoolFlag("d", "Build in Debug mode", &debugMode).
BoolFlag("verbose", "Verbose output", &verbose). 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 var b strings.Builder
for _, plat := range getSupportedPlatforms() { for _, plat := range getSupportedPlatforms() {
@ -84,7 +86,7 @@ func init() {
} }
} }
if !supported { 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 projectOptions.CrossCompile = true
@ -93,6 +95,9 @@ func init() {
projectOptions.Architecture = plat[1] projectOptions.Architecture = plat[1]
} }
// Add ldflags
projectOptions.LdFlags = ldflags
// Validate config // Validate config
// Check if we have a frontend // Check if we have a frontend
err = cmd.ValidateFrontendConfig(projectOptions) err = cmd.ValidateFrontendConfig(projectOptions)