diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index c0415facf..d7dc33f5d 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -83,6 +83,9 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { updateGoMod := false command.BoolFlag("u", "Updates go.mod to use the same Wails version as the CLI", &updateGoMod) + debug := false + command.BoolFlag("debug", "Retains debug data in the compiled application", &debug) + command.Action(func() error { quiet := verbosity == 0 @@ -164,13 +167,20 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { } } + mode := build.Production + modeString := "Production" + if debug { + mode = build.Debug + modeString = "Debug" + } + // Create BuildOptions buildOptions := &build.Options{ Logger: logger, OutputType: outputType, OutputFile: outputFilename, CleanBuildDirectory: cleanBuildDirectory, - Mode: build.Production, + Mode: mode, Pack: !noPackage, LDFlags: ldflags, Compiler: compilerCommand, @@ -206,6 +216,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { fmt.Fprintf(w, "Platform: \t%s\n", buildOptions.Platform) fmt.Fprintf(w, "Arch: \t%s\n", buildOptions.Arch) fmt.Fprintf(w, "Compiler: \t%s\n", compilerPath) + fmt.Fprintf(w, "Build Mode: \t%s\n", modeString) fmt.Fprintf(w, "Skip Frontend: \t%t\n", skipFrontend) fmt.Fprintf(w, "Compress: \t%t\n", buildOptions.Compress) fmt.Fprintf(w, "Package: \t%t\n", buildOptions.Pack) diff --git a/v2/pkg/commands/build/base.go b/v2/pkg/commands/build/base.go index 39ca7a3ee..42fbf7e2b 100644 --- a/v2/pkg/commands/build/base.go +++ b/v2/pkg/commands/build/base.go @@ -215,7 +215,7 @@ func (b *BaseBuilder) CompileProject(options *Options) error { commands := slicer.String([]string{"build"}) // Add better debugging flags - if options.Mode == Dev { + if options.Mode == Dev || options.Mode == Debug { commands.Add("-gcflags") commands.Add(`"all=-N -l"`) } @@ -233,7 +233,7 @@ func (b *BaseBuilder) CompileProject(options *Options) error { tags.Add(options.WebView2Strategy) } - if options.Mode == Production { + if options.Mode == Production || options.Mode == Debug { tags.Add("production") } diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index 37b862b9e..7ee348d28 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -23,6 +23,8 @@ const ( Dev Mode = iota // Production mode Production + // Debug build + Debug ) // Options contains all the build options as well as the project data diff --git a/website/docs/reference/cli.mdx b/website/docs/reference/cli.mdx index 4f6f07ae9..471bdf556 100644 --- a/website/docs/reference/cli.mdx +++ b/website/docs/reference/cli.mdx @@ -67,6 +67,7 @@ A list of community maintained templates can be found [here](/docs/community/tem | -v int | Verbosity level (0 - silent, 1 - default, 2 - verbose) | 1 | | -webview2 | WebView2 installer strategy: download,embed,browser,error | download | | -u | Updates your project's `go.mod` to use the same version of Wails as the CLI | | +| -debug | Retains debug information in the application | false | For a detailed description of the `webview2` flag, please refer to the [Windows](/docs/guides/windows) Guide.