From a20cea2bedb99fa418113cbe4d357de01da557c1 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Tue, 4 Jun 2019 16:53:41 +0200 Subject: [PATCH] Build releases using Bazel --- BUILD | 16 +++++++++++----- build.sh | 26 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/BUILD b/BUILD index 54e5ea39..5400f7ff 100644 --- a/BUILD +++ b/BUILD @@ -7,17 +7,23 @@ gazelle(name = "gazelle") sh_test( name = "py_bazelisk_test", srcs = ["bazelisk_test.sh"], - data = ["bazelisk.py", "releases_for_tests.json"], + args = ["PY"], + data = [ + "bazelisk.py", + "releases_for_tests.json", + ], deps = ["@bazel_tools//tools/bash/runfiles"], - args = ["PY"] ) sh_test( name = "go_bazelisk_test", srcs = ["bazelisk_test.sh"], - data = [":bazelisk", "releases_for_tests.json"], + args = ["GO"], + data = [ + "releases_for_tests.json", + ":bazelisk", + ], deps = ["@bazel_tools//tools/bash/runfiles"], - args = ["GO"] ) go_library( @@ -25,8 +31,8 @@ go_library( srcs = ["bazelisk.go"], importpath = "github.com/philwo/bazelisk", visibility = ["//visibility:private"], - deps = ["@com_github_hashicorp_go_version//:go_default_library"], x_defs = {"BazeliskVersion": "{STABLE_VERSION}"}, + deps = ["@com_github_hashicorp_go_version//:go_default_library"], ) go_binary( diff --git a/build.sh b/build.sh index 73ba79f4..a4b8f23c 100755 --- a/build.sh +++ b/build.sh @@ -16,6 +16,26 @@ set -euxo pipefail -GOOS=linux GOARCH=amd64 go build -o bin/bazelisk-linux-amd64 -GOOS=darwin GOARCH=amd64 go build -o bin/bazelisk-darwin-amd64 -GOOS=windows GOARCH=amd64 go build -o bin/bazelisk-windows-amd64.exe +### Build release artifacts using Bazel. +go build +for platform in darwin linux windows; do + USE_BAZEL_VERSION=0.25.3 ./bazelisk build \ + --stamp \ + --workspace_status_command="$PWD/stamp.sh" \ + --platforms=@io_bazel_rules_go//go/toolchain:${platform}_amd64 \ + //:bazelisk + if [[ $platform == windows ]]; then + cp bazel-bin/${platform}_*/bazelisk.exe bin/bazelisk-${platform}-amd64.exe + else + cp bazel-bin/${platform}_*/bazelisk bin/bazelisk-${platform}-amd64 + fi +done +rm -f bazelisk + +### Build release artifacts using `go build`. +# GOOS=linux GOARCH=amd64 go build -o bin/bazelisk-linux-amd64 +# GOOS=darwin GOARCH=amd64 go build -o bin/bazelisk-darwin-amd64 +# GOOS=windows GOARCH=amd64 go build -o bin/bazelisk-windows-amd64.exe + +### Print some information about the generated binaries. +file bin/*