mirror of
https://github.com/dnote/dnote
synced 2026-03-14 14:35: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
|
|
@ -32,8 +32,13 @@ You can build either a development version or a production version:
|
|||
# Build a development version for your platform and place it in your `PATH`.
|
||||
make debug=true build-cli
|
||||
|
||||
# Build a production version
|
||||
# Build a production version for all platforms
|
||||
make version=v0.1.0 build-cli
|
||||
|
||||
# Build a production version for a specific platform
|
||||
# Note: You cannot cross-compile using this method because Dnote uses CGO
|
||||
# and requires the OS specific headers.
|
||||
GOOS=[insert OS] GOARCH=[insert arch] make version=v0.1.0 build-cli
|
||||
```
|
||||
|
||||
### Test
|
||||
|
|
|
|||
8
Makefile
8
Makefile
|
|
@ -79,7 +79,7 @@ build-web:
|
|||
|
||||
build-server: build-web
|
||||
ifndef version
|
||||
$(error version is required. Usage: make version=v0.1.0 build-server)
|
||||
$(error version is required. Usage: make version=0.1.0 build-server)
|
||||
endif
|
||||
|
||||
@echo "==> building server"
|
||||
|
|
@ -93,7 +93,7 @@ ifeq ($(debug), true)
|
|||
else
|
||||
|
||||
ifndef version
|
||||
$(error version is required. Usage: make version=v0.1.0 build-cli)
|
||||
$(error version is required. Usage: make version=0.1.0 build-cli)
|
||||
endif
|
||||
|
||||
@echo "==> building cli"
|
||||
|
|
@ -104,7 +104,7 @@ endif
|
|||
## release
|
||||
release-cli: build-cli
|
||||
ifndef version
|
||||
$(error version is required. Usage: make version=v0.1.0 release-cli)
|
||||
$(error version is required. Usage: make version=0.1.0 release-cli)
|
||||
endif
|
||||
ifndef HUB
|
||||
$(error please install hub)
|
||||
|
|
@ -128,7 +128,7 @@ endif
|
|||
|
||||
release-server: build-server
|
||||
ifndef version
|
||||
$(error version is required. Usage: make version=v0.1.0 release-server)
|
||||
$(error version is required. Usage: make version=0.1.0 release-server)
|
||||
endif
|
||||
ifndef HUB
|
||||
$(error please install hub)
|
||||
|
|
|
|||
|
|
@ -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