kubernetes/1000-add-riscv-support.patch
2023-09-25 11:26:36 +08:00

186 lines
6.5 KiB
Diff

From 20db0e90fdfb804c5639964c54df4854771d92f7 Mon Sep 17 00:00:00 2001
From: misaka00251 <liuxin@iscas.ac.cn>
Date: Mon, 25 Sep 2023 10:49:49 +0800
Subject: [PATCH] Add riscv64 support
---
build/pause/Makefile | 3 ++-
cluster/get-kube-binaries.sh | 5 ++++-
cluster/images/etcd/Makefile | 5 ++++-
hack/lib/golang.sh | 12 ++++++++++--
hack/lib/util.sh | 5 ++++-
hack/local-up-cluster.sh | 5 ++++-
test/images/image-util.sh | 2 +-
7 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/build/pause/Makefile b/build/pause/Makefile
index 256a9fd1..ac01e882 100644
--- a/build/pause/Makefile
+++ b/build/pause/Makefile
@@ -32,7 +32,7 @@ OSVERSION ?= 1809 20H2 ltsc2022
OUTPUT_TYPE ?= docker
ALL_OS = linux windows
-ALL_ARCH.linux = amd64 arm arm64 ppc64le s390x
+ALL_ARCH.linux = amd64 arm arm64 ppc64le s390x riscv64
ALL_OS_ARCH.linux = $(foreach arch, ${ALL_ARCH.linux}, linux-$(arch))
ALL_ARCH.windows = amd64
ALL_OSVERSIONS.windows := 1809 20H2 ltsc2022
@@ -66,6 +66,7 @@ TRIPLE.linux-arm := arm-linux-gnueabihf
TRIPLE.linux-arm64 := aarch64-linux-gnu
TRIPLE.linux-ppc64le := powerpc64le-linux-gnu
TRIPLE.linux-s390x := s390x-linux-gnu
+TRIPLE.linux-riscv64 := riscv64-linux-gnu
TRIPLE := ${TRIPLE.${OS}-${ARCH}}
BASE.linux := scratch
# Source for windows pause image base is located at https://github.com/microsoft/windows-pause-image-base
diff --git a/cluster/get-kube-binaries.sh b/cluster/get-kube-binaries.sh
index 589a335f..81dc0a1c 100755
--- a/cluster/get-kube-binaries.sh
+++ b/cluster/get-kube-binaries.sh
@@ -120,9 +120,12 @@ function detect_client_info() {
s390x*)
CLIENT_ARCH="s390x"
;;
+ riscv64*)
+ CLIENT_ARCH="riscv64"
+ ;;
*)
echo "Unknown, unsupported architecture (${machine})." >&2
- echo "Supported architectures x86_64, i686, arm, arm64, ppc64le, s390x." >&2
+ echo "Supported architectures x86_64, i686, arm, arm64, ppc64le, s390x, riscv64." >&2
echo "Bailing out." >&2
exit 3
;;
diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile
index 5543cc61..cde77f89 100644
--- a/cluster/images/etcd/Makefile
+++ b/cluster/images/etcd/Makefile
@@ -51,7 +51,7 @@ OSVERSION ?= 1809
OUTPUT_TYPE ?= docker
ALL_OS = linux windows
-ALL_ARCH.linux = amd64 arm arm64 ppc64le s390x
+ALL_ARCH.linux = amd64 arm arm64 ppc64le s390x riscv64
ALL_OS_ARCH.linux = $(foreach arch, ${ALL_ARCH.linux}, linux-$(arch))
ALL_ARCH.windows = amd64
ALL_OSVERSIONS.windows := 1809 20H2 ltsc2022
@@ -106,6 +106,9 @@ endif
ifeq ($(ARCH),s390x)
BASEIMAGE?=registry.k8s.io/build-image/debian-base-s390x:bullseye-v1.3.0
endif
+ifeq ($(ARCH),riscv64)
+ BASEIMAGE?=registry.k8s.io/build-image/debian-base-riscv64:bullseye-v1.3.0
+endif
BASE.windows = mcr.microsoft.com/windows/nanoserver
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index c6cbce44..ccdb753e 100755
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -27,6 +27,7 @@ readonly KUBE_SUPPORTED_SERVER_PLATFORMS=(
linux/arm64
linux/s390x
linux/ppc64le
+ linux/riscv64
)
# The node platforms we build for
@@ -36,6 +37,7 @@ readonly KUBE_SUPPORTED_NODE_PLATFORMS=(
linux/arm64
linux/s390x
linux/ppc64le
+ linux/riscv64
windows/amd64
)
@@ -48,6 +50,7 @@ readonly KUBE_SUPPORTED_CLIENT_PLATFORMS=(
linux/arm64
linux/s390x
linux/ppc64le
+ linux/riscv64
darwin/amd64
darwin/arm64
windows/amd64
@@ -63,6 +66,7 @@ readonly KUBE_SUPPORTED_TEST_PLATFORMS=(
linux/arm64
linux/s390x
linux/ppc64le
+ linux/riscv64
darwin/amd64
darwin/arm64
windows/amd64
@@ -213,8 +217,8 @@ kube::golang::setup_platforms() {
elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then
host_arch=$(kube::util::host_arch)
- if [[ "${host_arch}" != "amd64" && "${host_arch}" != "arm64" && "${host_arch}" != "ppc64le" && "${host_arch}" != "s390x" ]]; then
- # on any platform other than amd64, arm64, ppc64le and s390x, we just default to amd64
+ if [[ "${host_arch}" != "amd64" && "${host_arch}" != "arm64" && "${host_arch}" != "ppc64le" && "${host_arch}" != "s390x" && "${host_arch}" != "riscv64" ]]; then
+ # on any platform other than amd64, arm64, ppc64le, s390x and riscv64, we just default to amd64
host_arch="amd64"
fi
KUBE_SERVER_PLATFORMS=("linux/${host_arch}")
@@ -444,6 +448,10 @@ kube::golang::set_platform_envs() {
export CGO_ENABLED=1
export CC=${KUBE_LINUX_S390X_CC:-s390x-linux-gnu-gcc}
;;
+ "linux/riscv64")
+ export CGO_ENABLED=1
+ export CC=${KUBE_LINUX_RISCV64_CC:-riscv64-linux-gnu-gcc}
+ ;;
esac
fi
diff --git a/hack/lib/util.sh b/hack/lib/util.sh
index 67454132..d0b3d3ed 100755
--- a/hack/lib/util.sh
+++ b/hack/lib/util.sh
@@ -185,8 +185,11 @@ kube::util::host_arch() {
ppc64le*)
host_arch=ppc64le
;;
+ riscv64*)
+ host_arch=riscv64
+ ;;
*)
- kube::log::error "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le."
+ kube::log::error "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x, ppc64le or riscv64."
exit 1
;;
esac
diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh
index 0a49b296..6c909be0 100755
--- a/hack/local-up-cluster.sh
+++ b/hack/local-up-cluster.sh
@@ -316,8 +316,11 @@ function detect_binary {
ppc64le*)
host_arch=ppc64le
;;
+ riscv64*)
+ host_arch=riscv64
+ ;;
*)
- echo "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le." >&2
+ echo "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x, ppc64le or riscv64." >&2
exit 1
;;
esac
diff --git a/test/images/image-util.sh b/test/images/image-util.sh
index 2b211868..5d6b91a4 100755
--- a/test/images/image-util.sh
+++ b/test/images/image-util.sh
@@ -34,7 +34,7 @@ source "${KUBE_ROOT}/hack/lib/logging.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"
# Mapping of go ARCH to actual architectures shipped part of multiarch/qemu-user-static project
-declare -A QEMUARCHS=( ["amd64"]="x86_64" ["arm"]="arm" ["arm64"]="aarch64" ["ppc64le"]="ppc64le" ["s390x"]="s390x" )
+declare -A QEMUARCHS=( ["amd64"]="x86_64" ["arm"]="arm" ["arm64"]="aarch64" ["ppc64le"]="ppc64le" ["s390x"]="s390x" ["riscv64"]="riscv64")
# NOTE(claudiub): In the test image build jobs, this script is not being run in a git repository,
# which would cause git log to fail. Instead, we can use the GIT_COMMIT_ID set in cloudbuild.yaml.
--
2.39.3 (Apple Git-145)