Skip to content

Commit

Permalink
cmd/cue: document -ldflags for local release builds
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: I91678ad763c584931147bc540f9446ef78622f3a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194118
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mvdan committed May 1, 2024
1 parent 6132343 commit f9c2de9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,19 @@ Using [Homebrew](https://brew.sh), you can install using the CUE Homebrew tap:

#### Install from Source

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

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

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

You can also build the tool locally from source via `go install ./cmd/cue`.
Note that local release builds [lack version information](https://go.dev/issue/50603),
so they should inject the version string, such as:

git switch -d v0.9.0
go install -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=v0.9.0' ./cmd/cue

### Learning CUE

The fastest way to learn the basics is to follow the
Expand Down
10 changes: 3 additions & 7 deletions cmd/cue/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ func newVersionCmd(c *Command) *cobra.Command {
return cmd
}

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

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

0 comments on commit f9c2de9

Please sign in to comment.