From 95fa8756e4c6e8e7cf7d520c598592d10e6b3fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Mon, 30 Apr 2018 20:59:54 +0200 Subject: [PATCH] Create build scripts - Builds binaries for Windows, macOS and Linux - Shrinks the binaries with additional linker flags + Do the same in the CI configuration files --- .appveyor.yml | 1 + .travis.yml | 1 + README.md | 20 ++++++++++++++++++++ build.ps1 | 13 +++++++++++++ build.sh | 14 ++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 build.ps1 create mode 100755 build.sh diff --git a/.appveyor.yml b/.appveyor.yml index e0e3504..f618254 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,3 +14,4 @@ install: build_script: - go build + - .\build.ps1 diff --git a/.travis.yml b/.travis.yml index 42e3613..7490156 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,4 @@ go: script: - go build + - ./build.sh diff --git a/README.md b/README.md index 44be2f5..0addaa4 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,19 @@ With Go installed: `go get github.com/philippgille/serve` +Without Go installed: + +1. Download the correct binary for your OS from [GitHub Releases](https://github.com/philippgille/serve/releases) +2. Rename the file to "serve" (on Linux/macOS) or "serve.exe" (on Windows) +2. Make it available as shell command with one of the following options: + - Put the binary into a directory that's on your `PATH` + - For example `$HOME/bin` or `/usr/local/bin` on Linux + - Add the directory where you put the binary to the `PATH` + - Create an alias for the binary in your shell's profile (no need to rename the binary in this case) + > Note: Most Windows folks don't know this, but PowerShell has a profile, too: + > Just examine the environment variable `$profile` to see the file's path. + > Example: `C:\Users\John\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` + Use --- @@ -61,7 +74,14 @@ To build `serve` by yourself: 2. `cd` into the root directory of this repository 3. Execute: `go build` +> Note: The binaries in GitHub Releases are shrinked with additional Go linker flags + To also make `serve` available as command in other directories: 1. Add `$GOPATH/bin` to your `PATH` if you haven't done that already when installing Go 2. Execute: `go install` + +There are also build scripts for Windows and Linux for creating release artifacts (shrinked binaries for Windows, macOS and Linux): + +- Windows: `.\build.ps1` +- Linux: `./build.sh` diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..4576ad2 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,13 @@ +$ErrorActionPreference = "Stop" + +# Clean up the previous build +If (Test-Path "${PSScriptRoot}\artifacts") {Remove-Item -Recurse -Force "${PSScriptRoot}\artifacts"} + +# Build for Windows, macOS and Linux +# Use linker flags for shrinking +set GOOS=linux +go build -o "${PSScriptRoot}\artifacts\serve_Windows_x64.exe" -ldflags="-s -w" "github.com/philippgille/serve" +set GOOS=linux +go build -o "${PSScriptRoot}\artifacts\serve_macOS_x64" -ldflags="-s -w" "github.com/philippgille/serve" +set GOOS=linux +go build -o ${PSScriptRoot}\"artifacts\serve_Linux_x64" -ldflags="-s -w" "github.com/philippgille/serve" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2acec05 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -euxo pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Clean up the previous build +rm -rf $SCRIPTDIR/artifacts + +# Build for Windows, macOS and Linux +# Use linker flags for shrinking +GOOS=windows go build -o "$SCRIPTDIR/artifacts/serve_Windows_x64.exe" -ldflags="-s -w" "github.com/philippgille/serve" +GOOS=darwin go build -o "$SCRIPTDIR/artifacts/serve_macOS_x64" -ldflags="-s -w" "github.com/philippgille/serve" +GOOS=linux go build -o "$SCRIPTDIR/artifacts/serve_Linux_x64" -ldflags="-s -w" "github.com/philippgille/serve"