diff --git a/v2/cmd/wails/build.go b/v2/cmd/wails/build.go index 05f235078..39ad00d2f 100644 --- a/v2/cmd/wails/build.go +++ b/v2/cmd/wails/build.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/wailsapp/wails/v2/pkg/commands/buildtags" "os" "runtime" "strings" @@ -59,6 +60,13 @@ func buildApplication(f *flags.Build) error { f.GarbleArgs = projectOptions.GarbleArgs } + projectTags, err := buildtags.Parse(projectOptions.BuildTags) + if err != nil { + return err + } + userTags := f.GetTags() + compiledTags := append(projectTags, userTags...) + // Create BuildOptions buildOptions := &build.Options{ Logger: logger, @@ -76,7 +84,7 @@ func buildApplication(f *flags.Build) error { IgnoreFrontend: f.SkipFrontend, Compress: f.Upx, CompressFlags: f.UpxFlags, - UserTags: f.GetTags(), + UserTags: compiledTags, WebView2Strategy: f.GetWebView2Strategy(), TrimPath: f.TrimPath, RaceDetector: f.RaceDetector, @@ -106,7 +114,7 @@ func buildApplication(f *flags.Build) error { {"Package", bool2Str(!f.NoPackage)}, {"Clean Bin Dir", bool2Str(f.Clean)}, {"LDFlags", f.LdFlags}, - {"Tags", "[" + strings.Join(f.GetTags(), ",") + "]"}, + {"Tags", "[" + strings.Join(compiledTags, ",") + "]"}, {"Race Detector", bool2Str(f.RaceDetector)}, }...) if len(buildOptions.OutputFile) > 0 && f.GetTargets().Length() == 1 { diff --git a/v2/cmd/wails/internal/dev/dev.go b/v2/cmd/wails/internal/dev/dev.go index a406768ed..9495b5bf2 100644 --- a/v2/cmd/wails/internal/dev/dev.go +++ b/v2/cmd/wails/internal/dev/dev.go @@ -76,10 +76,15 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error { return err } - buildOptions.UserTags = userTags - projectConfig := f.ProjectConfig() + projectTags, err := buildtags.Parse(projectConfig.BuildTags) + if err != nil { + return err + } + compiledTags := append(projectTags, userTags...) + buildOptions.UserTags = compiledTags + // Setup signal handler quitChannel := make(chan os.Signal, 1) signal.Notify(quitChannel, os.Interrupt, syscall.SIGTERM) diff --git a/v2/internal/project/project.go b/v2/internal/project/project.go index 6aad383e8..2df99bdfa 100644 --- a/v2/internal/project/project.go +++ b/v2/internal/project/project.go @@ -42,6 +42,9 @@ type Project struct { // Build directory BuildDir string `json:"build:dir"` + // BuildTags Extra tags to process during build + BuildTags string `json:"build:tags"` + // The output filename OutputFilename string `json:"outputfilename"` diff --git a/website/docs/reference/project-config.mdx b/website/docs/reference/project-config.mdx index a937e0d51..a9f8785fa 100644 --- a/website/docs/reference/project-config.mdx +++ b/website/docs/reference/project-config.mdx @@ -18,6 +18,8 @@ The project config resides in the `wails.json` file in the project directory. Th "reloaddirs": "", // The directory where the build files reside. Defaults to 'build' "build:dir": "", + // Additional tags to include at build time regardless of environment + "build:tags": "", // Relative path to the frontend directory. Defaults to 'frontend' "frontend:dir": "", // The command to install node dependencies, run in the frontend directory - often `npm install` diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 2a7ab13d3..eab7e8bc6 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Configure Vite timeout by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/4374) - Added `ContentProtection` option to allow hiding the application window from screen sharing software [#4241](https://github.com/wailsapp/wails/pull/4241) by [@Taiterbase](https://github.com/Taiterbase) +- Added `build:tags` to project specification for automatically adding compilation tags by @symball in [PR](https://github.com/wailsapp/wails/pull/4439) ## v2.10.2 - 2025-07-06