Preparation
We need golang 1.12 or later to compile cloudflared. But the official go version on Raspbian is 1.7. Use this to download golang 1.12. Extract the content and take note of the path.
wget https://storage.googleapis.com/golang/go1.12.linux-armv6l.tar.gz
Also, the build process needs more than 1GB of memory. You may want to create a temporary swap file:
sudo fallocate -l 1G swapfile
sudo dd if=/dev/zero of=swapfile bs=1M count=1024
sudo chmod 600 swapfile
sudo mkswap swapfile
sudo swapon swapfile
After building cloudflared, you can use "swapoff" to remove the temporary swap space and then delete the physical file.
Compiling
Here is the script to compile the cloudflared binary. Save and run it under a working folder. Edit the definition of the first two variables to point to the golang version you are using and the cloudflared version to compile. If you are corss-compiling, change the "CC" environment to the cross compiler.#!/bin/sh
set -e
# custom install version of go >= 1.12
GOLANG_PATH=$HOME/apps/go/bin
# which version to build
CLOUDFLARED_VERSION=2019.11.0
export GOPATH=$(pwd)
export GOOS=linux
export GOARCH=arm
export GOARM=6
export CGO_ENABLED=1
export CC=gcc
export PATH=${GOLANG_PATH}:$PATH
CLOUDFLARED_BUILDTIME=$(date)
go get -v github.com/cloudflare/cloudflared/cmd/cloudflared
cd src/github.com/cloudflare/cloudflared
git checkout tags/${CLOUDFLARED_VERSION}
cd ../../../../
go build -v "-ldflags=-X 'main.Version=${CLOUDFLARED_VERSION}' -X 'main.BuildTime=${CLOUDFLARED_BUILDTIME}'" github.com/cloudflare/cloudflared/cmd/cloudflared
1 comment:
Thanks for these instructions and script. They worked perfectly today to compile Cloudflared 20202.8.0 using golang 14.7 on my pi zero. I was getting the segfault on the prebuilt binary from Cloudflare.
Post a Comment