Repository navigation
Expand file tree
/
Copy pathbuild
More file actions
executable file
·114 lines (94 loc) · 3.21 KB
/
Copy pathbuild
File metadata and controls
executable file
·114 lines (94 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -eu
print_usage() {
echo "Usage: $0 [ignition|ignition-validate|ignition-validate-cross|butane|butane-cross]" >&2
}
if [ $# -eq 0 ]; then
print_usage
exit 1
fi
export GO111MODULE=on
NAME="ignition"
ORG_PATH="github.com/coreos"
REPO_PATH="${ORG_PATH}/${NAME}/v2"
export GOFLAGS=-mod=vendor
GLDFLAGS=${GLDFLAGS:-}
if [ -z "${VERSION:-}" ]; then
VERSION=$(git describe --dirty --always)
echo "Using version from git: ${VERSION}"
fi
GLDFLAGS+=" -X github.com/coreos/ignition/v2/internal/version.Raw=${VERSION}"
eval $(go env)
if [ -z ${BIN_PATH+a} ]; then
export BIN_PATH=${PWD}/bin/
fi
export CGO_ENABLED=1
ignition() {
local name="ignition"
echo "Building ${name} ${GOEXPERIMENT:+with GOEXPERIMENT=${GOEXPERIMENT}}..."
# clean the cache since cgo isn't correctly handled by gocache.
go clean -cache -testcache
go build -buildmode=pie -ldflags "${GLDFLAGS}" -o "${BIN_PATH}/${name}" ${REPO_PATH}/internal
}
ignition_validate() {
local name="ignition-validate"
echo "Building ${name}..."
go build -ldflags "${GLDFLAGS}" -o "${BIN_PATH}/${name}" ${REPO_PATH}/validate
}
build_cross_validate() {
local goos=$1 goarch=$2 output=$3
echo "Building ${output}..."
CGO_ENABLED=0 GOARCH=${goarch} GOOS=${goos} go build -ldflags "${GLDFLAGS}" -a -v -x -o "${BIN_PATH}/${output}" ${REPO_PATH}/validate
}
ignition_validate_cross() {
build_cross_validate linux arm64 ignition-validate-aarch64-unknown-linux-gnu-static
build_cross_validate darwin arm64 ignition-validate-aarch64-apple-darwin
build_cross_validate linux ppc64le ignition-validate-ppc64le-unknown-linux-gnu-static
build_cross_validate linux s390x ignition-validate-s390x-unknown-linux-gnu-static
build_cross_validate linux amd64 ignition-validate-x86_64-unknown-linux-gnu-static
build_cross_validate darwin amd64 ignition-validate-x86_64-apple-darwin
build_cross_validate windows amd64 ignition-validate-x86_64-pc-windows-gnu.exe
}
butane() {
local name="butane"
local butane_ldflags="-X github.com/coreos/ignition/v2/butane/internal/version.Raw=${VERSION}"
echo "Building ${name}..."
CGO_ENABLED=0 go build -ldflags "${butane_ldflags}" -o "${BIN_PATH}/${name}" ${REPO_PATH}/butane/internal
}
build_cross_butane() {
local goos=$1 goarch=$2 output=$3
local butane_ldflags="-X github.com/coreos/ignition/v2/butane/internal/version.Raw=${VERSION}"
echo "Building ${output}..."
CGO_ENABLED=0 GOARCH=${goarch} GOOS=${goos} go build -ldflags "${butane_ldflags}" -a -v -x -o "${BIN_PATH}/${output}" ${REPO_PATH}/butane/internal
}
butane_cross() {
build_cross_butane linux arm64 butane-aarch64-unknown-linux-gnu-static
build_cross_butane darwin arm64 butane-aarch64-apple-darwin
build_cross_butane linux ppc64le butane-ppc64le-unknown-linux-gnu-static
build_cross_butane linux s390x butane-s390x-unknown-linux-gnu-static
build_cross_butane linux amd64 butane-x86_64-unknown-linux-gnu-static
build_cross_butane darwin amd64 butane-x86_64-apple-darwin
build_cross_butane windows amd64 butane-x86_64-pc-windows-gnu.exe
}
case "$1" in
ignition)
ignition
;;
ignition-validate)
ignition_validate
;;
ignition-validate-cross)
ignition_validate_cross
;;
butane)
butane
;;
butane-cross)
butane_cross
;;
*)
echo "Unknown command: $1" >&2
print_usage
exit 1
;;
esac