2024-02-22 21:40:05 +08:00
|
|
|
#!/usr/bin/env elvish
|
|
|
|
|
|
|
|
# This script is supposed to be run with Elvish at the same commit. Either
|
|
|
|
# ensure that Elvish is built and installed from the repo, or use "go run
|
|
|
|
# ./cmd/elvish tools/buildall.elv ...".
|
|
|
|
|
|
|
|
use flag
|
|
|
|
use os
|
|
|
|
use platform
|
|
|
|
use str
|
|
|
|
|
|
|
|
var platforms = [
|
2024-02-23 01:34:19 +08:00
|
|
|
[&arch=amd64 &os=linux]
|
2024-02-22 21:40:05 +08:00
|
|
|
[&arch=amd64 &os=darwin]
|
|
|
|
[&arch=amd64 &os=freebsd]
|
|
|
|
[&arch=amd64 &os=openbsd]
|
|
|
|
[&arch=amd64 &os=netbsd]
|
2024-02-23 01:34:19 +08:00
|
|
|
[&arch=amd64 &os=windows]
|
2024-02-22 21:40:05 +08:00
|
|
|
|
|
|
|
[&arch=386 &os=linux]
|
2024-02-23 01:34:19 +08:00
|
|
|
[&arch=386 &os=windows]
|
2024-02-22 21:40:05 +08:00
|
|
|
|
2024-02-23 01:34:19 +08:00
|
|
|
[&arch=arm64 &os=linux]
|
2024-02-22 21:40:05 +08:00
|
|
|
[&arch=arm64 &os=darwin]
|
2024-06-11 23:13:19 +08:00
|
|
|
|
|
|
|
[&arch=riscv64 &os=linux]
|
2024-02-22 21:40:05 +08:00
|
|
|
]
|
|
|
|
|
2024-06-11 23:19:33 +08:00
|
|
|
fn sha256sum-if-available {|name|
|
|
|
|
if (has-external sha256sum) {
|
|
|
|
sha256sum $name > $name.sha256sum
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 21:40:05 +08:00
|
|
|
var usage = ^
|
2024-06-11 23:19:33 +08:00
|
|
|
'buildall.elv [-name name] [-variant variant] [-keep-bin] go-pkg dst-dir
|
2024-02-22 21:40:05 +08:00
|
|
|
|
2024-06-11 23:19:33 +08:00
|
|
|
Builds $go-pkg, writing a binary $dst-dir/$GOOS-$GOARCH/$name and an archive for
|
|
|
|
a predefined list of supported GOOS/GOARCH combinations. The binary is removed
|
|
|
|
after the archive is created, unless -keep-bin is specified.
|
2024-02-22 21:40:05 +08:00
|
|
|
|
|
|
|
For GOOS=windows, the binary name has an .exe suffix, and the archive is a
|
|
|
|
.zip file. For all other GOOS, the archive is a .tar.gz file.
|
|
|
|
|
|
|
|
If the sha256sum command is available, this script also creates a sha256sum
|
|
|
|
file for each binary and archive file, and puts it in the same directory.
|
|
|
|
|
|
|
|
The value of $variant will be used to override
|
|
|
|
src.elv.sh/pkg/buildinfo.BuildVariant.
|
|
|
|
'
|
|
|
|
|
2024-06-11 23:19:33 +08:00
|
|
|
fn main {|go-pkg dst-dir &name=elvish &variant='' &keep-bin=$false|
|
2024-02-22 21:40:05 +08:00
|
|
|
tmp E:CGO_ENABLED = 0
|
|
|
|
for platform $platforms {
|
|
|
|
var arch os = $platform[arch] $platform[os]
|
|
|
|
|
|
|
|
var bin-dir = $dst-dir/$os'-'$arch
|
|
|
|
os:mkdir-all $bin-dir
|
|
|
|
|
2024-02-26 23:46:54 +08:00
|
|
|
var bin-name-in-archive bin-name archive-name = (
|
2024-02-22 21:40:05 +08:00
|
|
|
if (eq $os windows) {
|
2024-02-26 23:46:54 +08:00
|
|
|
put elvish.exe $name{.exe .zip}
|
2024-02-22 21:40:05 +08:00
|
|
|
} else {
|
2024-02-26 23:46:54 +08:00
|
|
|
put elvish $name{'' .tar.gz}
|
2024-02-22 21:40:05 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
print 'Building for '$os'-'$arch'... '
|
|
|
|
|
|
|
|
tmp E:GOOS E:GOARCH = $os $arch
|
|
|
|
|
|
|
|
try {
|
|
|
|
go build ^
|
|
|
|
-trimpath ^
|
|
|
|
-ldflags '-X src.elv.sh/pkg/buildinfo.BuildVariant='$variant ^
|
2024-02-26 23:46:54 +08:00
|
|
|
-o $bin-dir/$bin-name-in-archive ^
|
2024-02-22 21:40:05 +08:00
|
|
|
$go-pkg
|
|
|
|
} catch e {
|
|
|
|
echo 'Failed'
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
# This is needed to get files appear in the root of the archive files.
|
|
|
|
tmp pwd = $bin-dir
|
|
|
|
# Archive files store the modification timestamp of files. Change it to a
|
|
|
|
# fixed point in time to make the archive files reproducible.
|
2024-02-26 23:46:54 +08:00
|
|
|
touch -d 2000-01-01T00:00:00Z $bin-name-in-archive
|
2024-02-22 21:40:05 +08:00
|
|
|
if (eq $os windows) {
|
2024-02-26 23:46:54 +08:00
|
|
|
zip -q $archive-name $bin-name-in-archive
|
2024-02-22 21:40:05 +08:00
|
|
|
} else {
|
|
|
|
# If we create a .tar.gz file directly with the tar command, the
|
|
|
|
# resulting archive will contain the timestamp of the .tar file,
|
|
|
|
# rendering the result unreproducible. As a result, we need to do it in
|
|
|
|
# two steps.
|
2024-02-26 23:46:54 +08:00
|
|
|
tar cf $bin-name.tar $bin-name-in-archive
|
2024-02-22 21:40:05 +08:00
|
|
|
touch -d 2022-01-01T00:00:00Z $bin-name.tar
|
|
|
|
gzip -f $bin-name.tar
|
|
|
|
}
|
2024-06-11 23:19:33 +08:00
|
|
|
sha256sum-if-available $archive-name
|
2024-06-11 23:32:18 +08:00
|
|
|
mv $bin-name-in-archive $bin-name
|
|
|
|
# Update the modification time again to reflect the actual modification
|
|
|
|
# time. (Technically this makes the file appear slightly newer han it really
|
|
|
|
# is, but it's close enough).
|
|
|
|
touch $bin-name
|
|
|
|
sha256sum-if-available $bin-name
|
|
|
|
if (not $keep-bin) {
|
|
|
|
rm $bin-name
|
2024-02-22 21:40:05 +08:00
|
|
|
}
|
2024-06-11 23:19:33 +08:00
|
|
|
echo 'Done'
|
2024-02-22 21:40:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flag:call $main~ $args &on-parse-error={|_| print $usage; exit 1}
|