Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RISC-V #7778

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,76 @@ volumes:
host:
path: /var/run/docker.sock

---
kind: pipeline
name: riscv64

platform:
os: linux
arch: amd64

trigger:
event:
exclude:
- cron

steps:
- name: skipfiles
image: plugins/git
commands:
- export NAME=$(test $DRONE_BUILD_EVENT = pull_request && echo remotes/origin/${DRONE_COMMIT_BRANCH:-master} || echo ${DRONE_COMMIT_SHA}~)
- export DIFF=$(git --no-pager diff --name-only $NAME | grep -v -f .droneignore);
- if [ -z "$DIFF" ]; then
echo "All files in PR are on ignore list";
exit 78;
else
echo "Some files in PR are not ignored, $DIFF";
fi;
when:
event:
- pull_request

- name: build
image: rancher/dapper:v0.5.0
secrets: [ AWS_SECRET_ACCESS_KEY-k3s-ci-uploader, AWS_ACCESS_KEY_ID-k3s-ci-uploader ]
environment:
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY-k3s-ci-uploader
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID-k3s-ci-uploader
commands:
- ARCH=riscv64 SKIP_IMAGE=true SKIP_VALIDATE=true SKIP_AIRGAP=true dapper ci
- echo "${DRONE_TAG}-riscv64" | sed -e 's/+/-/g' >.tags
volumes:
- name: docker
path: /var/run/docker.sock

- name: github_binary_release
image: plugins/github-release
settings:
api_key:
from_secret: github_token
prerelease: true
checksum:
- sha256
checksum_file: CHECKSUMsum-riscv64.txt
checksum_flatten: true
files:
- "dist/artifacts/*"
when:
instance:
- drone-publish.k3s.io
ref:
- refs/head/master
- refs/tags/*
event:
- tag

volumes:
- name: docker
host:
path: /var/run/docker.sock

---
kind: pipeline
name: validate_go_mods
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ENV SELINUX=${SELINUX}

# Set Dapper configuration variables
ENV DAPPER_RUN_ARGS="--privileged -v k3s-cache:/go/src/github.com/k3s-io/k3s/.cache -v trivy-cache:/root/.cache/trivy" \
DAPPER_ENV="REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE SKIP_IMAGE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER DEBUG" \
DAPPER_ENV="REPO TAG DRONE_TAG IMAGE_NAME ARCH SKIP_VALIDATE SKIP_IMAGE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER DEBUG" \
DAPPER_SOURCE="/go/src/github.com/k3s-io/k3s/" \
DAPPER_OUTPUT="./bin ./dist ./build/out ./build/static ./pkg/static ./pkg/deploy" \
DAPPER_DOCKER_SOCKET=true \
Expand Down
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
4 changes: 4 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ setup_verify_arch() {
ARCH=s390x
SUFFIX=-${ARCH}
;;
riscv64)
ARCH=riscv64
SUFFIX=-${ARCH}
;;
aarch64)
ARCH=arm64
SUFFIX=-${ARCH}
Expand Down
2 changes: 1 addition & 1 deletion install.sh.sha256sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
afacec791f66d92cec11880479c42b9e261912e0d97d3e3a3de21315b6ac49f3 install.sh
41860b3152407623d980eff26c622706ac97f15809f1064227bfabe8a9f00b16 install.sh
2 changes: 2 additions & 0 deletions scripts/binary_size_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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}${BINARY_POSTFIX}"
Expand Down
7 changes: 7 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ 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-alpine-linux-musl-gcc"
export PKG_CONFIG_PATH=/home/builder/sysroot-riscv64/usr/lib/pkgconfig/
fi

k3s_binaries=(
"bin/k3s-agent"
"bin/k3s-server"
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pushd $SCRIPT_DIR

./download
./validate
if [ ${ARCH} = riscv64 ]; then
./prepare-cross
fi
./build
./package

Expand Down
5 changes: 5 additions & 0 deletions scripts/package-cli
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ 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}${BINARY_POSTFIX}

GOOS=linux CC=gcc CXX=g++ "${GO}" generate
if [ ${ARCH} = riscv64 ]; then
export GOARCH="riscv64"
fi
LDFLAGS="
-X github.com/k3s-io/k3s/pkg/version.Version=$VERSION
-X github.com/k3s-io/k3s/pkg/version.GitCommit=${COMMIT:0:8}
Expand Down
39 changes: 39 additions & 0 deletions scripts/prepare-cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#/bin/bash

# This script prepares a cross-compilation environment for $ARCH

if [ -z "$ARCH" ]; then
echo "Error: ARCH not defined"
exit 1;
fi

if [ "$ARCH" != "riscv64" ]; then
echo "Error: Cross-compilation only available for riscv64"
exit 1;
fi

if [ "$ARCH" = "riscv64" ]; then
ALPINE_APK_REPO=https://dl-cdn.alpinelinux.org/alpine/edge/main
fi

# Build packages for cross-compiling (bootstrap.sh requires a non-root user)
adduser -D builder
addgroup builder abuild

su builder -c "abuild-keygen -an"
cp ~builder/.abuild/builder-*.rsa.pub /etc/apk/keys/

ALPINE_VERSION=$(. /etc/os-release; echo $VERSION_ID | cut -f1,2 -d.)
su builder -c "cd; git clone --single-branch --branch=$ALPINE_VERSION-stable --depth 1 https://github.com/alpinelinux/aports"
sed -i "/Cross building base system/i exit 0\n" /home/builder/aports/scripts/bootstrap.sh
apk update
su builder -c "CBUILDROOT=~/sysroot-$ARCH ~/aports/scripts/bootstrap.sh $ARCH"

# Install the cross-compiler in the host
apk -X /home/builder/packages/main add gcc-$ARCH

# Install headers and libraries in the gcc sysroot (upstream packages)
apk -X $ALPINE_APK_REPO -U --allow-untrusted \
-p /home/builder/sysroot-$ARCH --arch $ARCH add \
musl musl-dev linux-headers libseccomp-dev libseccomp-static sqlite-dev sqlite-static zlib-static libgcc
sed -i "s/^prefix=.*/prefix=\/home\/builder\/sysroot-$ARCH\/usr/g" /home/builder/sysroot-riscv64/usr/lib/pkgconfig/libseccomp.pc
Loading