Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pbf
nodejs/
build/

*.bits
*.sqlite
Expand Down
130 changes: 34 additions & 96 deletions xcompile.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash
set -euo pipefail

# note: works with golang 1.7 but not on 1.8!

# requires 'upx'
SKIP_COMPRESSION=true;
# ensure build directory exists
mkdir build

# ensure the compiler exits with status 0
function assert() {
Expand All @@ -14,113 +12,53 @@ function assert() {
fi
}

# ensure the files were compiled to the correct architecture
declare -A matrix
matrix["build/pbf.darwin-x64"]="Mach-O 64-bit "
matrix["build/pbf.linux-arm"]="ELF 32-bit "
matrix["build/pbf.linux-x64"]="ELF 64-bit "
matrix["build/pbf.win32-x64"]="PE32 executable "

function checkFiles() {
for path in "${!matrix[@]}"
do
expected="$path: ${matrix[$path]}";
actual=$(file $path);
actualArr=($actual);
start=$(printf "%s " "${actualArr[@]:0:3}");
if [ "${start}" != "$expected" ]; then
echo "invalid file architecture: $path"
echo "expected: $expected"
echo "actual: $actual"
echo "start: $start"
exit 1
fi
done
# check the reported file class matches what's expected
function check() {
actual=$(file -b ${1});
if [[ "${actual}" != "${2}"* ]]; then
echo "invalid file architecture: ${1}"
echo "expected: ${2}"
echo "actual: ${actual}"
echo "-${actual}-${2}-"
exit 1
fi
}

echo "[compile] linux x64";
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
assert $?;
chmod +x pbf;
mv pbf build/pbf.linux-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.linux-x64;
# if the 'UPX' bindary packer is available, use it
# https://upx.github.io/
function compress() {
[ -x "$(command -v upx)" ] && upx "${1}"
}

echo "[compile] linux arm";
GOOS=linux GOARCH=arm go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
echo $?;
env GOOS=linux GOARCH=arm go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf;
mv pbf build/pbf.linux-arm;
$SKIP_COMPRESSION || upx --brute build/pbf.linux-arm;
check 'build/pbf.linux-arm' 'ELF 32-bit LSB executable';
compress 'build/pbf.linux-arm';

# echo "[compile] linux i386";
# GOOS=linux GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.linux-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.linux-ia32;
echo "[compile] linux x64";
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf;
mv pbf build/pbf.linux-x64;
check 'build/pbf.linux-x64' 'ELF 64-bit LSB executable';
compress 'build/pbf.linux-x64';

echo "[compile] darwin x64";
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf;
mv pbf build/pbf.darwin-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.darwin-x64;

# echo "[compile] darwin i386";
# GOOS=darwin GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.darwin-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.darwin-ia32;
check 'build/pbf.darwin-x64' 'Mach-O 64-bit';
# UPX disabled due to https://github.com/upx/upx/issues/187
# compress 'build/pbf.darwin-x64';

echo "[compile] windows x64";
GOOS=windows GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -o pbf.exe pbf.go;
env GOOS=windows GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH} -o pbf.exe;
assert $?;
chmod +x pbf.exe;
mv pbf.exe build/pbf.win32-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.win32-x64;

# echo "[compile] windows i386";
# GOOS=windows GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf.exe;
# mv pbf.exe build/pbf.win32-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.win32-ia32;

# echo "[compile] freebsd arm";
# GOOS=freebsd GOARCH=arm go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-arm;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-arm;

# echo "[compile] freebsd x64";
# GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-x64;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-x64;

# echo "[compile] freebsd i386";
# GOOS=freebsd GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-ia32;

# echo "[compile] openbsd i386";
# GOOS=openbsd GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.openbsd-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.openbsd-ia32;

# echo "[compile] openbsd x64";
# GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.openbsd-x64;
# $SKIP_COMPRESSION || upx --brute build/pbf.openbsd-x64;

checkFiles
check 'build/pbf.win32-x64' 'PE32 executable';
compress 'build/pbf.win32-x64';