Skip to content

Commit

Permalink
Adds option in hack/build.sh to build cross platform binaries (#371)
Browse files Browse the repository at this point in the history
- Use `./hack/build.sh -x` or `./hack/build.sh --build-cross`
 - Doesn't touch any of the existing flow, providing these options will build binaries and exit
  • Loading branch information
navidshaikh authored and knative-prow-robot committed Aug 21, 2019
1 parent 223ff53 commit d6c798a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

source $(dirname $0)/build-flags.sh

set -o pipefail

source_dirs="cmd pkg test"
Expand Down Expand Up @@ -46,6 +48,11 @@ run() {
exit 0
fi

if $(has_flag --build-cross -x); then
build_cross
exit 0
fi

if $(has_flag --watch -w); then
# Build and test first
go_build
Expand Down Expand Up @@ -259,6 +266,19 @@ has_flag() {
echo 'false'
}

build_cross() {
local ld_flags="$(build_flags $(dirname $0)/..)"
local pkg="github.com/knative/client/pkg/kn/commands"

export CGO_ENABLED=0
echo "🚧 🐧 Building for Linux"
GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-amd64 ./cmd/... || exit 1
echo "🚧 🍏 Building for macOS"
GOOS=darwin GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-darwin-amd64 ./cmd/... || exit 1
echo "🚧 🎠 Building for Windows"
GOOS=windows GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-windows-amd64.exe ./cmd/... || exit
}

# Display a help message.
display_help() {
local command="${1:-}"
Expand All @@ -273,6 +293,7 @@ with the following options:
-t --test Run tests when used with --fast or --watch
-c --codegen Runs formatting, doc gen and update without compiling/testing
-w --watch Watch for source changes and recompile in fast mode
-x --build-cross Build cross platform binaries
-h --help Display this help message
--verbose More output
--debug Debug information for this script (set -x)
Expand All @@ -290,6 +311,7 @@ Examples:
* Run only tests: .................... build.sh --test
* Compile with tests: ................ build.sh -f -t
* Automatic recompilation: ........... build.sh --watch
* Build cross platform binaries: ..... build.sh --build-cross
EOT
}

Expand Down

0 comments on commit d6c798a

Please sign in to comment.