@@ -61,37 +61,95 @@ jobs:
6161 ./bins/linux-arm64 \
6262 ./artifacts
6363
64- build() {
65- for binary in \
64+ function build() {
65+ for command in \
6666 influx \
6767 influx_inspect \
6868 influxd
6969 do
70- go build \
71- -tags "netgo,osusergo,static_build" \
72- -buildmode=pie \
73- -ldflags="-s
74- -X \"main.version=${VERSION}\"
75- -X \"main.branch=${CIRCLE_BRANCH}\"
76- -X \"main.commit=${CIRCLE_SHA1}\"
77- -linkmode=external
78- -extld=${CC}
79- -extldflags \"-fno-PIC -static-pie -Wl,-z,stack-size=8388608\"" \
80- -o "bins/${GOOS}-${GOARCH}/${binary}" \
81- "github.com/influxdata/influxdb/cmd/${binary}"
70+ # tags
71+ case "${GOOS}" in
72+ darwin)
73+ tags='netgo,osusergo'
74+ ;;
75+ linux|windows)
76+ tags='netgo,osusergo,static_build'
77+ ;;
78+ esac
79+
80+ # buildmode
81+ case "${GOOS}" in
82+ darwin|linux)
83+ buildmode='pie'
84+ ;;
85+ windows)
86+ buildmode='exe'
87+ ;;
88+ esac
89+
90+ # linker flags
91+ case "${GOOS}" in
92+ darwin|windows)
93+ ldflags='-s -w'
94+ ;;
95+ linux)
96+ ldflags='-s -w -linkmode=external -extld='"${CC}"' -extldflags "-fno-PIC -static-pie -Wl,-z,stack-size=8388608"'
97+ ;;
98+ esac
99+
100+ # windows requires ".exe" appended to filename
101+ if [[ "${GOOS}" = windows ]] ; then
102+ binary="bins/${GOOS}-${GOARCH}/${command}.exe"
103+ else
104+ binary="bins/${GOOS}-${GOARCH}/${command}"
105+ fi
106+
107+ set -x
108+ go build -tags="${tags}" -buildmode="${buildmode}" \
109+ -ldflags="${ldflags:-}
110+ -X \"main.version=${VERSION}\"
111+ -X \"main.branch=${CIRCLE_BRANCH}\"
112+ -X \"main.commit=${CIRCLE_SHA1}\"
113+ " \
114+ -o "${binary}" \
115+ "github.com/influxdata/influxdb/cmd/${command}"
116+ set +x
82117 done
83118 }
84119
85120 archive() {
86121 target="artifacts/influxdb_bin_${GOOS}_${GOARCH}-${CIRCLE_SHA1}.tar.gz"
87- tar -czf "${target}" -C "bins/${GOOS}-${GOARCH}" \
88- influx \
89- influx_inspect \
90- influxd
122+ if [[ "${GOOS}" = windows ]] ; then
123+ tar -czf "${target}" -C "bins/${GOOS}-${GOARCH}" \
124+ influx.exe \
125+ influx_inspect.exe \
126+ influxd.exe
127+ else
128+ tar -czf "${target}" -C "bins/${GOOS}-${GOARCH}" \
129+ influx \
130+ influx_inspect \
131+ influxd
132+ fi
91133 md5sum "${target}" > "${target}.md5"
92134 sha256sum "${target}" > "${target}.sha256"
93135 }
94136
137+ # darwin
138+ export CC="$(xcc darwin)"
139+ export CGO_ENABLED=1
140+ export GOARCH=amd64
141+ export GOOS=darwin
142+ build
143+ archive
144+
145+ # windows
146+ export CC="$(xcc windows)"
147+ export CGO_ENABLED=1
148+ export GOARCH=amd64
149+ export GOOS=windows
150+ build
151+ archive
152+
95153 # linux amd64 (static build)
96154 export CC="$(xcc linux x86_64)"
97155 export CGO_ENABLED=1
0 commit comments