Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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