Skip to content

Commit 9ac7879

Browse files
committed
chore: add build scripts
1 parent ca4cfa8 commit 9ac7879

8 files changed

+113
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.*/
2+
/output

build/build-all-by-docker.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
cd $(dirname "$0")
4+
5+
# init variable `builds`
6+
source ./build-all.inc.sh
7+
8+
prefix=$(realpath ../)
9+
ehfs=/go/src/mjpclab.dev/ehfs
10+
11+
rm -rf "$prefix/output/"
12+
13+
buildByDocker() {
14+
gover="$1"
15+
shift
16+
docker pull golang:"$gover"
17+
18+
docker run \
19+
--rm \
20+
-v "$prefix":"$ehfs" \
21+
-e EX_UID="$(id -u)" \
22+
-e EX_GID="$(id -g)" \
23+
golang:"$gover" \
24+
/bin/bash -c '
25+
sed -i -e "s;://[^/ ]*;://mirrors.aliyun.com;" /etc/apt/sources.list;
26+
apt-get update;
27+
apt-get install -yq git zip;
28+
/bin/bash '"$ehfs"'/build/build.sh "$@";
29+
chown -R $EX_UID:$EX_GID '"$ehfs"'/output;
30+
' \
31+
'argv_0_placeholder' \
32+
"$@"
33+
}
34+
35+
gover=latest
36+
buildByDocker "$gover" "${builds[@]}"
37+
38+
#gover=1.16
39+
#builds=('darwin amd64 -10.12-sierra')
40+
#buildByDocker "$gover" "${builds[@]}"

build/build-all.inc.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
builds=('linux 386' 'linux amd64' 'linux amd64,v2' 'linux amd64,v3' 'linux arm' 'linux arm64' 'linux riscv64' 'linux loong64')
2+
builds=("${builds[@]}" 'windows 386' 'windows amd64' 'windows amd64,v2' 'windows amd64,v3' 'windows arm' 'windows arm64')
3+
builds=("${builds[@]}" 'darwin amd64' 'darwin arm64')
4+
builds=("${builds[@]}" 'freebsd 386' 'freebsd amd64' 'freebsd arm' 'freebsd arm64')
5+
builds=("${builds[@]}" 'openbsd 386' 'openbsd amd64' 'openbsd arm' 'openbsd arm64')
6+
builds=("${builds[@]}" 'netbsd 386' 'netbsd amd64' 'netbsd arm' 'netbsd arm64')
7+
builds=("${builds[@]}" 'dragonfly amd64')
8+
builds=("${builds[@]}" 'plan9 386' 'plan9 amd64' 'plan9 arm')

build/build-all.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
cd $(dirname "$0")
4+
rm -rf ../output/
5+
6+
# init variable `builds`
7+
source ./build-all.inc.sh
8+
9+
bash ./build.sh "${builds[@]}"

build/build-current.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
cd $(dirname "$0")
4+
rm -rf ../output/
5+
6+
GOARCH=$(go env GOARCH)
7+
ARCH_OPT_NAME=$(echo "GO$GOARCH" | tr 'a-z' 'A-Z')
8+
if [ -n "${!ARCH_OPT_NAME}" ]; then
9+
ARCH_OPT=",${!ARCH_OPT_NAME}"
10+
fi
11+
12+
bash ./build.sh "$(go env GOOS) ${GOARCH}${ARCH_OPT}"

build/build.inc.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
TMP='/tmp'
2+
OUTDIR='../output'
3+
MAINNAME='ehfs'
4+
MOD=$(go list ../src/)
5+
BASEMOD=mjpclab.dev/ghfs/src
6+
source ./build.inc.version.sh
7+
LICENSE='../LICENSE'
8+
getLdFlags() {
9+
echo "-s -w -X $BASEMOD/version.appVer=$VERSION -X $BASEMOD/version.appArch=${ARCH:-$(go env GOARCH)}"
10+
}

build/build.inc.version.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VERSION=$(git describe --abbrev=0 --tags 2> /dev/null || git rev-parse --abbrev-ref HEAD 2> /dev/null)
2+
VERSION=${VERSION#v}

build/build.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
cd $(dirname "$0")
4+
5+
source ./build.inc.sh
6+
export GOPROXY=https://goproxy.cn,direct
7+
mkdir -p "$OUTDIR"
8+
9+
for build in "$@"; do
10+
arg=($build)
11+
export GOOS="${arg[0]}"
12+
ARCH="${arg[1]}" # e.g. "amd64" or "amd64,v2"
13+
export GOARCH=${ARCH%,*}
14+
if [ "$ARCH" != "$GOARCH" ]; then
15+
# e.g. "GOAMD64=v2"
16+
ARCH_OPT="${ARCH#*,}"
17+
declare -x $(echo GO$GOARCH | tr 'a-z' 'A-Z')="$ARCH_OPT"
18+
else
19+
ARCH_OPT=''
20+
unset $(echo "GO$GOARCH" | tr 'a-z' 'A-Z')
21+
fi
22+
OS_SUFFIX="${arg[2]}"
23+
24+
BIN="$TMP/$MAINNAME$(go env GOEXE)"
25+
rm -f "$BIN"
26+
echo "Building: $GOOS$OS_SUFFIX $ARCH"
27+
go build -ldflags "$(getLdFlags)" -o "$BIN" ../src/main.go
28+
29+
OUT="$OUTDIR/$MAINNAME-$VERSION-$GOOS$OS_SUFFIX-$GOARCH$ARCH_OPT".zip
30+
zip -j "$OUT" "$BIN" "$LICENSE"
31+
done

0 commit comments

Comments
 (0)