Skip to content

Commit 4fe3a37

Browse files
aykevldeadprogram
authored andcommitted
ci: add ARM build, cross compiled on an amd64 host
I'm making this so I don't have to build all the releases on my Raspberry Pi at home, and to make the process more reproducible.
1 parent fce42fc commit 4fe3a37

File tree

2 files changed

+142
-10
lines changed

2 files changed

+142
-10
lines changed

.github/workflows/linux.yml

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ jobs:
8484
run: make wasi-libc
8585
- name: Install fpm
8686
run: |
87-
sudo apt-get install ruby ruby-dev
8887
sudo gem install --no-document fpm
8988
- name: Build TinyGo release
9089
run: |
@@ -94,7 +93,7 @@ jobs:
9493
- name: Publish release artifact
9594
uses: actions/upload-artifact@v2
9695
with:
97-
name: release-double-zipped
96+
name: linux-amd64-double-zipped
9897
path: |
9998
/tmp/tinygo.linux-amd64.tar.gz
10099
/tmp/tinygo_amd64.deb
@@ -116,7 +115,7 @@ jobs:
116115
- name: Download release artifact
117116
uses: actions/download-artifact@v2
118117
with:
119-
name: release-double-zipped
118+
name: linux-amd64-double-zipped
120119
- name: Extract release tarball
121120
run: |
122121
mkdir -p ~/lib
@@ -242,3 +241,108 @@ jobs:
242241
- run: make smoketest
243242
- run: make wasmtest
244243
- run: make tinygo-baremetal
244+
build-linux-arm:
245+
# Build ARM Linux binaries, ready for release.
246+
# This intentionally uses an older Linux image, so that we compile against
247+
# an older glibc version and therefore are compatible with a wide range of
248+
# Linux distributions.
249+
# It is set to "needs: build-linux" because it modifies the release created
250+
# in that process to avoid doing lots of duplicate work and to avoid
251+
# complications around precompiled libraries such as compiler-rt shipped as
252+
# part of the release tarball.
253+
runs-on: ubuntu-18.04
254+
needs: build-linux
255+
steps:
256+
- name: Checkout
257+
uses: actions/checkout@v2
258+
- name: Install apt dependencies
259+
run: |
260+
sudo apt-get install --no-install-recommends \
261+
qemu-user \
262+
g++-arm-linux-gnueabihf \
263+
libc6-dev-armhf-cross
264+
- name: Install Go
265+
uses: actions/setup-go@v2
266+
with:
267+
go-version: '1.17'
268+
- name: Cache Go
269+
uses: actions/cache@v2
270+
with:
271+
key: go-cache-linux-arm-v2-${{ hashFiles('go.mod') }}
272+
path: |
273+
~/.cache/go-build
274+
~/go/pkg/mod
275+
- name: Cache LLVM source
276+
uses: actions/cache@v2
277+
id: cache-llvm-source
278+
with:
279+
key: llvm-source-14-linux-v1
280+
path: |
281+
llvm-project/clang/lib/Headers
282+
llvm-project/clang/include
283+
llvm-project/compiler-rt
284+
llvm-project/lld/include
285+
llvm-project/llvm/include
286+
- name: Download LLVM source
287+
if: steps.cache-llvm-source.outputs.cache-hit != 'true'
288+
run: make llvm-source
289+
- name: Cache LLVM build
290+
uses: actions/cache@v2
291+
id: cache-llvm-build
292+
with:
293+
key: llvm-build-14-linux-arm-v1
294+
path: llvm-build
295+
- name: Build LLVM
296+
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
297+
run: |
298+
# fetch LLVM source
299+
rm -rf llvm-project
300+
make llvm-source
301+
# Install build dependencies.
302+
sudo apt-get install --no-install-recommends ninja-build
303+
# build!
304+
make llvm-build CROSS=arm-linux-gnueabihf
305+
# Remove unnecessary object files (to reduce cache size).
306+
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
307+
- name: Cache Binaryen
308+
uses: actions/cache@v2
309+
id: cache-binaryen
310+
with:
311+
key: binaryen-linux-arm-v1
312+
path: build/wasm-opt
313+
- name: Build Binaryen
314+
if: steps.cache-binaryen.outputs.cache-hit != 'true'
315+
run: |
316+
sudo apt-get install --no-install-recommends ninja-build
317+
git submodule update --init lib/binaryen
318+
make CROSS=arm-linux-gnueabihf binaryen
319+
- name: Install fpm
320+
run: |
321+
sudo gem install --no-document fpm
322+
- name: Build TinyGo binary
323+
run: |
324+
make CROSS=arm-linux-gnueabihf
325+
- name: Download amd64 release
326+
uses: actions/download-artifact@v2
327+
with:
328+
name: linux-amd64-double-zipped
329+
- name: Extract amd64 release
330+
run: |
331+
mkdir -p build/release
332+
tar -xf tinygo.linux-amd64.tar.gz -C build/release tinygo
333+
- name: Modify release
334+
run: |
335+
cp -p build/tinygo build/release/tinygo/bin
336+
cp -p build/wasm-opt build/release/tinygo/bin
337+
- name: Create arm release
338+
run: |
339+
make release deb RELEASEONLY=1 DEB_ARCH=armhf
340+
cp -p build/release.tar.gz /tmp/tinygo.linux-arm.tar.gz
341+
cp -p build/release.deb /tmp/tinygo_armhf.deb
342+
- name: Publish release artifact
343+
uses: actions/upload-artifact@v2
344+
with:
345+
name: linux-arm-double-zipped
346+
path: |
347+
/tmp/tinygo.linux-arm.tar.gz
348+
/tmp/tinygo_armhf.deb

Makefile

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ else
5050
LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=OFF'
5151
endif
5252

53+
# Cross compiling support.
54+
ifneq ($(CROSS),)
55+
CC = $(CROSS)-gcc
56+
CXX = $(CROSS)-g++
57+
LLVM_OPTION += \
58+
-DCMAKE_C_COMPILER=$(CC) \
59+
-DCMAKE_CXX_COMPILER=$(CXX) \
60+
-DLLVM_DEFAULT_TARGET_TRIPLE=$(CROSS) \
61+
-DCROSS_TOOLCHAIN_FLAGS_NATIVE="-UCMAKE_C_COMPILER;-UCMAKE_CXX_COMPILER"
62+
ifeq ($(CROSS), arm-linux-gnueabihf)
63+
# Assume we're building on a Debian-like distro, with QEMU installed.
64+
LLVM_CONFIG_PREFIX = qemu-arm -L /usr/arm-linux-gnueabihf/
65+
# The CMAKE_SYSTEM_NAME flag triggers cross compilation mode.
66+
LLVM_OPTION += \
67+
-DCMAKE_SYSTEM_NAME=Linux \
68+
-DLLVM_TARGET_ARCH=ARM
69+
GOENVFLAGS = GOARCH=arm CC=$(CC) CXX=$(CXX) CGO_ENABLED=1
70+
BINARYEN_OPTION += -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
71+
else
72+
$(error Unknown cross compilation target: $(CROSS))
73+
endif
74+
endif
75+
5376
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
5477

5578
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsmanifest
@@ -110,9 +133,9 @@ NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(ad
110133

111134
# For static linking.
112135
ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
113-
CGO_CPPFLAGS+=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
136+
CGO_CPPFLAGS+=$(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
114137
CGO_CXXFLAGS=-std=c++14
115-
CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
138+
CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
116139
endif
117140

118141
clean:
@@ -208,8 +231,7 @@ lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a:
208231
# Build the Go compiler.
209232
tinygo:
210233
@if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo " make llvm-source"; echo " make $(LLVM_BUILDDIR)"; exit 1; fi
211-
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags byollvm -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
212-
234+
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GOENVFLAGS) $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags byollvm -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
213235
test: wasi-libc
214236
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=20m -buildmode exe -tags byollvm ./builder ./cgo ./compileopts ./compiler ./interp ./transform .
215237

@@ -694,12 +716,18 @@ endif
694716
./build/tinygo build-library -target=cortex-m0plus -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/picolibc picolibc
695717
./build/tinygo build-library -target=cortex-m4 -o build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/picolibc picolibc
696718

697-
release: build/release
719+
release:
698720
tar -czf build/release.tar.gz -C build/release tinygo
699721

700-
deb: build/release
722+
DEB_ARCH ?= native
723+
deb:
701724
@mkdir -p build/release-deb/usr/local/bin
702725
@mkdir -p build/release-deb/usr/local/lib
703726
cp -ar build/release/tinygo build/release-deb/usr/local/lib/tinygo
704727
ln -sf ../lib/tinygo/bin/tinygo build/release-deb/usr/local/bin/tinygo
705-
fpm -f -s dir -t deb -n tinygo -v $(shell grep "const Version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
728+
fpm -f -s dir -t deb -n tinygo -a $(DEB_ARCH) -v $(shell grep "const Version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
729+
730+
ifneq ($(RELEASEONLY), 1)
731+
release: build/release
732+
deb: build/release
733+
endif

0 commit comments

Comments
 (0)