Skip to content

Commit

Permalink
Create build scripts
Browse files Browse the repository at this point in the history
- Builds binaries for Windows, macOS and Linux
- Shrinks the binaries with additional linker flags

+ Do the same in the CI configuration files
  • Loading branch information
philippgille committed May 1, 2018
1 parent d25e404 commit 95fa875
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ install:

build_script:
- go build
- .\build.ps1
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ go:

script:
- go build
- ./build.sh
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down Expand Up @@ -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`
13 changes: 13 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 95fa875

Please sign in to comment.