Skip to content

Commit 741b834

Browse files
author
Akash Satheesan
authored
feat(ci): armv7 cross builds (#3892)
1 parent fb11766 commit 741b834

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

.github/workflows/ci.yaml

+26-15
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,32 @@ jobs:
234234
# It is not feasible to cross-compile with CentOS.
235235

236236
# Cross-compile notes: To compile native dependencies for arm64,
237-
# we install the aarch64 cross toolchain and then set it as the default
237+
# we install the aarch64/armv7l cross toolchain and then set it as the default
238238
# compiler/linker/etc. with the AR/CC/CXX/LINK environment variables.
239239
# qemu-user-static on ubuntu-16.04 currently doesn't run Node correctly,
240-
# so we just build with "native"/x86_64 node, then download arm64 node
241-
# and then put it in our release. We can't smoke test the arm64 build this way,
240+
# so we just build with "native"/x86_64 node, then download arm64/armv7l node
241+
# and then put it in our release. We can't smoke test the cross build this way,
242242
# but this means we don't need to maintain a self-hosted runner!
243-
package-linux-arm64:
244-
name: Linux ARM64 cross-compile build
243+
package-linux-cross:
244+
name: Linux cross-compile builds
245245
needs: build
246246
runs-on: ubuntu-16.04
247247
timeout-minutes: 15
248+
strategy:
249+
matrix:
250+
include:
251+
- prefix: aarch64-linux-gnu
252+
arch: arm64
253+
- prefix: arm-linux-gnueabihf
254+
arch: armv7l
255+
248256
env:
249-
AR: aarch64-linux-gnu-ar
250-
CC: aarch64-linux-gnu-gcc
251-
CXX: aarch64-linux-gnu-g++
252-
LINK: aarch64-linux-gnu-g++
253-
NPM_CONFIG_ARCH: arm64
257+
AR: ${{ format('{0}-ar', matrix.prefix) }}
258+
CC: ${{ format('{0}-gcc', matrix.prefix) }}
259+
CXX: ${{ format('{0}-g++', matrix.prefix) }}
260+
LINK: ${{ format('{0}-g++', matrix.prefix) }}
261+
NPM_CONFIG_ARCH: ${{ matrix.arch }}
262+
NODE_VERSION: v14.17.4
254263

255264
steps:
256265
- uses: actions/checkout@v2
@@ -266,7 +275,9 @@ jobs:
266275
echo "$HOME/.local/bin" >> $GITHUB_PATH
267276
268277
- name: Install cross-compiler
269-
run: sudo apt install g++-aarch64-linux-gnu
278+
run: sudo apt install $PACKAGE
279+
env:
280+
PACKAGE: ${{ format('g++-{0}', matrix.prefix) }}
270281

271282
- name: Download npm package
272283
uses: actions/download-artifact@v2
@@ -279,14 +290,14 @@ jobs:
279290
- name: Build standalone release
280291
run: yarn release:standalone
281292

282-
- name: Replace node with arm64 equivalent
293+
- name: Replace node with cross-compile equivalent
283294
run: |
284-
wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-arm64.tar.xz
285-
tar -xf node-v14.17.0-linux-arm64.tar.xz node-v14.17.0-linux-arm64/bin/node --strip-components=2
295+
wget https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-${NPM_CONFIG_ARCH}.tar.xz
296+
tar -xf node-${NODE_VERSION}-linux-${NPM_CONFIG_ARCH}.tar.xz node-${NODE_VERSION}-linux-${NPM_CONFIG_ARCH}/bin/node --strip-components=2
286297
mv ./node ./release-standalone/lib/node
287298
288299
- name: Build packages with nfpm
289-
run: yarn package arm64
300+
run: yarn package ${NPM_CONFIG_ARCH}
290301

291302
- name: Upload release artifacts
292303
uses: actions/upload-artifact@v2

ci/build/arch-override.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rpm": {
3+
"armv7l": "armhfp"
4+
},
5+
"deb": {
6+
"armv7l": "armhf"
7+
}
8+
}

ci/build/build-packages.sh

+20-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,31 @@ release_gcp() {
4343
cp "./release-packages/$release_name.tar.gz" "./release-gcp/latest/$OS-$ARCH.tar.gz"
4444
}
4545

46+
# On some CPU architectures (notably node/uname "armv7l", default on Raspberry Pis),
47+
# different package managers have different labels for the same CPU (deb=armhf, rpm=armhfp).
48+
# This function parses arch-override.json and returns the overriden arch on platforms
49+
# with alternate labels, or the same arch otherwise.
50+
get_nfpm_arch() {
51+
if jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json > /dev/null; then
52+
jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json
53+
else
54+
echo "$ARCH"
55+
fi
56+
}
57+
4658
# Generates deb and rpm packages.
4759
release_nfpm() {
4860
local nfpm_config
61+
62+
PKG_FORMAT="deb"
63+
NFPM_ARCH="$(get_nfpm_arch)"
4964
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
65+
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server_${VERSION}_${NFPM_ARCH}.deb"
5066

51-
# The underscores are convention for .deb.
52-
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server_${VERSION}_$ARCH.deb"
53-
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server-$VERSION-$ARCH.rpm"
67+
PKG_FORMAT="rpm"
68+
NFPM_ARCH="$(get_nfpm_arch)"
69+
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
70+
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server-$VERSION-$NFPM_ARCH.rpm"
5471
}
5572

5673
main "$@"

ci/build/nfpm.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "code-server"
2-
arch: "${ARCH}"
2+
arch: "${NFPM_ARCH}"
33
platform: "linux"
44
version: "v${VERSION}"
55
section: "devel"

0 commit comments

Comments
 (0)