|
@@ -1,124 +1,82 @@
|
|
|
# Packager's Manual
|
|
|
|
|
|
**Note**: The guidance here applies to the current development version and
|
|
|
-release versions starting from 0.16.0. The details for earlier versions are
|
|
|
+release versions starting from 0.19.0. The details for earlier versions are
|
|
|
different.
|
|
|
|
|
|
-Elvish is a normal Go application, and doesn't require any special attention.
|
|
|
-Build the main package of `cmd/elvish`, and you should get a fully working
|
|
|
-binary.
|
|
|
+The main package of Elvish is `cmd/elvish`, and you can build it like any other
|
|
|
+Go application. None of the instructions below are strictly required.
|
|
|
|
|
|
-If you don't care about accurate version information or reproducible builds, you
|
|
|
-can now stop reading. If you do, there is a small amount of extra work to get
|
|
|
-them.
|
|
|
+## Supplying VCS information for development builds
|
|
|
|
|
|
-## Accurate version information
|
|
|
+When Elvish is built from a development branch, it will try to figure out its
|
|
|
+version from the VCS information Go compiler encoded. When that works,
|
|
|
+`elvish -version` will output something like this:
|
|
|
|
|
|
-The `pkg/buildinfo` package contains a constant, `Version`, and a variable,
|
|
|
-`VersionSuffix`, which are concatenated to form the full version used in the
|
|
|
-output of `elvish -version` and `elvish -buildinfo`. Their values are set as
|
|
|
-follows:
|
|
|
+```
|
|
|
+0.19.0-dev.0.20220320172241-5dc8c02a32cf
|
|
|
+```
|
|
|
|
|
|
-- At release tags, `Version` contains the version of the release, which is
|
|
|
- identical to the tag name. `VersionSuffix` is empty.
|
|
|
+The version string follows the syntax of
|
|
|
+[Go module pseudo-version](https://go.dev/ref/mod#pseudo-versions), and consists
|
|
|
+of the following parts:
|
|
|
|
|
|
-- At development commits, `Version` contains the version of the next release.
|
|
|
- `VersionSuffix` is set to `-dev.unknown`.
|
|
|
+- `0.19.0-dev` identifies that this is a development build **before** the
|
|
|
+ 0.19.0 release.
|
|
|
|
|
|
-The `VersionSuffix` variable can be overridden at build time, by passing
|
|
|
-`-ldflags "-X src.elv.sh/pkg/buildinfo.VersionSuffix=-foobar"` to `go build`,
|
|
|
-`go install` or `go get`. This is necessary in several scenarios, which are
|
|
|
-documented below.
|
|
|
+- `.0` indicates that this is a pseudo-version, instead of a real version.
|
|
|
|
|
|
-### Packaging release versions
|
|
|
+- `20220320172241` identifies the commit's creation time, in UTC.
|
|
|
|
|
|
-If you are using the standard Go toolchain and not applying any patches, there
|
|
|
-is nothing more to do; the default empty `VersionSuffix` suffices.
|
|
|
+- `5dc8c02a32cf` is the 12-character prefix of the commit hash.
|
|
|
|
|
|
-If you are using a non-standard toolchain, or have applied any patches that can
|
|
|
-affect the resulting binary, you **must** override `VersionSuffix` with a string
|
|
|
-that starts with `+` and can uniquely identify your toolchain and patch. For
|
|
|
-official Linux distribution builds, this should identify your distribution, plus
|
|
|
-the version of the patch. Example:
|
|
|
+If that doesn't work for your build environment, the output of `elvish -version`
|
|
|
+will instead be:
|
|
|
|
|
|
```sh
|
|
|
-go build -ldflags "-X src.elv.sh/pkg/buildinfo.VersionSuffix=+deb1" ./cmd/elvish
|
|
|
+0.19.0-dev.unknown
|
|
|
```
|
|
|
|
|
|
-### Packaging development builds
|
|
|
-
|
|
|
-If you are packaging development builds, the default value of `VersionSuffix`,
|
|
|
-which is `-dev.unknown`, is likely not good enough, as it does not identify the
|
|
|
-commit Elvish is built from.
|
|
|
-
|
|
|
-You should override `VersionSuffix` with `-dev.$commit_hash`, where
|
|
|
-`$commit_hash` is the full commit hash, which can be obtained with
|
|
|
-`git rev-parse HEAD`. Example:
|
|
|
+If your build environment has the required information to build the
|
|
|
+pseudo-version string, you can supply it by overriding
|
|
|
+`src.elv.sh/pkg/buildinfo.VCSOverride` with the last two parts of the version
|
|
|
+string, commit's creation time and the 12-character prefix of the commit hash:
|
|
|
|
|
|
```sh
|
|
|
-go build -ldflags \
|
|
|
- "-X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.$(git rev-parse HEAD)" \
|
|
|
- ./cmd/elvish
|
|
|
+go build -ldflags '-X src.elv.sh/pkg/buildinfo.VCSOverride=20220320172241-5dc8c02a32cf' ./cmd/elvish
|
|
|
```
|
|
|
|
|
|
-If you have applied any patches that is not committed as a Git commit, you
|
|
|
-should also append a string that starts with `+` and can uniquely identify your
|
|
|
-patch.
|
|
|
-
|
|
|
-## Reproducible builds
|
|
|
-
|
|
|
-The idea of
|
|
|
-[reproducible build](https://en.wikipedia.org/wiki/Reproducible_builds) is that
|
|
|
-an Elvish binary from two different sources should be bit-to-bit identical, as
|
|
|
-long as they are built from the same version of the source code using the same
|
|
|
-version of the Go compiler.
|
|
|
-
|
|
|
-To make reproducible builds, you must do the following:
|
|
|
-
|
|
|
-- Pass `-trimpath` to the Go compiler.
|
|
|
-
|
|
|
-- For the following platforms, also pass `-buildmode=pie` to the Go compiler:
|
|
|
-
|
|
|
- - `GOOS=windows`, any `GOARCH`
|
|
|
+## Identifying the build variant
|
|
|
|
|
|
- - `GOOS=linux`, `GOARCH=amd64` or `GOARCH=arm64`
|
|
|
+You are encouraged to identify your build by overriding
|
|
|
+`src.elv.sh/pkg/buildinfo.BuildVariant` with something that identifies the
|
|
|
+distribution you are building for, and any patch level you have applied for
|
|
|
+Elvish. This will allow Elvish developers to easily identify any
|
|
|
+distribution-specific issue:
|
|
|
|
|
|
-- Disable cgo by setting the `CGO_ENABLED` environment variable to 0.
|
|
|
-
|
|
|
-- Follow the requirements above for putting
|
|
|
- [accurate version information](#accurate-version-information) into the
|
|
|
- binary, so that the user is able to uniquely identify the build by running
|
|
|
- `elvish -version`.
|
|
|
+```
|
|
|
+go build -ldflags '-X src.elv.sh/pkg/buildinfo.BuildVariant=deb1' ./cmd/elvish
|
|
|
+```
|
|
|
|
|
|
- The recommendation for how to set `VersionSuffix` when
|
|
|
- [packaging development builds](#packaging-development-builds) becomes hard
|
|
|
- requirements when packaging reproducible builds.
|
|
|
+## Official builds
|
|
|
|
|
|
- In addition, if your distribution uses a patched version of the Go compiler
|
|
|
- that changes its output, or if the build command uses any additional flags
|
|
|
- (either via the command line or via any environment variables), you must
|
|
|
- treat this as a patch on Elvish itself, and supply a version suffix
|
|
|
- accordingly.
|
|
|
+A special build variant is `official`. This variant has a special meaning: the
|
|
|
+binary must be bit-by-bit identical to the official binaries, linked from
|
|
|
+https://elv.sh/get.
|
|
|
|
|
|
-If you follow these requirements when building Elvish, you can mark the build as
|
|
|
-a reproducible one by overriding `src.elv.sh/pkg/buildinfo.Reproducible` to
|
|
|
-`"true"`.
|
|
|
+The official binaries are built using the `tools/buildall.sh` script in the Git
|
|
|
+repo, using the docker image defined in https://github.com/elves/up. If you can
|
|
|
+fully mirror the environment **and** verify that the resulting binary is
|
|
|
+bit-by-bit identical to the official one, you can identify your build as
|
|
|
+`official`.
|
|
|
|
|
|
-Example when building a release version without any patches, on a platform where
|
|
|
-PIE is applicable:
|
|
|
+Reproducing the official binaries is completely optional. If your build setup is
|
|
|
+technically reproducible, but not identical with the official binaries, you can
|
|
|
+always use a distribution-specific variant, such as `deb1-reproducible`.
|
|
|
|
|
|
-```sh
|
|
|
-go build -buildmode=pie -trimpath \
|
|
|
- -ldflags "-X src.elv.sh/pkg/buildinfo.Reproducible=true" \
|
|
|
- ./cmd/elvish
|
|
|
-```
|
|
|
-
|
|
|
-Example when building a development version with a patch, on a platform where
|
|
|
-PIE is application:
|
|
|
-
|
|
|
-```sh
|
|
|
-go build -buildmode=pie -trimpath \
|
|
|
- -ldflags "-X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.$(git rev-parse HEAD)+deb0 \
|
|
|
- -X src.elv.sh/pkg/buildinfo.Reproducible=true" \
|
|
|
- ./cmd/elvish
|
|
|
-```
|
|
|
+If you do want to reproduce the official binaries, realize that this is not a
|
|
|
+one-off configuration, but an ongoing commitment, since the environment for
|
|
|
+building the official binary will change over time (at a minimal, the Go version
|
|
|
+will be bumped from time to time). You must watch changes to them, update your
|
|
|
+build setup accordingly, and always verify that your build remains identical to
|
|
|
+official binaries.
|