2020-01-30 11:38:30 +01:00
|
|
|
#!/bin/sh
|
2021-01-25 17:45:26 +01:00
|
|
|
set -e
|
2020-08-22 11:20:50 +02:00
|
|
|
|
|
|
|
# We don't have a git repository when running in github actions
|
|
|
|
v=`git describe --tags || echo $GITHUB_SHA`
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
windows)
|
2021-01-25 17:45:26 +01:00
|
|
|
set -x
|
2021-01-20 13:09:37 +01:00
|
|
|
$0 windows_amd64
|
|
|
|
$0 windows_386
|
|
|
|
;;
|
|
|
|
|
|
|
|
windows_amd64)
|
2020-08-22 11:20:50 +02:00
|
|
|
# Note! This assumes we've installed the mingw-w64 compiler.
|
|
|
|
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc \
|
|
|
|
go build -ldflags='-s -w' ./cmd/ooniprobe
|
|
|
|
tar -cvzf ooniprobe_${v}_windows_amd64.tar.gz LICENSE.md Readme.md ooniprobe.exe
|
|
|
|
# We don't have zip inside the github actions runner
|
|
|
|
zip ooniprobe_${v}_windows_amd64.zip LICENSE.md Readme.md ooniprobe.exe || true
|
|
|
|
mv ooniprobe.exe ./CLI/windows/amd64/
|
|
|
|
;;
|
|
|
|
|
2021-01-20 13:09:37 +01:00
|
|
|
windows_386)
|
|
|
|
# Note! This assumes we've installed the mingw-w64 compiler.
|
|
|
|
GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc \
|
|
|
|
go build -ldflags='-s -w' ./cmd/ooniprobe
|
|
|
|
tar -cvzf ooniprobe_${v}_windows_386.tar.gz LICENSE.md Readme.md ooniprobe.exe
|
|
|
|
# We don't have zip inside the github actions runner
|
|
|
|
zip ooniprobe_${v}_windows_386.zip LICENSE.md Readme.md ooniprobe.exe || true
|
|
|
|
mv ooniprobe.exe ./CLI/windows/386/
|
|
|
|
;;
|
|
|
|
|
2020-08-22 11:20:50 +02:00
|
|
|
linux)
|
2021-01-25 17:45:26 +01:00
|
|
|
set -x
|
2021-01-20 13:09:37 +01:00
|
|
|
$0 linux_amd64
|
|
|
|
$0 linux_386
|
|
|
|
;;
|
|
|
|
|
|
|
|
linux_amd64)
|
|
|
|
docker pull --platform linux/amd64 golang:1.14-alpine
|
|
|
|
docker run --platform linux/amd64 -v`pwd`:/ooni -w/ooni golang:1.14-alpine ./build.sh _alpine
|
2020-08-22 11:20:50 +02:00
|
|
|
tar -cvzf ooniprobe_${v}_linux_amd64.tar.gz LICENSE.md Readme.md ooniprobe
|
|
|
|
mv ooniprobe ./CLI/linux/amd64/
|
|
|
|
;;
|
|
|
|
|
2021-01-20 13:09:37 +01:00
|
|
|
linux_386)
|
|
|
|
docker pull --platform linux/386 golang:1.14-alpine
|
|
|
|
docker run --platform linux/386 -v`pwd`:/ooni -w/ooni golang:1.14-alpine ./build.sh _alpine
|
|
|
|
tar -cvzf ooniprobe_${v}_linux_386.tar.gz LICENSE.md Readme.md ooniprobe
|
|
|
|
mv ooniprobe ./CLI/linux/386/
|
|
|
|
;;
|
|
|
|
|
2020-08-22 11:20:50 +02:00
|
|
|
_alpine)
|
2021-01-20 13:09:37 +01:00
|
|
|
apk update
|
|
|
|
apk upgrade
|
2020-08-22 11:20:50 +02:00
|
|
|
apk add --no-progress gcc git linux-headers musl-dev
|
|
|
|
go build -tags netgo -ldflags='-s -w -extldflags "-static"' ./cmd/ooniprobe
|
|
|
|
;;
|
|
|
|
|
2020-08-24 19:16:58 +02:00
|
|
|
macos|darwin)
|
2021-01-25 17:45:26 +01:00
|
|
|
set -x
|
2020-08-22 11:20:50 +02:00
|
|
|
# Note! The following line _assumes_ you have a working C compiler. If you
|
|
|
|
# have Xcode command line tools installed, you are fine.
|
|
|
|
go build -ldflags='-s -w' ./cmd/ooniprobe
|
2020-08-24 19:16:58 +02:00
|
|
|
tar -cvzf ooniprobe_${v}_darwin_amd64.tar.gz LICENSE.md Readme.md ooniprobe
|
|
|
|
mv ooniprobe ./CLI/darwin/amd64/
|
2020-08-22 11:20:50 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
release)
|
|
|
|
$0 linux
|
|
|
|
$0 windows
|
2020-08-24 19:16:58 +02:00
|
|
|
$0 darwin
|
2021-01-20 13:09:37 +01:00
|
|
|
shasum -a 256 ooniprobe_${v}_*_*.* > ooniprobe_checksums.txt
|
2020-08-22 11:20:50 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2020-10-14 11:42:10 +02:00
|
|
|
|
|
|
|
set +x
|
2020-08-24 19:16:58 +02:00
|
|
|
echo "Usage: $0 darwin|linux|macos|windows|release"
|
2020-08-22 11:20:50 +02:00
|
|
|
echo ""
|
|
|
|
echo "You need a C compiler and Go >= 1.14. The C compiler must be a"
|
|
|
|
echo "UNIX like compiler like GCC, Clang, Mingw-w64."
|
|
|
|
echo ""
|
2021-01-25 17:45:26 +01:00
|
|
|
echo "To build a static Linux binary, we use Docker and Alpine. We currently"
|
|
|
|
echo "build for linux/386 and linux/amd64."
|
2020-08-22 11:20:50 +02:00
|
|
|
echo ""
|
|
|
|
echo "You can cross compile for Windows from macOS or Linux. You can"
|
|
|
|
echo "compile for Linux as long as you have Docker. Cross compiling for"
|
|
|
|
echo "macOS has never been tested. We have a bunch of cross compiling"
|
|
|
|
echo "checks inside the .github/workflows/cross.yml file."
|
|
|
|
echo ""
|
2020-08-24 19:16:58 +02:00
|
|
|
echo "The macos rule is an alias for the darwin rule. The generated"
|
2021-01-25 17:45:26 +01:00
|
|
|
echo 'binary file is named ooniprobe_${version}_darwin_${arch}.tar.gz'
|
2020-08-24 19:16:58 +02:00
|
|
|
echo "because the platform name is darwin."
|
|
|
|
echo ""
|
2020-08-22 11:20:50 +02:00
|
|
|
;;
|
|
|
|
esac
|