Skip to content

Commit 87f4a99

Browse files
committed
Support setting version string via ldflags
When xcaddy is built directly from source (e.g. distro packaging), Go's debug.ReadBuildInfo() reports the main module version as "(devel)" rather than the actual release version. The upstream build process works around this by building from a separate wrapper module that imports xcaddy as a versioned dependency, but packagers typically build directly from the source tarball. Add a version variable that can be set via -ldflags -X at build time, allowing packagers to inject the correct version string.
1 parent 14e0e39 commit 87f4a99

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmd/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import (
3333
"github.com/caddyserver/xcaddy/internal/utils"
3434
)
3535

36+
// version can be set at build time via -ldflags to override the version
37+
// reported by debug.ReadBuildInfo() (which returns "(devel)" when built
38+
// as the main module, e.g. in distro packaging).
39+
var version string
40+
3641
var (
3742
caddyVersion = os.Getenv("CADDY_VERSION")
3843
raceDetector = os.Getenv("XCADDY_RACE_DETECTOR") == "1"
@@ -207,6 +212,9 @@ func splitWith(arg string) (module, version, replace string, err error) {
207212

208213
// xcaddyVersion returns a detailed version string, if available.
209214
func xcaddyVersion() string {
215+
if version != "" {
216+
return version
217+
}
210218
mod := goModule()
211219
ver := mod.Version
212220
if mod.Sum != "" {

0 commit comments

Comments
 (0)