Skip to content

Commit f9c2de9

Browse files
committed
cmd/cue: document -ldflags for local release builds
https://cuelang.org/cl/1194044 did away with fallbackVersion, and we are moving back to a situation where local builds of cmd/cue contain v0.0.0 pseudo-versions derived from stamped VCS information. As such, local release builds should go back to using -ldflags=-X, which many downstreams such as Linux distros were still doing. I manually verified that building master with the flag works: $ go install ./cmd/cue $ cue version | sed 1q cue version v0.0.0-20240501095423-2b2cc23a5d70 $ go install -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=v0.12.345' ./cmd/cue $ cue version | sed 1q cue version v0.12.345 Signed-off-by: Daniel Martí <[email protected]> Change-Id: I91678ad763c584931147bc540f9446ef78622f3a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194118 Reviewed-by: Paul Jolly <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 6132343 commit f9c2de9

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,19 @@ Using [Homebrew](https://brew.sh), you can install using the CUE Homebrew tap:
109109

110110
#### Install from Source
111111

112-
You need Go 1.21 or later to build CUE from source; follow the instructions at https://go.dev/doc/install.
112+
You need [Go 1.21 or later](https://go.dev/doc/install) to build CUE from source.
113113

114114
To download and install the `cue` command line tool, run:
115115

116116
go install cuelang.org/go/cmd/cue@latest
117117

118+
You can also build the tool locally from source via `go install ./cmd/cue`.
119+
Note that local release builds [lack version information](https://go.dev/issue/50603),
120+
so they should inject the version string, such as:
121+
122+
git switch -d v0.9.0
123+
go install -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=v0.9.0' ./cmd/cue
124+
118125
### Learning CUE
119126

120127
The fastest way to learn the basics is to follow the

cmd/cue/cmd/version.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ func newVersionCmd(c *Command) *cobra.Command {
3838
return cmd
3939
}
4040

41-
// version can be set by a builder using
42-
// -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>'.
43-
// However, people should prefer building via a mechanism which
44-
// resolves cuelang.org/go as a dependency (and not the main
45-
// module), in which case the version information is determined
46-
// from the *debug.BuildInfo (see below). So this mechanism is
47-
// considered legacy.
41+
// version can be set at build time to inject cmd/cue's version string,
42+
// particularly necessary when building a release locally.
43+
// See the top-level README.md for more details.
4844
var version string
4945

5046
func runVersion(cmd *Command, args []string) error {

0 commit comments

Comments
 (0)