mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
Allow to build for a specific platform (#250)
This commit is contained in:
parent
bda05f71f6
commit
df4866b4d4
3 changed files with 50 additions and 19 deletions
|
|
@ -2,9 +2,16 @@
|
|||
#
|
||||
# build.sh compiles dnote binary for target platforms. It is resonsible for creating
|
||||
# distributable files that can be released by a human or a script.
|
||||
# use: ./scripts/build.sh 0.4.8
|
||||
#
|
||||
# It can either cross-compile for different platforms using xgo, simply target a specific
|
||||
# platform. Set GOOS and GOARCH environment variables to disable xgo and instead
|
||||
# compile for a specific platform.
|
||||
#
|
||||
# use:
|
||||
# ./scripts/build.sh 0.4.8
|
||||
# GOOS=linux GOARCH=amd64 ./scripts/build.sh 0.4.8
|
||||
|
||||
set -eux
|
||||
set -ex
|
||||
|
||||
version=$1
|
||||
projectDir="$GOPATH/src/github.com/dnote/dnote"
|
||||
|
|
@ -43,18 +50,33 @@ get_binary_name() {
|
|||
build() {
|
||||
platform=$1
|
||||
arch=$2
|
||||
# native indicates if the compilation is to take place natively on the host platform
|
||||
# if not true, use xgo with Docker to cross-compile
|
||||
native=$3
|
||||
|
||||
# build binary
|
||||
destDir="$outputDir/$platform-$arch"
|
||||
ldflags="-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version"
|
||||
tags="fts5"
|
||||
|
||||
mkdir -p "$destDir"
|
||||
xgo \
|
||||
-go "$goVersion" \
|
||||
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" \
|
||||
--targets="$platform/$arch" \
|
||||
--tags "fts5" \
|
||||
--dest="$destDir" \
|
||||
"$basedir"
|
||||
|
||||
if [ "$native" == true ]; then
|
||||
GOOS="$platform" GOARCH="$arch" \
|
||||
go build \
|
||||
-ldflags "$ldflags" \
|
||||
--tags "$tags" \
|
||||
-o="$destDir/cli-$platform-$arch" \
|
||||
"$basedir"
|
||||
else
|
||||
xgo \
|
||||
-go "$goVersion" \
|
||||
--targets="$platform/$arch" \
|
||||
-ldflags "$ldflags" \
|
||||
--tags "$tags" \
|
||||
--dest="$destDir" \
|
||||
"$basedir"
|
||||
fi
|
||||
|
||||
binaryName=$(get_binary_name "$platform")
|
||||
mv "$destDir/cli-${platform}-"* "$destDir/$binaryName"
|
||||
|
|
@ -74,9 +96,13 @@ build() {
|
|||
popd
|
||||
}
|
||||
|
||||
# fetch tool
|
||||
go get -u github.com/karalabe/xgo
|
||||
if [ -z "$GOOS" ] && [ -z "$GOARCH" ]; then
|
||||
# fetch tool
|
||||
go get -u github.com/karalabe/xgo
|
||||
|
||||
build linux amd64
|
||||
build darwin amd64
|
||||
build windows amd64
|
||||
build linux amd64
|
||||
build darwin amd64
|
||||
build windows amd64
|
||||
else
|
||||
build "$GOOS" "$GOARCH" true
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue