Adds option in hack/build.sh to build cross platform binaries (#371)

- 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
This commit is contained in:
Navid Shaikh 2019-08-22 04:46:33 +05:30 committed by Knative Prow Robot
parent 223ff5316a
commit d6c798ad65
1 changed files with 22 additions and 0 deletions

View File

@ -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"
@ -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
@ -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:-}"
@ -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)
@ -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
}