Skip to content

Commit

Permalink
Add support for RISC-V
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Chazapis <[email protected]>
  • Loading branch information
chazapis committed Jun 14, 2023
1 parent b66a118 commit a8d44c2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX sh -
Manual Download
---------------

1. Download `k3s` from latest [release](https://github.com/k3s-io/k3s/releases/latest), x86_64, armhf, arm64 and s390x are supported.
1. Download `k3s` from latest [release](https://github.com/k3s-io/k3s/releases/latest), x86_64, armhf, arm64, s390x and riscv64 are supported.
1. Run the server.

```bash
Expand Down
33 changes: 33 additions & 0 deletions cross-compile-riscv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#/bin/bash

# Cross-compile for RISC-V in an Ubuntu 22.04 container

# To run mount a clean checkout of the code inside the container and run the script:
#
# docker run --rm --mount type=bind,source=${PWD},target=/k3s ubuntu:22.04 /bin/bash -c /k3s/cross-compile-riscv.sh

dpkg --add-architecture riscv64
apt-get update
apt-get install -y wget curl git gcc-riscv64-linux-gnu g++-riscv64-linux-gnu pkg-config libseccomp-dev:riscv64 make zstd

HOST_ARCH=$(uname -m)
if [ ${HOST_ARCH} = aarch64 ]; then
HOST_ARCH=arm64
fi

wget -P /tmp "https://dl.google.com/go/go1.20.5.linux-${HOST_ARCH}.tar.gz"
(cd /; tar -C /usr/local -xzf "/tmp/go1.20.5.linux-${HOST_ARCH}.tar.gz")
rm -rf /tmp/go1.20.5.linux-${HOST_ARCH}.tar.gz
mkdir -p /go/src /go/bin

export GOPATH=/go
export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH

wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/${HOST_ARCH}
chmod +x /usr/local/bin/yq

cd /k3s
export ARCH=riscv64
bash -x ./scripts/download
bash -x ./scripts/build
bash -x ./scripts/package-cli
4 changes: 4 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ setup_verify_arch() {
ARCH=arm
SUFFIX=-${ARCH}hf
;;
riscv64)
ARCH=riscv64
SUFFIX=-${ARCH}
;;
*)
fatal "Unsupported architecture $ARCH"
esac
Expand Down
2 changes: 2 additions & 0 deletions scripts/binary_size_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ elif [ ${ARCH} = arm ]; then
BIN_SUFFIX="-armhf"
elif [ ${ARCH} = s390x ]; then
BIN_SUFFIX="-s390x"
elif [ ${ARCH} = riscv64 ]; then
BIN_SUFFIX="-riscv64"
fi

CMD_NAME="dist/artifacts/k3s${BIN_SUFFIX}"
Expand Down
8 changes: 8 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ if [ ${ARCH} = s390x ]; then
export GOARCH="s390x"
fi

if [ ${ARCH} = riscv64 ]; then
export GOARCH="riscv64"
# These are needed as we are cross-compiling
export CC=riscv64-linux-gnu-gcc
export PKG_CONFIG_PATH=/usr/lib/riscv64-linux-gnu/pkgconfig/
export CGO_ENABLED=1
fi

rm -f \
bin/k3s-agent \
bin/k3s-server \
Expand Down
6 changes: 5 additions & 1 deletion scripts/download
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ rm -rf ${CONTAINERD_DIR}
mkdir -p ${CHARTS_DIR}
mkdir -p ${DATA_DIR}

curl --compressed -sfL https://github.com/k3s-io/k3s-root/releases/download/${VERSION_ROOT}/k3s-root-${ARCH}.tar | tar xf -
if [ ${ARCH} = riscv64 ]; then
curl --compressed -sfL https://github.com/CARV-ICS-FORTH/k3s-root/releases/download/20230614/k3s-root-riscv64.tar | tar xf -
else
curl --compressed -sfL https://github.com/k3s-io/k3s-root/releases/download/${VERSION_ROOT}/k3s-root-${ARCH}.tar | tar xf -
fi

git clone --single-branch --branch=${VERSION_RUNC} --depth=1 https://github.com/opencontainers/runc ${RUNC_DIR}

Expand Down
4 changes: 2 additions & 2 deletions scripts/image_scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fi

ARCH=$2

# skipping image scan for s390x since trivy doesn't support s390x arch yet
if [ "${ARCH}" == "s390x" ]; then
# skipping image scan for s390x and riscv64 since trivy doesn't support these archs yet
if [ "${ARCH}" == "s390x" ] || [ "${ARCH}" == "riscv64" ]; then
exit 0
fi

Expand Down
3 changes: 3 additions & 0 deletions scripts/package-cli
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ elif [ ${ARCH} = arm ]; then
BIN_SUFFIX="-armhf"
elif [ ${ARCH} = s390x ]; then
BIN_SUFFIX="-s390x"
elif [ ${ARCH} = riscv64 ]; then
export GOARCH="riscv64"
BIN_SUFFIX="-riscv64"
fi

CMD_NAME=dist/artifacts/k3s${BIN_SUFFIX}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export -f test-wait
# ---

sonobuoy-test() {
if [ "$ARCH" = 'arm' ]; then
if [ "$ARCH" = 'arm' ] || [ "$ARCH" = 'riscv64' ]; then
echo "Aborting sonobuoy tests, images not available for $ARCH"
return 0
fi
Expand Down

0 comments on commit a8d44c2

Please sign in to comment.