Skip to content

Commit f82296c

Browse files
committed
install cross-compilation toolchain
1 parent b2df10f commit f82296c

File tree

3 files changed

+169
-8
lines changed

3 files changed

+169
-8
lines changed

.github/workflows/dd-build.yaml

+64-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,78 @@ on:
88
- "*-dd*"
99
permissions: write-all
1010
jobs:
11-
build:
11+
build-arm64:
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
platform:
16+
- "linux/arm64"
1317
steps:
1418
- uses: actions/checkout@v4
1519
with:
1620
fetch-depth: 0
17-
- name: Set release version environment variable
18-
run: echo RELEASE_VERSION=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV
21+
- name: Set environment variables
22+
id: set_env
23+
run: |
24+
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
25+
echo "GOOS=$(echo ${{ matrix.platform }} | cut -d'/' -f1)" >> $GITHUB_ENV
26+
echo "GOARCH=$(echo ${{ matrix.platform }} | cut -d'/' -f2)" >> $GITHUB_ENV
1927
env:
2028
GITHUB_REF: ${{ github.ref }}
2129
- name: Build etcd
22-
run: REPOSITORY=https://github.com/${{ env.GITHUB_REPOSITORY}}.git CGO_ENABLED=1 GOEXPERIMENT=boringcrypto ./scripts/build-binary ${{ env.RELEASE_VERSION }}
30+
run: |
31+
REPOSITORY=https://github.com/${{ env.GITHUB_REPOSITORY}}.git \
32+
CGO_ENABLED=1 \
33+
GO_BUILD_FLAGS="-tags=fips" \
34+
GO_ADDITIONAL_FLAGS="GOEXPERIMENT=boringcrypto" \
35+
GOOS=${GOOS} \
36+
GOARCH=${GOARCH} \
37+
./scripts/build-release-single-target ${{ env.RELEASE_VERSION }}
38+
env:
39+
GITHUB_REPOSITORY: ${{ github.repository }}
40+
- name: Calculate checksums
41+
id: calculate_checksums
42+
shell: bash
43+
working-directory: release/
44+
run: ls . | grep -E '\.tar.gz$|\.zip$' | xargs shasum -a 256 > ./SHA256SUMS
45+
- uses: actions/upload-artifact@v4
46+
with:
47+
name: etcd_output
48+
path: release/
49+
build:
50+
strategy:
51+
matrix:
52+
platform:
53+
- "linux/amd64"
54+
- "linux/ppc64le"
55+
- "linux/s390x"
56+
- "darwin/amd64"
57+
- "darwin/arm64"
58+
- "windows/amd64"
59+
- "windows/arm64"
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0
65+
- name: Install cross-compilation toolchain
66+
run: |
67+
sudo apt-get update
68+
sudo apt-get install -y gcc-aarch64-linux-gnu
69+
- name: Set environment variables
70+
id: set_env
71+
run: |
72+
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
73+
echo "GOOS=$(echo ${{ matrix.platform }} | cut -d'/' -f1)" >> $GITHUB_ENV
74+
echo "GOARCH=$(echo ${{ matrix.platform }} | cut -d'/' -f2)" >> $GITHUB_ENV
75+
- name: Build etcd
76+
run: |
77+
REPOSITORY=https://github.com/${{ env.GITHUB_REPOSITORY}}.git \
78+
CGO_ENABLED=1 \
79+
GOEXPERIMENT=boringcrypto \
80+
GOOS=${GOOS} \
81+
GOARCH=${GOARCH} \
82+
./scripts/build-release-single-target ${{ env.RELEASE_VERSION }}
2383
env:
2484
GITHUB_REPOSITORY: ${{ github.repository }}
2585
- name: Calculate checksums

build.sh

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ CGO_ENABLED="${CGO_ENABLED:-0}"
2020
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
2121
# shellcheck disable=SC2206
2222
GO_LDFLAGS=(${GO_LDFLAGS:-} "-X=${VERSION_SYMBOL}=${GIT_SHA}")
23-
GO_BUILD_ENV=("CGO_ENABLED=${CGO_ENABLED}" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS:-}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")
23+
24+
# Allow additional build flags to be passed
25+
GO_ADDITIONAL_FLAGS=${GO_ADDITIONAL_FLAGS:-}
26+
27+
# Initialize GO_BUILD_ENV with common variables
28+
GO_BUILD_ENV=("CGO_ENABLED=${CGO_ENABLED}" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS:-}" "GO_ADDITIONAL_FLAGS=${GO_ADDITIONAL_FLAGS}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")
29+
30+
# Add CC only when building for Linux ARM64
31+
if [ "${CGO_ENABLED}" = "1" ] && [ -n "${CC:-}" ] && [ "${GOOS}" = "linux" ] && [ "${GOARCH}" = "arm64" ]; then
32+
GO_BUILD_ENV+=("CC=${CC}")
33+
fi
2434

2535
GOFAIL_VERSION=$(cd tools/mod && go list -m -f '{{.Version}}' go.etcd.io/gofail)
2636
# enable/disable failpoints
@@ -65,7 +75,7 @@ etcd_build() {
6575
cd ./server
6676
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
6777
# shellcheck disable=SC2086
68-
run env "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
78+
run env "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} ${GO_ADDITIONAL_FLAGS:-} \
6979
-trimpath \
7080
-installsuffix=cgo \
7181
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -76,7 +86,7 @@ etcd_build() {
7686
# shellcheck disable=SC2086
7787
(
7888
cd ./etcdutl
79-
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
89+
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} ${GO_ADDITIONAL_FLAGS:-} \
8090
-trimpath \
8191
-installsuffix=cgo \
8292
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -87,7 +97,7 @@ etcd_build() {
8797
# shellcheck disable=SC2086
8898
(
8999
cd ./etcdctl
90-
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
100+
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} ${GO_ADDITIONAL_FLAGS:-} \
91101
-trimpath \
92102
-installsuffix=cgo \
93103
"-ldflags=${GO_LDFLAGS[*]}" \

scripts/build-release-single-target

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
source ./scripts/test_lib.sh
6+
7+
VER=${1:-}
8+
REPOSITORY="${REPOSITORY:-git@github.com:etcd-io/etcd.git}"
9+
10+
if [ -z "${VER}" ]; then
11+
echo "Usage: ${0} VERSION" >> /dev/stderr
12+
exit 255
13+
fi
14+
15+
16+
function setup_env {
17+
local ver=${1}
18+
local proj=${2}
19+
20+
if [ ! -d "${proj}" ]; then
21+
run git clone "${REPOSITORY}"
22+
fi
23+
24+
pushd "${proj}" >/dev/null
25+
run git fetch --all
26+
run git checkout "${ver}"
27+
popd >/dev/null
28+
}
29+
30+
31+
function package {
32+
local target=${1}
33+
local srcdir="${2}/bin"
34+
35+
local ccdir="${srcdir}/${GOOS}_${GOARCH}"
36+
if [ -d "${ccdir}" ]; then
37+
srcdir="${ccdir}"
38+
fi
39+
local ext=""
40+
if [ "${GOOS:-}" == "windows" ]; then
41+
ext=".exe"
42+
fi
43+
for bin in etcd etcdctl etcdutl; do
44+
cp "${srcdir}/${bin}" "${target}/${bin}${ext}"
45+
done
46+
47+
cp etcd/README.md "${target}"/README.md
48+
cp etcd/etcdctl/README.md "${target}"/README-etcdctl.md
49+
cp etcd/etcdctl/READMEv2.md "${target}"/READMEv2-etcdctl.md
50+
cp etcd/etcdutl/README.md "${target}"/README-etcdutl.md
51+
52+
cp -R etcd/Documentation "${target}"/Documentation
53+
}
54+
55+
function main {
56+
local proj="etcd"
57+
58+
mkdir -p release
59+
cd release
60+
setup_env "${VER}" "${proj}"
61+
62+
local tarcmd=tar
63+
if [[ $(go env GOOS) == "darwin" ]]; then
64+
echo "Please use linux machine for release builds."
65+
exit 1
66+
fi
67+
68+
# Use environment variables if set, otherwise default to linux/amd64
69+
GOOS=${GOOS:-linux}
70+
GOARCH=${GOARCH:-amd64}
71+
72+
echo "Building etcd for ${GOOS}/${GOARCH}..."
73+
74+
pushd etcd >/dev/null
75+
GO_LDFLAGS="-s -w" ./build.sh
76+
popd >/dev/null
77+
78+
TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
79+
mkdir "${TARGET}"
80+
package "${TARGET}" "${proj}"
81+
82+
if [ ${GOOS} == "linux" ]; then
83+
${tarcmd} cfz "${TARGET}.tar.gz" "${TARGET}"
84+
echo "Wrote release/${TARGET}.tar.gz"
85+
else
86+
zip -qr "${TARGET}.zip" "${TARGET}"
87+
echo "Wrote release/${TARGET}.zip"
88+
fi
89+
}
90+
91+
main

0 commit comments

Comments
 (0)