Skip to content

Commit

Permalink
update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Sep 1, 2019
1 parent de782da commit 467552a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 58 deletions.
60 changes: 2 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,5 @@ test:
go test --cover -covermode=count -coverprofile=coverage.out ./...

build:
make linux
make macOS
make windows
cp ./.env ./bin/.env
echo "Build Success!"

linux:
make user_linux
make admin_linux
make message_queue_linux

macOS:
make user_mac
make admin_mac
make message_queue_mac

windows:
make user_win
make admin_win
make message_queue_win

# 细分任务

user_win:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o ./bin/user_win_x86.exe ./cmd/user/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./bin/user_win_x64.exe ./cmd/user/main.go

user_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./bin/user_linux_x86 ./cmd/user/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/user_linux_x64 ./cmd/user/main.go

user_mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o ./bin/user_osx_x86 ./cmd/user/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/user_osx_64 ./cmd/user/main.go

admin_win:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o ./bin/admin_win_x86.exe ./cmd/admin/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./bin/admin_win_x64.exe ./cmd/admin/main.go

admin_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./bin/admin_linux_x86 ./cmd/admin/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/admin_linux_x64 ./cmd/admin/main.go

admin_mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o ./bin/admin_osx_x86 ./cmd/admin/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/admin_osx_64 ./cmd/admin/main.go

message_queue_win:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o ./bin/message_queue_win_x86.exe ./cmd/message_queue/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./bin/message_queue_win_x64.exe ./cmd/message_queue/main.go

message_queue_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./bin/message_queue_linux_x86 ./cmd/message_queue/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/message_queue_linux_x64 ./cmd/message_queue/main.go

message_queue_mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o ./bin/message_queue_osx_x86 ./cmd/message_queue/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/message_queue_osx_64 ./cmd/message_queue/main.go
bash ./scripts/build.sh
echo "Build Success!"
85 changes: 85 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Reference:
# https://github.com/golang/go/blob/master/src/go/build/syslist.go
os_archs=(
darwin/386
darwin/amd64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/ppc64
linux/ppc64le
linux/mips
linux/mipsle
linux/mips64
linux/mips64le
linux/s390x
nacl/386
nacl/amd64p32
nacl/arm
netbsd/386
netbsd/amd64
netbsd/arm
openbsd/386
openbsd/amd64
openbsd/arm
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64
)

releases=()
targets=(
user
admin
message_queue
)

for target in "${targets[@]}"
do
for os_arch in "${os_archs[@]}"
do
goos=${os_arch%/*}
goarch=${os_arch#*/}

filename=${target}_server

if [[ ${goos} == "windows" ]];then
filename+=.exe
fi

echo building ${target} ${os_arch}

CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build -ldflags "-s -w" -o ./bin/${filename} ./cmd/${target}/main.go >/dev/null 2>&1

# if build success
if [[ $? == 0 ]];then
releases+=(${os_arch})
cd ./bin

tar -czf ${target}_server_${goos}_${goarch}.tar.gz ${filename}

rm -rf ./${filename}

cd ../
fi
done

echo "${target} release:"

for os_arch in "${releases[@]}"
do
printf "\t%s\n" "${os_arch}"
done
echo
done

0 comments on commit 467552a

Please sign in to comment.