mirror of https://github.com/knative/client.git
Add target platform flag to build script (#1981)
* Add targer platform flag to build script * Update hack/build.sh Co-authored-by: Chris Suszynski <krzysztof.suszynski@gmail.com> * Drop -mod=vendor flag --------- Co-authored-by: Chris Suszynski <krzysztof.suszynski@gmail.com>
This commit is contained in:
parent
747ac988ce
commit
441372aea1
|
|
@ -75,6 +75,15 @@ run() {
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# platform mode: Only to build target platform for cross-compilation
|
||||||
|
if has_flag --platform -p; then
|
||||||
|
# Extract GOOS and GOARCH from command-line arguments
|
||||||
|
GOOS="${ARGS[1]}"
|
||||||
|
GOARCH="${ARGS[2]}"
|
||||||
|
go_build_with_goos_goarch "$GOOS" "$GOARCH"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Run only tests
|
# Run only tests
|
||||||
if has_flag --test -t; then
|
if has_flag --test -t; then
|
||||||
go_test
|
go_test
|
||||||
|
|
@ -146,6 +155,25 @@ go_build() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go_build_with_goos_goarch() {
|
||||||
|
GOOS="${1:-}"
|
||||||
|
GOARCH="${2:-}"
|
||||||
|
|
||||||
|
if [ -z "${GOOS}" ] || [ -z "${GOARCH}" ]; then
|
||||||
|
echo "❌ Missing GOOS or GOARCH. Please provide both GOOS and GOARCH as arguments."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🚧 Compile for GOOS=${GOOS} GOARCH=${GOARCH}"
|
||||||
|
|
||||||
|
# Env var exported by hack/build-flags.sh
|
||||||
|
GOOS="${GOOS}" GOARCH="${GOARCH}" go build -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
|
||||||
|
|
||||||
|
if $(file kn | grep -q -i "Windows"); then
|
||||||
|
mv kn kn.exe
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
go_test() {
|
go_test() {
|
||||||
local test_output
|
local test_output
|
||||||
test_output="$(mktemp /tmp/kn-client-test-output.XXXXXX)"
|
test_output="$(mktemp /tmp/kn-client-test-output.XXXXXX)"
|
||||||
|
|
@ -336,6 +364,7 @@ Usage: $(basename "${BASH_SOURCE[0]}") [... options ...]
|
||||||
with the following options:
|
with the following options:
|
||||||
|
|
||||||
-f --fast Only compile (without dep update, formatting, testing, doc gen)
|
-f --fast Only compile (without dep update, formatting, testing, doc gen)
|
||||||
|
-p --platform Specify the target platform for cross-compilation (e.g., linux amd64, darwin amd64)"
|
||||||
-t --test Run tests when used with --fast or --watch
|
-t --test Run tests when used with --fast or --watch
|
||||||
-c --codegen Runs formatting, doc gen and update without compiling/testing
|
-c --codegen Runs formatting, doc gen and update without compiling/testing
|
||||||
-w --watch Watch for source changes and recompile in fast mode
|
-w --watch Watch for source changes and recompile in fast mode
|
||||||
|
|
@ -353,12 +382,13 @@ ln -s $(basedir)/hack/build.sh /usr/local/bin/kn_build.sh
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
* Update deps, format, license check,
|
* Update deps, format, license check,
|
||||||
gen docs, compile, test: ........... build.sh
|
gen docs, compile, test: ........................ build.sh
|
||||||
* Compile only: ...................... build.sh --fast
|
* Compile only: ................................... build.sh --fast
|
||||||
* Run only tests: .................... build.sh --test
|
* Build cross platform binaries for a platform: ... build.sh -p linux amd64
|
||||||
* Compile with tests: ................ build.sh -f -t
|
* Run only tests: ................................. build.sh --test
|
||||||
* Automatic recompilation: ........... build.sh --watch
|
* Compile with tests: ............................. build.sh -f -t
|
||||||
* Build cross platform binaries: ..... build.sh --all
|
* Automatic recompilation: ........................ build.sh --watch
|
||||||
|
* Build cross platform binaries: .................. build.sh --all
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue